• Forums
• Posts
Latest Posts
Active Posts
Recently Visited
Search Results
• Page Extras
• Forum Themes
• AVR Freaks

### Hot!fast approximate algorithm of phase for complex number

Author
Maple
PIC-fan
• Total Posts : 47
• Reward points : 0
• Joined: 2016/03/06 21:42:36
• Location: China
• Status: offline
4 (1)

# fast approximate algorithm of phase for complex number

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!

oliverb
Super Member
• Total Posts : 369
• Reward points : 0
• Joined: 2009/02/16 13:12:38
• Location: 0
• Status: offline
Re: fast approximate algorithm of phase for complex number 2020/11/19 00:14:14 (permalink)
+1 (1)
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?
1and0
Access is Denied
• Total Posts : 11747
• Reward points : 0
• Joined: 2007/05/06 12:03:20
• Location: Harry's Gray Matter
• Status: offline
Re: fast approximate algorithm of phase for complex number 2020/11/19 13:56:37 (permalink)
+3 (3)
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.

1and0
Access is Denied
• Total Posts : 11747
• Reward points : 0
• Joined: 2007/05/06 12:03:20
• Location: Harry's Gray Matter
• Status: offline
Re: fast approximate algorithm of phase for complex number 2020/11/20 04:25:01 (permalink)
+2 (2)
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.
Maple
PIC-fan
• Total Posts : 47
• Reward points : 0
• Joined: 2016/03/06 21:42:36
• Location: China
• Status: offline
Re: fast approximate algorithm of phase for complex number 2020/11/26 07:36:46 (permalink)
0
Thx you guys!