DSPRelated.com
Forums

C code for fixed point atan2

Started by Eric Meurville January 20, 2005
Hello,

I have to implement atan2 on a dsPIC30F and would like to do that in 
fixed point for reasonable performance. Does someone already did that?

Thanks,
-- 
Eric Meurville
Hi
You may want to look a this
http://dspguru.com/comp.dsp/tricks/alg/fxdatan2.htm

-Nithin

Thanks for the link but the code proposed uses floats and I would 
perform the computation with integers.

EMe.

Nithin wrote:
> Hi > You may want to look a this > http://dspguru.com/comp.dsp/tricks/alg/fxdatan2.htm > > -Nithin >
Hi Eric,

Look again. The example code may use floats, but the title is "fixed 
point atan2 with self-normalisation". If you recast the numbers as fixed 
point values it works just fine.

Regards,
Steve


Eric Meurville wrote:

> Thanks for the link but the code proposed uses floats and I would > perform the computation with integers. > > EMe. > > Nithin wrote: > >> Hi >> You may want to look a this >> http://dspguru.com/comp.dsp/tricks/alg/fxdatan2.htm >> >> -Nithin >>
Steve Underwood wrote:
> Hi Eric, > > Look again. The example code may use floats, but the title is "fixed > point atan2 with self-normalisation". If you recast the numbers as
fixed
> point values it works just fine. > > Regards, > Steve > > > Eric Meurville wrote: > > > Thanks for the link but the code proposed uses floats and I would > > perform the computation with integers. > > > > EMe. > > > > Nithin wrote: > > > >> Hi > >> You may want to look a this > >> http://dspguru.com/comp.dsp/tricks/alg/fxdatan2.htm > >> > >> -Nithin > >>
if you simply recast everything as integers, won't coeff_1 =0? and what do you do with 1e-10?
I agree, this code is definetely floating point. Nevertheless, its 
performance on dsPIC30F is 3 times better than Microchip native math 
library.


bungalow_steve@yahoo.com wrote:
> Steve Underwood wrote: > >>Hi Eric, >> >>Look again. The example code may use floats, but the title is "fixed >>point atan2 with self-normalisation". If you recast the numbers as > > fixed > >>point values it works just fine. >> >>Regards, >>Steve >> >> >>Eric Meurville wrote: >> >> >>>Thanks for the link but the code proposed uses floats and I would >>>perform the computation with integers. >>> >>>EMe. >>> >>>Nithin wrote: >>> >>> >>>>Hi >>>>You may want to look a this >>>>http://dspguru.com/comp.dsp/tricks/alg/fxdatan2.htm >>>> >>>>-Nithin >>>> > > > if you simply recast everything as integers, won't coeff_1 =0? and what > do you do with 1e-10? >
-- Eric Meurville
bungalow_steve@yahoo.com wrote:
> Steve Underwood wrote: > >>Hi Eric, >> >>Look again. The example code may use floats, but the title is "fixed >>point atan2 with self-normalisation". If you recast the numbers as > > fixed > >>point values it works just fine. >> >>Regards, >>Steve >> >> >>Eric Meurville wrote: >> >> >>>Thanks for the link but the code proposed uses floats and I would >>>perform the computation with integers. >>> >>>EMe. >>> >>>Nithin wrote: >>> >>> >>>>Hi >>>>You may want to look a this >>>>http://dspguru.com/comp.dsp/tricks/alg/fxdatan2.htm >>>> >>>>-Nithin >>>> > > > if you simply recast everything as integers, won't coeff_1 =0? and what > do you do with 1e-10? >
Who said anything about using integers. I said fixed point. You don't even have to think about the 1e-10. A comment tells you why it is there, and it is, therefore, trivial to eliminate it with a bit of logic. The logic doesn't work so well with floats, which I guess is why the original is kludged in that way. Regards, Steve
Steve Underwood wrote:
> bungalow_steve@yahoo.com wrote: > > Steve Underwood wrote: > > > >>Hi Eric, > >> > >>Look again. The example code may use floats, but the title is
"fixed
> >>point atan2 with self-normalisation". If you recast the numbers as > > > > fixed > > > >>point values it works just fine. > >> > >>Regards, > >>Steve > >> > >> > >>Eric Meurville wrote: > >> > >> > >>>Thanks for the link but the code proposed uses floats and I would > >>>perform the computation with integers. > >>> > >>>EMe. > >>> > >>>Nithin wrote: > >>> > >>> > >>>>Hi > >>>>You may want to look a this > >>>>http://dspguru.com/comp.dsp/tricks/alg/fxdatan2.htm > >>>> > >>>>-Nithin > >>>> > > > > > > if you simply recast everything as integers, won't coeff_1 =0? and
what
> > do you do with 1e-10? > > > > Who said anything about using integers. I said fixed point. You don't
> even have to think about the 1e-10. A comment tells you why it is
there,
> and it is, therefore, trivial to eliminate it with a bit of logic.
The
> logic doesn't work so well with floats, which I guess is why the > original is kludged in that way. > > Regards, > Steve
There is a fixed point data type in C?
Microchip might be implementing more terms in the polynomial, I suspect
if you implemented the code in integer math on the dsPIC the entire
function would execute in less time then a single floating point add.
If I remember correctly the integer divide is the killer, 18 cycles,
but even with that, your talking at most 25-30 cycles for the entire
integer algorithm compared with over 100 cycles for a single floating
addition.

bungalow_steve@yahoo.com wrote:

  ...

> There is a fixed point data type in C?
Fixed-point is at worst integer scaled by shifts. Compilers for some processors that have fixed-point hardware do support a fixed-point type. Without that, either do the job in assembler or write C-callable assembly routines for best execution speed. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������