DSPRelated.com
Forums

how to optimize c code of Cordic algorithm

Started by praveen December 11, 2003
Praveen,

A few comments:

1) The code as presented assumes that x>=0. Max total shift possible in your
code is a little more than 90 degrees.
2) From your comments you are using double precision variables and math,
which is expensive computationally. Depending on your application single
precision might work adequately.
3) The accuracy you have stated is required does not require the loop to
iterate 26 times.
4) Your cordic code is short enough that you should be able to determine the
assembly code generated and present that to the group for suggestions of
what to change. The question of how many shifts the C compiler is using to
implement '>>i' would be answered by this.  If the answer is 'i' shifts then
there are simple alternatives to save processing. Other potential problems
may also be apparent.

A few more questions:

1)The original values loaded into x and y have how many bits each?
2) Where are they placed in the 32 bits of the x and y variables prior to
starting the routine?

Dirk A. Bell
DSP Consultant


"praveen" <praveenkumar_11@yahoo.com> wrote in message
news:d8daf655.0312122059.1de8f781@posting.google.com...
> Hello, > > I need 25 iteration,so my look up table is 4 byte size each, > Size of x,y,atan is 4 byte each. My accuracy of estimation is of the > order 1 microradian. > > waiting for reply > with regards > praveen
Hello, 

> Are you using single precision (16 bits) or double precision (32 bits) > each to store 'x' and 'y'?
I am using double precision
> Are you using integer or fractional math?
integer
> Are the values of 'x' and 'y' using the entire range of the number of > bits they are stored in?
my range of x and y is maximum of 2 and minimum of -2. But i am 32 bit to represent it.
> How many bits represent 'ang'?
i am using 32 bit
> Why does i go from 0 to 25?
because my estimation of accuracy should of the order of 1 microradians.
> Describe the contents of your LUT.
its contains value from 45 degrees to 0. with step size of 45/26. static long LUT[26]={23592960,13927738,7359034,3735561,1875029,938429,469329,234679,117341,58671,29335,14668,7334,3667,1833,917,458,229,115,57,29,14,7,4,2,1};
> > Have you verified that the result at each iteration of the loop is > what you expected? How about the final results? For what range of > input angles?
Yes the result is fine as expected. Its also 32 bit. waiting for reply with regards praveen
Praveen,

See my last post for more comments, questions.

Dirk

"praveen" <praveenkumar_11@yahoo.com> wrote in message
news:d8daf655.0312150501.5ff9134e@posting.google.com...
> Hello, > > > Are you using single precision (16 bits) or double precision (32 bits) > > each to store 'x' and 'y'? > > I am using double precision > > > > Are you using integer or fractional math? > > integer > > > Are the values of 'x' and 'y' using the entire range of the number of > > bits they are stored in? > > my range of x and y is maximum of 2 and minimum of -2. But i am 32 bit > to represent it. > > > > How many bits represent 'ang'? > i am using 32 bit > > > Why does i go from 0 to 25? > > because my estimation of accuracy should of the order of 1 > microradians. > > > Describe the contents of your LUT. > its contains value from 45 degrees to 0. with step size of 45/26. > > static long
LUT[26]={23592960,13927738,7359034,3735561,1875029,938429,469329,234679,1173 41,58671,29335,14668,7334,3667,1833,917,458,229,115,57,29,14,7,4,2,1};
> > > > > > Have you verified that the result at each iteration of the loop is > > what you expected? How about the final results? For what range of > > input angles? > > Yes the result is fine as expected. Its also 32 bit. > > waiting for reply > with regards > praveen
Hello,

If you write the cordic in C for atan . How much is the usual number of cycle
required?????

waiting for reply
praveen