Fixed point math routines

Sub forums for various specialist XMOS applications. e.g. USB audio, motor control and robotics.
Gothmag
XCore Addict
Posts: 129
Joined: Wed May 11, 2016 3:50 pm

Post by Gothmag »

If a native asin acos aren't available in time that stackexchange link showed a way to derive them both from atan2. I can use the existing fixed atan and perform necessary operations to determine corrections to get atan2 output, then do the derivation. Going to be a slower way than native acos, asin and probably lose some accuracy but may be fast enough to sacrifice some accuracy. Alot of the implementations Ive found have not had very good accuracy, which could be a problem for an AHRS system.


henk
Respected Member
Posts: 347
Joined: Wed Jan 27, 2016 5:21 pm

Post by henk »

It will be a little while - I seem to have mislaid my copy, and as you point out, they aren't easy to find.
Gothmag
XCore Addict
Posts: 129
Joined: Wed May 11, 2016 3:50 pm

Post by Gothmag »

That's ok, for now I'll implement the functions as I described above. Whenever you're able to do it I can swap things out. Thanks for looking though, it's appreciated.
User avatar
akp
XCore Expert
Posts: 578
Joined: Thu Nov 26, 2015 11:47 pm

Post by akp »

I think for a numerical solution you are on the right track. I have seen a few asin implementations and they generally use optimized atan and sqrt functions (fast & accurate sqrt is easy with Newton's method). So I would think the biggest improvement you can get in speed is by optimizing the atan function if you need it. This is the function you will use to compute asin, you don't need atan2, regular atan is fine, just handle x = -1 or +1 to avoid divide by zero.

Code: Select all

asin(x) = atan(x/sqrt(1-x*x))
henk
Respected Member
Posts: 347
Joined: Wed Jan 27, 2016 5:21 pm

Post by henk »

Hi,

I found Cody and Waite and added ASIN/ACOS to my fork of the library

https://github.com/henkmuller/lib_dsp

dsp_math_asin() takes 113 thread cycles; 1.8 us on a 62.5 MIPS thread. It relies on a couple of divisions, so for a worst case when all threads do divisions add another 100 thread cycles, or 3.4 us. Many cases are much faster.

Cheers,
Henk
Post Reply