Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Question about polynomial atan and Fixed-Point Atan2 With Self Normalization

Status
Not open for further replies.

Terminator3

Advanced Member level 3
Joined
Feb 25, 2012
Messages
802
Helped
71
Reputation
142
Reaction score
63
Trophy points
1,308
Activity points
9,027
I came across this link https://www.dspguru.com/book/export/html/61
it describes Polynomial Fixed-Point Atan2 With Self Normalization. It works really good, less than 1ms vs 40ms of floating point atan2, i used fixed point code from here:(https://www.dsprelated.com/showthread/comp.dsp/28979-1.php message Posted by dewagter ●February 25, 2010). All works very well, but i want to understand more about how it works.

1) My first question is which points of ATAN function must be used when finding polynomial coefficients?
As i understand, if we have function y=ATAN(x) then we can build polynom y=a*x^3+b*x^2+c*x+d. For third order polynomial we need 4 points to solve all equations. But how do i choose those optimal points (x value) to make polynom better represent ATAN function?

2) My second question is about self-normalizing ratio (https://www.dspguru.com/book/export/html/61)
Code:
theta1=0.1963 * r^3 - 0.9817 * r + pi/4
    x-y
r = ---     (1)
    x+y
here is polynomial, and author somehow managed to use (x-y)/(x+y) instead of y/x. How is he came up with this idea? Finding polynomial coefficients in this case is similar to y=a*x^3+b*x^2+c*x+d? (just choosing 4 points r=... theta1=...)?
 

Representing a continuous function by a polynomial is called a polynomial fit, and the usual method is to choose coefficients that minimize an error function according to a norm, most popular squared error (gauss norm) or absolute error (chebyshev norm). Even spreadsheet calculators like MS Excel or LibreOffice Calc can calculate polynomial fits.

The substitution r=(x-y)/(x+y) has the property of self-normalization, that's why it apparently has been chosen.

Similar "tricks" to approximate transcendent functions have been developped since the beginning of numerical mathematics and can be found in many "practical" text books. Their "why" not always obvious.
 
...
1) My first question is which points of ATAN function must be used when finding polynomial coefficients?

The number of points and location are arbitrary, and may be all by integrate an error function.

As i understand, if we have function y=ATAN(x) then we can build polynom y=a*x^3+b*x^2+c*x+d. For third order polynomial we need 4 points to solve all equations.
But how do i choose those optimal points (x value) to make polynom better represent ATAN function?
That's an interpolation, but is best a LMS fit.

2) My second question is about self-normalizing ratio (https://www.dspguru.com/book/export/html/61)
.......
here is polynomial, and author somehow managed to use (x-y)/(x+y) instead of y/x. How is he came up with this idea?

He made a translation to get a good approximation in the first quadrant.
tan(theta) = y/x
r = tan(pi/4 - theta) = (1-y/x)/(1+y/x) = (x-y)/(x+y)

Finding polynomial coefficients in this case is similar to y=a*x^3+b*x^2+c*x+d? (just choosing 4 points r=... theta1=...)?

No, remember that x and y can take very large values. Therefore you can not use that expression without restricting the domain and/or perform variable transformations.

That's look like the author made a LMS fit of:
Error(u) = ((pi/4)*u + p*u*(1-u^2) - atan(u))^2​
over a finite number of points.

I say "look like" because minimizing by the integral give an approximation with slightly less deviation.
theta1 = 0.1839*r^3 - 0.9693*r + pi/4 --> maxdev = 0.0066
vs
theta1 = 0.1963*r^3 - 0.9817*r + pi/4 --> maxdev = 0.0101​
 
Thank for replies!
int32_t coeff_1 = 45;
int32_t coeff_1b = -56; // 56.24;
int32_t coeff_1c = 11; // 11.25
I have noticed that coefficients given in dsprelated.com forum deffers a little.
Code:
45*Pi/180
	Ans = 0.785398163
-56*Pi/180
	Ans = -0.977384381
11*Pi/180
	Ans = 0.191986218

theta1=0.192*r^3-0.9774*r+pi/4

so it is all about what points was choosen and minimizing error criteria..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top