Digital Circuits/CORDIC

From testwiki
Revision as of 13:12, 21 February 2025 by 86.13.161.37 (talk) (Fix a typo of the +/- sign for equations of y_i under "Thus we now have these co-ordinates following a pseudo-rotation".)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

A CORDIC (standing for COordinate Rotation DIgital Computer) circuit serves to compute several common mathematical functions, such as trigonometric, hyperbolic, logarithmic and exponential functions.

Application

A CORDIC uses only adders and bitshifts to compute the results, with the benefit that it can therefore be implemented using relatively basic hardware.

Methods such as power series or table lookups usually need multiplications to be performed. If a hardware multiplier is not available, a CORDIC is generally faster, but if a multiplier can be used, other methods may be faster.

CORDICs can also be implemented in many ways, including a single-stage iterative method, which requires very few gates when compared to multiplier circuits. Also, CORDICs can compute many functions with precisely the same hardware, so they are ideal for applications with an emphasis on reduction of cost (e.g. by reducing gate counts in FPGAs) over speed. An example of this priority is in pocket calculators, where CORDICs are very frequently used.

History

The CORDIC was first invented in 1959 by J.E. Volder, in the aeroelectronics departments of Convair, and was designed for the B-58 Hustler bomber's navigational computer to replace an analogue resolver, a device that computed trigonometric functions (Circular CORDIC).

In 1971, J.S. Walther, at Hewlett-Packard, extended the method to calculate hyperbolic functions, natural logarithms, natural exponentials, multiplications, divisions, and square roots (Linear CORDIC and Hyperbolic CORDIC).

In 2019, based on Hyperbolic CORDIC, Yuanyong Luo et al. further proposed a Generalized Hyperbolic CORDIC (GH CORDIC) to directly compute logarithms and exponentials with an arbitrary fixed base. Theoretically, Hyperbolic CORDIC is a special case of GH CORDIC.

General Concept

Consider the following rotations of vectors:

  • Start at (1, 0)
  • Rotate by θ
  • We get (cosθ, sinθ)
  • Start at (1, y)
  • Rotate until y = 0
  • The rotation is tan−1y

If we were to have a computationally efficient method of rotating a vector, we can directly evaluate sine, cosine and arctan functions. However, rotation by an arbitrary angle is non-trivial (you have to know the sine and cosines, which is precisely what we don't have). We use two methods to make it easier:

  • Instead of performing rotations, we perform "pseudorotations", which are easier to compute.
  • Construct the desired angle θ from a sum of special angles, αi:
θ=α1+α2++αm

The diagram belows shows a rotation and pseudo-rotation of a vector of length Ri about an angle of ai about the origin:

A rotation about the origin produces the following co-ordinates:

xi+1=xicosαiyisinαi
yi+1=yicosαi+xisinαi
θi+1=θi+αi

Recall the identity cosθ1/1+tan2θ.

xi+1=(xiyitanαi)/1+tan2αi
yi+1=(yi+xitanαi)/1+tan2αi

Our strategy will be to eliminate the factor of 1/1+tan2αi and somehow remove the multiplication by tanαi. A pseudo-rotation produces a vector with the same angle as the rotated vector, but with a different length. In fact, the pseudo-rotation changes the length to:

Ri+1=Ricosαi=Ri1+tan2αi

Thus we now have these co-ordinates following a pseudo-rotation:

xi+1=(xiyitanαi)
yi+1=(yi+xitanαi)
θi+1=θiαi

The pseudo-rotation has succeeded in removing our length-factor, which would have required a costly division operation. However, the vector will grow by a factor of K over a sequence of n pseudo-rotations:

K=i=0n11+tan2αi

The co-ordinates following the n pseudo-rotations are then:

xn=K(xicosi=0n1αiyisini=0n1αi)
yn=K(yicosi=0n1αi+xisini=0n1αi)
θn=θii=0n1αi
The first three pseudo-rotations. Note how we converge on the correct angle, θ

If the angles are always the same set, then K is fixed, and can be accounted for later. We choose these angle according to two criteria:

  • We must also choose the angles so that any angle can be constructed from the sum of all them, with appropriate signs.
  • We make all tanαi a power of 2, so that the multiplication can be performed by a simple logical shift of a binary number.

The tangent function has a monotonically increasing gradient on the interval [0, π/2], so the tangent of a given angle is always less than twice the tangent of half the angle. This means that if we make the angles αi=tan12i, we can satisfy both criteria. Note that the tangent function is odd, which means that to pseudo-rotate the other way, you just subtract, rather than add, the tangent of the angle.

i αi = tan−1 (2−i)
Degrees Radians
0 45.00 0.7854
1 26.57 0.4636
2 14.04 0.2450
3 7.13 0.1244
4 3.58 0.0624
5 1.79 0.0312
6 0.90 0.0160
7 0.45 0.0080
8 0.22 0.0040
9 0.11 0.0020

In step i of the process, we pseudo-rotate by di2i, where di is the direction (or sign) of the rotation, which will be chosen at each step to force the angle to converge to the desired final rotation. For example, consider a rotation of 28°:

2845.026.57+14.047.13+3.581.79+0.900.45+0.22+0.11
2827.91

The more steps we take, the better the approximation that we can make by successive rotations. Thus, we have the following iterative co-ordinate calculation:

xi+1=xidiyi2i
yi+1=yi+dixi2i
θi+1=θidiαi

In order to achieve k bit of precision, k iterations are needed, because tan12i2i, converging as i increases.

Using CORDICs

CORDICs can be used to compute many functions. A CORDIC has three inputs, x0, y0, and z0. Depending on the inputs to the CORDIC, various results can be produced at the outputs xn, yn, and zn. Template:Clear

Using CORDIC in rotation mode

xi+1=xidiyi2i
yi+1=yi+dixi2i
zi+1=zidiαi

xn=K(x0cosz0y0sinz0)
yn=K(y0cosz0+x0sinz0)
zn=0

For convergence of zn to 0, choose di=sgn zi.

If we start with x0 = 1/K and y0=0, at the end of the process, we find xn=cos z0 and yn=sin z0.

The domain of convergence is 99.7<z0<99.7 because 99.7° is the sum of all angles in the list.

Using CORDIC in vectoring mode

xi+1=xidiyi2i
yi+1=yi+dixi2i
zi+1=zidiαi

xn=Kx2+y2
yn=0
zn=z0+tan1(y0/x0)

For convergence of yn to 0, choose di=sgn (yi).

If we start with x0 = 1 and z0 = 0, we find zn=tan−1y0

Implementations of CORDICs

Bit-parallel, unrolled

Bit-parallel, iterative

If a high speed is not required, this can be implemented with a single adder and a single shifter.

Bit-serial

The Universal CORDIC

By introducing a factor μ, we can also cater for linear and hyperbolic functions:

xi+1=xiμdiyi2i
yi+1=yi+dixi2i
zi+1=zidiαi

Summary of Universal CORDIC implementations

xi+1=xiμdiyi2i
yi+1=yi+dixi2i
zi+1=zidiαi
Mode Rotation Vectoring
di=sgn (zi),z0 di=sgn (yi),y0
Circular

μ = 1
αi = tan−12−i

Linear

μ = 0
αi = 2−i

Hyperbolic

μ = -1
αi = tanh−12−i

  • In hyperbolic mode, iterations 4, 13, 40, 121, ..., j, 3j+1,... must be repeated. The constant K' given below accounts for this.
  • K = 1.646760258121...
  • 1/K = 0.607252935009...
  • K' = 0.8281593609602...
  • 1/K' = 1.207497067763...

Directly computable functions

sinz cosz
tan1z sinhz
coshz tanh1z
y/x xz
tan1(y/x) x2+y2
x2y2 ez=sinhz+coshz

Indirectly computable functions

In addition to the above functions, a number of other functions can be produced by combining the results of previous computations:

tanz=sinzcosz cos1w=tan11w2w
tanhz=sinhzcoshz sin1w=tan1w1w2
lnw=2tanh1w1w+1 logbw=lnwlnb
wt=etlnw cosh1=ln(w+w21)
tan1(y/x) sinh1=ln(w+w2+1)
x2y2 w=(w+1/4)2(w1/4)2

Further reading

Template:Wikipedia

Template:BookCat