# Implementation of Arctan(x)

Started by October 1, 2007
```Hi,
I am  implementing arctan(x) in hardware can any one suggest me any
of the algorithms other than cordic because it takes lots of iterations to
reach the final result.

Thanks and Regards
Karthik W

```
```karthikw wrote:
> Hi,
>      I am  implementing arctan(x) in hardware can any one suggest me any
> of the algorithms other than cordic because it takes lots of iterations to
> reach the final result.
>
Some sort of a table lookup + interpolation will probably be the best as
far as speed/size.  No matter what you do, you'll have some interesting
effects as the slope goes to infinity -- you'll either be taking
reciprocals (not speedy), or _really_ juggling cost/speed/precision issues.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" gives you just what it says.
See details at http://www.wescottdesign.com/actfes/actfes.html
```
```"karthikw" <karthikwali@gmail.com> writes:

> Hi,
>      I am  implementing arctan(x) in hardware can any one suggest me any
> of the algorithms other than cordic because it takes lots of iterations to
> reach the final result.
>
> Thanks and Regards
> Karthik W

Hi Karthik,

Try:

Efficient approximations for the arctangent function
Rajan, S.; Sichun Wang; Inkol, R.; Joyal, A.;
Signal Processing Magazine, IEEE
Volume 23,  Issue 3,  May 2006 Page(s):108 - 111
Digital Object Identifier 10.1109/MSP.2006.1628884
Summary: This paper provides several efficient approximations for the arctangent
function using Lagrange interpolation and minimax optimization techniques. These
approximations are particularly useful when processing power, memory, and power
consumption are i.....
--
%  Randy Yates                  % "With time with what you've learned,
%% Fuquay-Varina, NC            %  they'll kiss the ground you walk
%%% 919-577-9882                %  upon."
%%%% <yates@ieee.org>           % '21st Century Man', *Time*, ELO
http://www.digitalsignallabs.com
```
```karthikw wrote:
> Hi,
>      I am  implementing arctan(x) in hardware can any one suggest me any
> of the algorithms other than cordic because it takes lots of iterations to
> reach the final result.

What accuracy do you need? Over what range?

Jerry
--
Engineering is the art of making what you want from things you can get.
&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;
```
```On Oct 2, 5:16 am, "karthikw" <karthikw...@gmail.com> wrote:
> Hi,
>      I am  implementing arctan(x) in hardware can any one suggest me any
> of the algorithms other than cordic because it takes lots of iterations to
> reach the final result.
>
> Thanks and Regards
> Karthik W

If you are demodulating FM then forget it. You don't need arctan(x).

Hardy

```
```Tim Wescott wrote:
> karthikw wrote:
> > Hi,
> >      I am  implementing arctan(x) in hardware can any one suggest me any
> > of the algorithms other than cordic because it takes lots of iterations to
> > reach the final result.
>
> Some sort of a table lookup + interpolation will probably be the best as
> far as speed/size.  No matter what you do, you'll have some interesting
> effects as the slope goes to infinity

The slope of the arctan goes to zero, not infinity. Perhaps this is
interesting:

http://dspguru.com/comp.dsp/tricks/alg/fxdatan2.htm

Regards,
Andor

```
```Andor wrote:
> Tim Wescott wrote:
>> karthikw wrote:
>>> Hi,
>>>      I am  implementing arctan(x) in hardware can any one suggest me any
>>> of the algorithms other than cordic because it takes lots of iterations to
>>> reach the final result.
>> Some sort of a table lookup + interpolation will probably be the best as
>> far as speed/size.  No matter what you do, you'll have some interesting
>> effects as the slope goes to infinity
>
> The slope of the arctan goes to zero, not infinity. Perhaps this is
> interesting:
>
arctan(x) = sin(x)/cos(x).  As x goes to pi/2 the arctan (and it's
slope) goes to infinity.

Granted, for pi/4 < x < pi/2 you can use 1/(arctan(pi/2-x)) -- but then
you're calculating a reciprocal, of a number, so you're back to some
computationally intensive calculation.

Not that I'm an expert.  I've always sliced and diced the ordinate down
to 0 <= x <= pi/4, then negated and inverted as necessary -- but I've
never needed the absolute fastest speed, either.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" gives you just what it says.
See details at http://www.wescottdesign.com/actfes/actfes.html
```
```Tim Wescott <t...@seemywebsite.com> wrote:
> Andor wrote:
> > Tim Wescott wrote:
> >> karthikw wrote:
> >>> Hi,
> >>>      I am  implementing arctan(x) in hardware can any one suggest me any
> >>> of the algorithms other than cordic because it takes lots of iterations to
> >>> reach the final result.
> >> Some sort of a table lookup + interpolation will probably be the best as
> >> far as speed/size.  No matter what you do, you'll have some interesting
> >> effects as the slope goes to infinity
>
> > The slope of the arctan goes to zero, not infinity. Perhaps this is
> > interesting:
>
> arctan(x) = sin(x)/cos(x).  As x goes to pi/2 the arctan (and it's
> slope) goes to infinity.

You are mixing up tan with arctan.

Regards,
andor

```
```Andor wrote:
> Tim Wescott <t...@seemywebsite.com> wrote:
>> Andor wrote:
>>> Tim Wescott wrote:
>>>> karthikw wrote:
>>>>> Hi,
>>>>>      I am  implementing arctan(x) in hardware can any one suggest me any
>>>>> of the algorithms other than cordic because it takes lots of iterations to
>>>>> reach the final result.
>>>> Some sort of a table lookup + interpolation will probably be the best as
>>>> far as speed/size.  No matter what you do, you'll have some interesting
>>>> effects as the slope goes to infinity
>>> The slope of the arctan goes to zero, not infinity. Perhaps this is
>>> interesting:
>> arctan(x) = sin(x)/cos(x).  As x goes to pi/2 the arctan (and it's
>> slope) goes to infinity.
>
> You are mixing up tan with arctan.
>
> Regards,
> andor
>
Argh.  So I am.

In which case a look-up table would work nice, except for the minor
problem of the infinite ordinate -- then one may want a lookup table
with ever-increasing intervals, which actually wouldn't be too bad to
implement.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" gives you just what it says.
See details at http://www.wescottdesign.com/actfes/actfes.html
```
```On Oct 1, 5:43 pm, Tim Wescott <t...@seemywebsite.com> wrote:
>
...
>
> In which case a look-up table would work nice, except for the minor
> problem of the infinite ordinate -- then one may want a lookup table
> with ever-increasing intervals, which actually wouldn't be too bad to
> implement.

so how would one determine the index into the table without some
repeated search and compare operations?

also, i think something like

arctan(1/x) = pi/2 - arctan(x)

can be used for the the nearly infinite ordinates, no?  (a division is
required.)

dunno how this would work for hardware, but if a single division is
tolerable and
for -1 <= x <= 1, a very accurate approximation is:

arctan(x) ~= x/f(x^2)

where

f(u)  =     1.0
+  0.33288950512027 * u
+ -0.08467922817644 * u^2
+  0.03252232640125 * u^3
+ -0.00749305860992 * u^4

maybe too many terms, but it's not the finite power series that's bad,
but the division by it that's costly in many different contexts.

r b-j

```