• MPLAB XC16
  • fast approximate algorithm of phase for complex number
2020/10/22 00:32:19
Maple
Hello everyone!
I am using dsPIC33CK64MP506 MCU, XC16 compiler v1.41.
I want to get feature data of a fractcomplex-type data, which are its magnitude and phase.
I found build-in functions "_Q15sqrt"&"_Q15atanYByX" in <libq.h>, but it turns out "_Q15atanYByX" takes too much time to get the result for me(well _Q15sqrt is ok). Does anyone can share some fast approximate algorithms of phase estimation? (Given the actual phase range is [-45°, 45°]), THX in advance!
2020/11/19 00:14:14
oliverb
How much of an approximation can your application tolerate. Since you're working over a limited range you might start with Y/X, working in radians the error is 28% at the extremes. Then I suppose you could replace atan with some sort of look-up based approximation?
2020/11/19 13:56:37
1and0
grchy
Does anyone can share some fast approximate algorithms of phase estimation? (Given the actual phase range is [-45°, 45°]

For the range of [-45°, 45°] |y| <= x, so -1 <= y/x <= 1.  One arctan approximation is

    z = y/x

    arctan(z) = z * [(pi/4 + 0.273) - 0.273 * abs(z)]

which takes one division, two multiplications, and one subtraction.  A quick spreadsheet shows a worst case error of ~0.2° for that range.

Of course, this will have to be scaled for the Q15 format; i.e. 0x0000 is 0 radians, 0x8000 is pi radians, and 0xFFFF is almost 2*pi radians.
 
2020/11/20 04:25:01
1and0
For comparison, the first-order formula suggested by oliverb

    z = y/x

    arctan(z) = (pi/4) * z
    
takes one division and one multiplication but with a worst case error of ~4°.

As always, higher order polynomials usually result in better approximation.
2020/11/26 07:36:46
Maple
Thx you guys!
I found your suggestion is very useful, I will try both of your advice and see!
© 2021 APG vNext Commercial Version 4.5

Use My Existing Forum Account