25f02-cordic

advertisement
CORDIC Algorithm
COordinate Rotation DIgital Computer
• Method for Elementary Function Evaluation (e.g.,
sin(z), cos(z), tan-1(y))
• Originally Used for Real-time Navigation (Volder
1956)
• Idea is to Rotate a Vector in Cartesion Plane by
Some Angle
• Complexity Comparable to Division
Rotations in the Plane
 x '  cos   sin    x 
 y '   sin  cos    y 
  
 
y
(0.707,0.707)(cos45°, sin45°)
0.707
45°
x
0.707
(1,0)
Rotations in the Plane-Simplifications
x '  x cos   y sin 
y '  y cos   x sin 
Factoring the term cos from the above Equations:
x '  cos   [ x  y tan  ]
y '  cos   [ y  x tan  ]
Restrict the Rotation Angles Such that:
tan   2
i
Above Multiplication is Reduced to a Simple Shift!!
Iterations Over Angles
• Arbitrary Angles Obtained After Series of Smaller
Rotations (increasing i values)
• At Each Iteration Rotate Up or Rotate Down
• Possible Rotation Angles, e (i) = tan –1 2-i (degrees):
Rotations in the Plane-Simplifications
Restrict the Rotation Angles Such that:
tan   2  i  d i 2  i
d i  1
  tan 1 ( d i 2  i )
Substituting into Previous Equations:
x '  cos   [ x  y tan  ]
y '  cos   [ y  x tan  ]
x '  cos{tan 1 (di 2i )}  [ x  y  d i  2i ]
1
i
i
y '  cos{tan (di 2 )}  [ y  x  d i  2 ]
Rotations in the Plane-Simplifications
Using the Identity:
cos(  )  cos( )
Previous Equations:
x '  cos{tan 1 (di 2i )}  [ x  y  d i  2i ]
y '  cos{tan 1 (di 2i )}  [ y  x  d i  2i ]
Are Further Simplified as:
x '  cos{tan 1 (2i )}  [ x  y  d i  2i ]
y '  cos{tan 1 (2i )}  [ y  x  d i  2i ]
Scaling Constant – CORDIC Gain Factor
Gain Factor Becomes:
1
1
i
Ki  cos(tan 2 ) 
1  22i
This Value is Pre-computed for a Given i Value:
i
x '  Ki  [ x  y  d i  2 ]
i
y '  Ki  [ y  x  d i  2 ]
•Can Remove the Ki Value and Apply Elsewhere in System
•Can Pre-scale (x, y) by An
n
An   1  22i
i 0
Angle Accumulator, zi
Overall Rotation Angle Defined by Sequence of Iterations:
Use Angle Accumulator to Keep Track of Rotations:
zi 1  zi  di  tan1 (2i )
i
0
1
2
3
4
5
6
7
8
9
i
45
26.6
14.0
7.1
3.6
1.8
0.9
0.4
0.2
0.1
di
+1
-1
+1
-1
+1
+1
-1
+1
-1
+1
zi
45
18.4
32.4
25.3
28.9
30.7
29.8
30.2
30.0
30.1
Binary Angular Measurement - BAM
• Angle Accumulator can Represent Angles as BAM
• Encode di={-1,+1} as Bit Values {0,1}
• Example: -1 Represented by 0 and +1 Represented by 1
• LSb Represents d0
• Content z=01011
• z=+45  +26.6  -14.0  +7.1  -3.6  =61.1
• Can Simplify CORDIC Circuitry for Some Modes
• May Need BAM encode/decode – Can Use Lookup Table
CORDIC - Rotation Mode
• Input is Angle,  – Initialized in Angle
Accumulator
• Vector Initialized to Lie on x-axis
• Each Iteration di Chosen by Sign of Angle
• Attempt to Bring Angle to Zero
• Result is x Register Contains ~cos
• Result is y Register Contains ~sin
• Also Polar to Rectangular if x Register Initialized
to Magnitude
CORDIC - Vector Mode
• Input is (Pre-scaled) Vector in (x,y) Registers
• Angle,  – Initialized to Zero
• Each Iteration di Chosen to Move Vector to Lie
Along Positive x-axis (Want to Reduce y Register
to Zero)
• Result is Original Vector Angle in Angle
Accumulator
• Can be Used for sin-1 and cos-1
• Also Rectangular to Polar Conversion
• Magnitude in x Register
CORDIC – Rotation/Vector Modes
xn  An  x0 cos z0  y0 sin z0 
• Rotation Mode:
yn  An  y0 cos z0  x0 sin z0 
zn  0
xi 1  xi  yi  d i  2  i
yi 1  yi  xi  d i  2
n
An   1  2 2i
i
i 0
1
i
zi 1  zi  d i  tan (2 )
• Vector Mode:
xn  An x0  y0
2
xi 1  xi  yi  d i  2  i
yi 1  yi  xi  d i  2
 1, zi  0
di  
 1, otherwise
i
zi 1  zi  d i  tan 1 (2  i )
yn  0
zn  z0  tan  1
2
 x
y0
n
An   1  2 2i
i 0
 1, yi  0
di  
 1, otherwise
0
Rotation Angle Limits
• Rotation/Vector Algorithms Limited to 90
• Due to Use of =tan(20) for First Iteration
• Several Ways to Extend Range
• One Way is to Use Additional Rotation for Angles
Outside Range
• This Rotation is Initial 90 Rotation
x '  d  y
y'  d x
 2
z'  z  d  
 1, y  0
di  
 1, otherwise
CORDIC Uses
OPERATION
Sine, Cosine
Polar to Rect.
General Rotation
Arctangent
Vector Magnitude
Rect. to Polar
Arcsine, Arccosine
MODE
Rotation
Rotation
Rotation
Vector
Vector
Vector
Vector
INITIALIZE
x=1/An, y=0, z=
x=(1/An)Xmag, y=0, z=Xphase
x=(1/An)x0, y=(1/An)y0, z=
x=(1/An)x0, y=(1/An)y0, z=0
x=(1/An)x0, y=(1/An)y0, z=0
x=(1/An)x0, y=(1/An)y0, z=0
x=(1/An), y=0,
arg=sin or cos
DIRECTION
Reduce z to Zero
Reduce z to Zero
Reduce z to Zero
Reduce y to Zero
Reduce y to Zero
Reduce y to Zero
Reduce y to Value
in arg Register
• Can Use CORDIC For Others Also:
– Linear Functions
– Hyperbolic Functions
– Square Rooting
– Logarithms, Exponentials
CORDIC Hardware
Iterative CORDIC Structure*
*Taken from “A Survey of CORDIC Algorithms for FPGA
Based Computers”, R. Andraka, FPGA’98
Bit-serial CORDIC Structure*
*Taken from “A Survey of CORDIC Algorithms for FPGA
Based Computers”, R. Andraka, FPGA’98
Download