Fixed point math routines
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.
It will be a little while - I seem to have mislaid my copy, and as you point out, they aren't easy to find.
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.
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))
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
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