You are on page 1of 48

Dr. Rehan Hafiz <rehan.hafiz@seecs.edu.

pk>
Lecture # 14
ADSD Fall 2011
Course Website for ADSD Fall 2011
http://lms.nust.edu.pk/
2
Lectures: Tuesday @ 5:30-6:20 pm, Friday @ 6:30-7:20 pm
Contact: By appointment/Email
Office: VISpro Lab above SEECS Library
Acknowledgement: Material from the following sources has been consulted/used in these
slides:
1. A survey of CORDIC algorithms for FPGA based computers, Ray Andraka, Andraka
Consulting Group, Inc
2. University of Minnesota : EE 5324 - VLSI Design II - Lectures Slides by Kia Bazargan,
Spring 2006
3. http://www.indovina.us/~mai/paco/Pacos_cordic_algorithm.xl
4. [SHO] Digital Design of Signal Processing System by Dr Shoab A Khan



Material/Slides from these slides CAN be used with following citing reference:
Dr. Rehan Hafiz: Advanced Digital System Design 2010

Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
COordinate Rotation DIgital Computer
(CORDIC)
Iterative Technique
Enormous Applications
Linear Functions / Multiplication
Division
Hyperbolic Functions
Square Rooting
Logarithms, Exponentials
Sine, Cosine Generation
Does so much with just SHIFT & ADD
Rotation of a Vector
V1
x = r cos()
y = r sin()
V2
x'= r cos(+)
x'= r [cos()cos() -sin()sin()]
x'= r [(x/r)cos() (y/r)sin()]
x'= xcos() ysin()
y'= r sin(+)
y'= ycos() + xsin()




V1
(x,y)
V2
(x,y)
r
r
Re-arranging the Rotation
Transformation
Rotates a vector in a
Cartesian Plane by the
angle
Calculations
Re-arranging
So, given a rotation angle ;
these equations require the
computation of tan()


cos =
| |
| | ) tan( . .
tan 1
1
'
) tan( . .
tan 1
1
2
2
|
|
|
|
x y y
y x x
+
+
=

+
=
'
) sin( . ) cos( '
) sin( . ) cos(
| |
| |
x y y
y x x
+ =
=
'
tan() is not simple to compute
in hardware



tan()
0.00 0.000
5.00 0.087
10.00 0.176
15.00 0.268
20.00 0.364
25.00 0.466
30.00 0.577
35.00 0.700
40.00 0.839
45.00 1.000
| |
| | ) tan( . .
tan 1
1
'
) tan( . .
tan 1
1
2
2
|
|
|
|
x y y
y x x
+
+
=

+
= '
Example: Lets say we want to rotate a vector
(x0,y0) 30-degrees anti-clockwise to (x3,y3)
Requires calculation of tan(30)
Suppose tan (10) is pre-computed & stored in HW
A 30 degree rotation can be modeled by applying 10 degree
rotation three times






& Similarly for y1,y2,y3



(x0,y0)
(x1,y1)
(x2,y2)
(x3,y3)
| |
| |
| | ) 10 tan( . .
) 10 ( tan 1
1
) 10 tan( . .
) 10 ( tan 1
1
) 10 tan( . .
) 10 ( tan 1
1
2 2
2
3
1 1
2
2
0 0
2
1
y x x
y x x
y x x

+
=

+
=

+
=
Putting a HW efficient
constraint over tan()
tan() is not simple to compute
in hardware



tan()
0.00 0.000
5.00 0.087
10.00 0.176
15.00 0.268
20.00 0.364
25.00 0.466
30.00 0.577
35.00 0.700
40.00 0.839
45.00 1.000

Rotation angles
are restricted so
that tan() = 2
-i
,
where i = 0,1,2,3,

Multiplication by
Tangent is reduced
to simple shift
operation
| |
| | ) tan( . .
tan 1
1
'
) tan( . .
tan 1
1
2
2
|
|
|
|
x y y
y x x
+
+
=

+
= '
i tan(
i
)
i
i 2
-i
tan
-1
(2
-i
)
0 1 45.000
1 0.5 26.565
2 0.25 14.036
3 0.125 7.125
4 0.0625 3.576
5 0.03125 1.790
6 0.015625 0.895
7 0.0078125 0.448
8 0.00390625 0.224
9 0.001953125 0.112
Putting a HW efficient
constraint over tan()

tan() = 2
-i
tan() =d.2
-i

d=-1,+1 depending
upon the rotation
direction




| |
| |
i -
2i -
i -
2i -
2 . . .
2 1
1
'
2 . . .
2 1
1
d x y y
d y x x
+
+
=

+
=
'
| |
| | ) tan( . .
tan 1
1
'
) tan( . .
tan 1
1
2
2
|
|
|
|
x y y
y x x
+
+
=

+
=
'
In CORDIC we use the
pre-computed 2
-i
table
Principle: A composite rotation of any
arbitrary angle can be represented
by summation() of elementary
rotations
Using elementary angles from the
constrained tan table
Writing 30 in terms of elementary angles
from table
= 30.0
~ 45.0 26.6 + 14.0 7.1 + 3.6
+ 1.8 0.9 + 0.4 0.2 + 0.1
= 30.1





Iter.
Constrain
-ed tan
Rotation for each
iteration
i tan(
i
)
i
i 2
-i
tan
-1
(2
-i
)
0 1 45.000
1 0.5 26.565
2 0.25 14.036
3 0.125 7.125
4 0.0625 3.576
5 0.03125 1.790
6 0.01562 0.895
7 0.00781 0.448
8 0.00390 0.224
9 0.00195 0.112
CORDIC- Algorithm
Initialize 0 with desired rotation
angle = 30
For first iteration you will be giving
a +45 deg rotation
For each iteration (i=09) do
following
Use pre-computed value of tan to
compute x
i+1
,y
i+1
Compute n = n-1 - tan
-1
(2
-i
)
If n >0, Give a +ve Rotation in next
iteration
If n <0, Give a -ve Rotation in next
iteration
xn & yn contain the desired result

Iter.
Constrain
-ed tan
Rotation for each
iteration
i tan(
i
) =2
-i

i=
tan
-1
(2
-i
)
0 1 45.000
1 0.5 26.565
2 0.25 14.036
3 0.125 7.125
4 0.0625 3.576
5 0.03125 1.790
6 0.01562 0.895
7 0.00781 0.448
8 0.00390 0.224
9 0.00195 0.112
X
Y
30
Example: Rewriting
Angles in Terms of o
i
| = 30.0
~ 45.0 26.6 + 14.0 7.1 + 3.6
+ 1.8 0.9 + 0.4 0.2 + 0.1
= 30.1
45
+ 1.10 - (+ 1.8 ) = - 0.70
Rotate the vector in -ve direction
+ 4.70 - (+ 3.6 ) = + 1.10
Rotate the vector in +ve direction
- 2.40 - (- 7.1 ) = + 4.70
Rotate the vector in +ve direction
+11.60 - (+14.00 ) = - 2.40
Rotate the vector in -ve direction
-15.00 - (-26.60 ) = +11.60
Rotate the vector in +ve direction
+30.00 - (+45.00 ) = -15.00
Rotate the vector in -ve direction
Angle Accumulator Angle(current tan value) = Residual Angle
+ve +ve direction, -ve -ve direction
The calculation of residual angle results into
another equation in the CORDIC System
Angle Accumulator Angle(current tan value) = Residual Angle
Actually it is
Angle Accumulator = Angle Acc. (Current Value) (Direction)Angle Moved




) 2 ( tan .
2 . .
2 . .
i - 1
1
i -
1
-i
1

+
+
+
=
+ =
=
i i i
i i i i
i i i i
d z z
d x y y
d y x x
Iter.
Constrain
-ed tan
Rotation for each
iteration
i tan(
i
) =2
-i

i=
tan
-1
(2
-i
)
0 1 45.000
1 0.5 26.565
2 0.25 14.036
3 0.125 7.125
4 0.0625 3.576
5 0.03125 1.790
6 0.01562 0.895
7 0.00781 0.448
8 0.00390 0.224
9 0.00195 0.112
1
-i 1
)] 2 ( .[tan
+

=
i i i
z d z
CORDIC- Formal
CORDIC
Derivation Summary
| |
| | ) tan( . .
tan 1
1
) tan( . .
tan 1
1
2
2
1
1
i
i
i
i
i
x y y
y x x
i i
i
|
|
|
|
+
+
=

+
=
+
+
| |
| |
i -
1
-i
1
2 . . .
2 . . .
i i i i i
i i i i i
d x y K y
d y x K x
+ =
=
+
+
1 ,
2 1
1
2i -
=
+
= d K
i
Provides an iterative method
of performing vector
rotations by arbitrary angles
Uses only shifts & adds
K
i
is just a scaling factor
multiplied in each iteration &
can be applied as a
cumulative gain A
n
to the
final x
n
,y
n
The precision increases with
each iteration
[
+ = =
n
n
A Gain
-2i
2 1 / 1 / 1
647 . 1
i
n
A
) 2 ( tan .
2 . .
2 . .
i - 1
1
i -
1
-i
1

+
+
+
=
+ =
=
i i i
i i i i
i i i i
d z z
d x y y
d y x x
Modes defined by Volder
Rotation - The coordinate components of a
vector and an angle of rotation are given and the
coordinate components of the original vector,
after rotation through the given angle, are
computed.
Vector - The coordinate components of a vector
are given and the magnitude and angular
argument of the original vector are computed.
CORDIC
Rotation Mode
Rotates the input vector by a
specified angle
Application
Calculating the x,y coordinates
at a given angle
Method:
Initialize angle accumulator by
desired angle
Initialize x & y
Decision d: based upon the
sign of angle accumulator
Goal : Minimize the Angle
Accumulator
The coordinate components of a vector and an
angle of rotation are given and the coordinate
components of the original vector, after rotation
through the given angle, are computed
Rotation Mode
1
0
3
2
5
4
6
(x, y)
z
(x, y) z=0
rotates a vector (x,y) by a given angle (z)
CORDIC
Vectoring Mode
Rotates the input vector to x-axis
while recording the angle required
to make that rotation
Application
Calculating the angle of a vector
Calculating the magnitude (scaled)
Initialize angle accumulator by
ZERO
Goal : Minimize the y component
of the residual vector.
Decision: based on Sign of the
residual y component
Angle accumulator will contain
the traversed angle at the end of
the iterations
The coordinate components of a vector
are given and the magnitude and
angular argument of the original
vector are computed
Vector Mode

rotates a vector (x,y) to the x axis while
recording the angle required to make the
rotation (z)
0 (x,y)
1
2
3
4
5 (x, 0)
z
Saving an addition for Angular Measurements
System --- Vector Mode
Can we avoid computing z in vector mode & still be able to know the final
angle ?
The angle of a composite rotation is uniquely defined by the directions of
elementary rotations.
Can be stored using : Decision Vector LUT
So, also skip Addition in Vector Mode
d
9
d
8
d
7
d
06
d
5
d
4
d
3
d
2
d
1
d
0
Angle
0 0 0 0 0 0 0 0 0 0 99.77
0.112 + 0.224 +0.448+0.895+1.790+3.576+7.125+14.036 + 26.565 + 45.000
0 0 0 0 0 0 0 0 0 1 9.77
0.112 + 0.224 +0.448+0.895+1.790+3.576+7.125+14.036 + 26.565 - 45.000
0 0 0 0 0 0 0 0 1 0 46.64
0.112 + 0.224 +0.448+0.895+1.790+3.576+7.125+14.036 - 26.565 + 45.000
CORDIC
Unified Equations
x
i+1
= x
i
y
i
.m.d
i
.2
-i

y
i+1
= y
i
+ x
i
.d
i
.2
-i

z
i+1
= z
i
d
i
.e
i

Coordinate System m e
i
Circular 1 tan
-1
(2
-i
)
Linear 0 2
-i

Hyperbolic -1 tanh
-1
(2
-i
)
Mode d
Rotation d
i
= -1 if z
i
< 0, else +1
Vector d
i
= +1 if y
i
< 0,else -1
J.Walther, A Unified Algorithm for Elementary Functions, Joint Computer
Conference Proceedings
CORDIC-Linear Mode
Multiplication
Lets say you are multiplying 28 by any
number z
Cordics HW optimization constraint
limits the possible multiplier to power
of 2 (i.e. 2
-i
)
Thus possible combinations are
28*(1)
28*(0.5)
28*(0.25),..
We can represent any composite
multiplier using these elementary
multipliers
Example 28*(1+0.5+0.25) = 28*(1.75)
Example 28*(1-0.5+0.25) = 28*(0.75)



CORDIC Linear Mode
Decision for d
The iterations work to produce such a combination (d) of elementary multiplier
that reduces the residual multiplier to zero
After every iteration we compare the residual with zero.
If residual is greater than zero (z
i
>0)
The combination that we have multiplied with till yet; is still less than the desired multiplier
We need to ADD the next elementary multiplier
If residual is less than zero (z
i
<0)
The combination that we have multiplied with till yet; is greater than desired multiplier
We need to SUBTRACT the next elementary multiplier

CORDIC-Linear Mode
Multiplication

0
10
20
30
40
50
60
1 2 3 4 5 6 7 8 9 10 11
Series1
CORDIC-Linear Mode
Multiplication

0
0.2
0.4
0.6
0.8
1
1.2
1 2 3 4 5 6 7 8 9 10 11
Division

0
0.2
0.4
0.6
0.8
1
1.2
1 2 3 4 5 6 7 8 9 10 11
Minimize this
term for division
in vector mode
Minimizing y
i+1
Means we wish to force y 0, in our iterations
Assume we want to find the ratio
Initialize x=4, y=3 & z=0
Minimizing y
i
+x
i
.(d
i
.2
-I
) means

Minimize 3+4( some term)
This term 3+4( some term) can only reach 0;
if some term = the ratio i.e. (-3/4)
AND z
i+1
is actually storing the updated value of this some
term in every iteration






CORDIC Uses
OPERATION MODE INITIALIZE
x
o
, y
o
, z
o
DIRECTION REQ. OUTPUT
Sine, Cosine of an
angle
Rotation x=1/A
n
, y=0, z=o Reduce z to Zero x
n
=cos z
o
Y
n
=sin z
o
Polar to Rect. Rotation x=(1/A
n
)X
mag
, y=0,
z=X
phase

Reduce z to Zero x
n
=X
mag
cos z
o
y
n
=X
mag
sin z
o
General Rotation
of a vector
Rotation x=(1/A
n
)x
0
,
y=(1/A
n
)y
0
, z=o
Reduce z to Zero x
n
,y
n
are the
rotated
coordinates
Vector Magnitude Vector x=(1/A
n
)x
0
,
y=(1/A
n
)y
0
, z=0
Reduce y to Zero
Arctangent

Vector x=(1/A
n
)x
0
,
y=(1/A
n
)y
0
, z=0
Reduce y to Zero
Rect. to Polar Vector x=(1/A
n
)x
0
,
y=(1/A
n
)y
0
, z=0
Reduce y to Zero X
n
is magnitude
Z
n
is magnitude
Arcsine,
Arccosine
Vector x=(1/A
n
), y=0,
arg=sino or coso
Reduce y to Value
in arg Register
) / ( tan
0
0 0
1
0
2
0
2
0
x y z z
y
y x A x
n
n
n n

+ =
=
+ =
Output Equations
[

+ =
=
+ =
=
n
i
n
n
n n
n n
A
z
z x z y A y
z y z x A x
2
0 0 0 0
0 0 0 0
2 1
0
] sin cos [
] sin cos [
Circular - Rotation
[

+ =
+ =
=
+ =
n
i
n
n
n
n n
A
x y z z
y
y x A x
2
0 0
1
0
2
0
2
0
2 1
) / ( tan
0
Circular - Vector
0
0 0 0
0
=
+ =
=
zn
z x y y
x x
n
n
Linear - Rotation
) / (
0
0 0 0
0
x y z z
y
x x
n
n
n
=
=
=
[

=
=
+ =
+ =
n
i
n
n
n n
n n
A
z
z x z y A y
z y z x A x
2
0 0 0 0
0 0 0 0
2 1
0
] sinh cosh [
] sinh cosh [
[

=
+ =
=
=
n
i
n
n
n
n n
A
x y z z
y
y x A x
2
0 0
1
0
2
0
2
0
2 1
) / ( tanh
0
Hyperbolic - Rotation
Linear - Vector
Hyperbolic - Vector
Micro-Architecture
CORDIC in HW
Bit Parallel Architecture
x
i+1
= x
i
y
i
.m.d
i
.2
-i

y
i+1
= y
i
+ x
i
.d
i
.2
-i

z
i+1
= z
i
d
i
.e
i

Coordinate System m e
i
Circular 1 tan
-1
(2
-i
)
Linear 0 2
-i

Hyperbolic -1 tanh
-1
(2
-i
)
Mode d
Rotation d
i
= -1 if z
i
< 0, else +1
Vector d
i
= +1 if y
i
< 0,else -1
ROM has the angle list
Bit-serial CORDIC Structure
MUX selection for cross terms depends on the Iteration number <multiplier shifts>
Each iteration takes w <number width> cycles
Unrolled
CORDIC
x
i+1
= x
i
y
i
.m.d
i
.2
-i

y
i+1
= y
i
+ x
i
.d
i
.2
-i

z
i+1
= z
i
d
i
.e
i

Discussion on some CORDIC Papers
Papers
(Please go through the paper)
50 Years of CORDIC: Algorithms,
Architectures, and Applications
Pramod K. Meher, Senior Member, IEEE, Javier Valls, Member, IEEE, Tso-Bing Juang,
Member, IEEE, K. Sridharan, Senior Member, IEEE, and Koushik Maharatna, Member,
IEEE
IEEE TRANSACTIONS ON CIRCUITS AND SYSTEMSI: REGULAR PAPERS, VOL. 56, NO. 9, SEPTEMBER 2009
Adaptive CORDIC: Using Parallel Angle
Recoding to Accelerate Rotations
Terence K. Rodrigues and Earl E. Swartzlander, Jr., Fellow, IEEE
IEEE TRANSACTIONS ON COMPUTERS, VOL. 59, NO. 4, APRIL 2010

CORDIC Implementations
The latency of an iterative algorithm like CORDIC is determined
by the product of the number of iterations times the cycle time
of each iteration.
Speeding up CORDIC
Reduce the number of iterations (Solution : e.g. Higher RADIX)
Reduce the execution time for each cycle (Solution : For e.g. Using
Fast Adders)
Two bottlenecks in CORDIC
The micro-rotation for any iteration is performed on the
intermediate vector computed by the previous iteration
(Solution: Unrolling)
The ith iteration could be started only after the completion of the
ith iteration, since the value of d needs to be estimated (Solution :
Predicting Angle Constants in advance)

Higher Radix CORDIC - Approach

Control CORDIC

Simple method; Can be applied in runtime
Diverging pseudorotations only occur when
there is an overshoot, so this method avoids
them by ensuring that the trajectory of the
moving vector will never overshoot the final
target position.
Angle Recoding
Exhaustive algortihm
At every iteration, the angle constant
that will bring the residual angle (Z i
) closest to 0 is chosen from the set
of available angle constants.
HW wise very complicated angle
selection logic !
It is, therefore, most attractive in
static cases where the rotation
angle is fixed and known a priori.
The selection of the angle constants
can be done offline, and the angle
constants saved in a Look-Up Table.
Angle Recoding

Dynamic Angle Selection for Angle
Recoding
A simulation was done for Angle Recoding to observe the pattern
Observation:
There are contiguous bands of rotation angles, all of which use a particular angle constant
during an intermediate iteration. If a rotation angle lies within a particular band, the angle
constant corresponding to that band is used.
For example, any
rotation angle in the
range [20.295, 35.78)
will use the angle
constant 26.56 degrees.
This implies that the
dynamic angle selection
for Angle Recoding can
be done by performing
an initial comparison
step, to determine the
bands that contain an
angle.


Ranges are then defined for every possible combination of Angle constants

Range comparisons increase exponentially with bit width

Parallel Comparators Required in H/W
H/W mapping for
Parallel Angle Recoding

Select fewer angle constants at a time, in a given
evaluation cycle. All the angle constants which
are evaluated together in the same cycle in the
comparison logic are said to constitute a section.
When all the angle constants from the section
have been processed in the CORDIC unit, the
absolute value of the residual angle that remains
at the end, is less than half the value of the
smallest angle constant in the section.
H/W mapping for
Section based Parallel Angle Recoding

You might also like