Upload
others
View
10
Download
0
Embed Size (px)
Citation preview
Cordic Algorithms in Cordic Algorithms in FPGAsFPGAs
Cordic Cordic AlgorithmsAlgorithms
Cordic AlgorithmCordic Algorithm
�� COrdinateCOrdinate Rotation Digital ComputerRotation Digital Computer
�� An iterative method to perform Coordinate Rotations An iterative method to perform Coordinate Rotations using only shifts and addsusing only shifts and adds
�� Hardware Efficient algorithms used for calculating Hardware Efficient algorithms used for calculating trigonometric and transcendental functionstrigonometric and transcendental functions
Cordic Cordic AlgorithmsAlgorithms
Vector rotation in Cartesian Vector rotation in Cartesian Coordinate SystemCoordinate System
X
Y
X’
Y’
φ
Px’
Py’
Px
Py
φ
P
Cordic Cordic AlgorithmsAlgorithms
Vector rotation in Cartesian Vector rotation in Cartesian Coordinate SystemCoordinate System
X
Y
X’
Y’
φ
Px’
Py’
Px
Py
φ
φ
Py*cos(φ)
Px*sin(φ)Py’=Px*sin(φφφφ)+Py*cos(φφφφ)
P
Cordic Cordic AlgorithmsAlgorithms
Vector rotation in Cartesian Vector rotation in Cartesian Coordinate SystemCoordinate System
X
Y
X’
Y’
φ
Px’
Py’
Px
Py
φ
Px*cos(φ)
Py*sin(φ)
Px’=Px*cos(φφφφ)-Py*sin(φφφφ)
P
Cordic Cordic AlgorithmsAlgorithms
Vector rotation in Cartesian Vector rotation in Cartesian Coordinate SystemCoordinate System
X
Y
X’
Y’
φ
Px’
Py’
Px
Py
φ
P
Px’=Px*cos(φφφφ)-Py*sin(φφφφ)
Py’=Px*sin(φφφφ)+Py*cos(φφφφ)
Px’= cos(φφφφ)*( Px-Py*tan(φφφφ))
Py’= cos(φφφφ)*(Py+Px*tan(φφφφ))
Cordic Cordic AlgorithmsAlgorithms
x x i+1i+1 = = coscos((φφφφφφφφii) * () * ( xxii -- yyii * tan(* tan(φφφφφφφφii) )) )
y y i+1i+1 = = coscos((φφφφφφφφii) * () * ( yyii + x + x I I * tan(* tan(φφφφφφφφii) )) )
z z i+1i+1 == zzii -- φφφφφφφφii
Assume Assume tan(tan(φφφφφφφφii) = d) = di i * 2* 2--ii where where ddi i = +1= +1 or or --11
φφφφφφφφii = = ddii * tan* tan--11(2(2--ii))
KKi i = cos(= cos(φφφφφφφφii) =) = coscos(tan(tan--11(2(2--II)) = 1/)) = 1/
CORDIC EquationsCORDIC Equations
1 2 2i+ −
Cordic Cordic AlgorithmsAlgorithms
Factor Out the constantFactor Out the constant KKii from each iterationfrom each iteration
xxii+1+1 = x = x I I -- yyi i * d* di i * 2* 2--ii
yyi+1i+1 = y = y I I + x + x ii* d* di i * 2* 2--ii
zzi+1i+1 = z= zii -- ddi i * tan* tan--11(2(2--ii))
Multiply by Multiply by AAnn after n iterations to account for after n iterations to account for constants constants KKii
AAnn = =
CORDIC EquationsCORDIC Equations
1 2 2i
i 1
n
+ −
=
∏
Cordic Cordic AlgorithmsAlgorithms
�� Previous Equations are valid if initial angle Previous Equations are valid if initial angle zz0 0 > > --ππππππππ/2/2and and zz00 < < ππππππππ/2/2. For other angles, give an initial rotation . For other angles, give an initial rotation of of ππππππππ..
�� For initial rotation the equations areFor initial rotation the equations are
xx/ / = d * x= d * x where where d = d = --11 if if x < 0x < 0 else else d = 1d = 1
yy/ / = = --d * yd * y
zz/ / = z= z if if dd is equal to is equal to 11
= z = z -- ππππππππ if if dd is equal to is equal to --11
�� An alternate solution is to rotate by An alternate solution is to rotate by ππππππππ/2/2 or or --ππππππππ/2/2initially.initially.
CORDIC EquationsCORDIC Equations
Cordic Cordic AlgorithmsAlgorithms
�� Hardware has three accumulators Hardware has three accumulators xx, , yy and and zz
xxi+1i+1 = = xxii -- yyii*d*dii*2*2--ii
yyi+1i+1 = = yyii + + xxii * * ddii * 2* 2--ii
zzi+1i+1 == zzii -- ddii * tan* tan--11(2(2--ii))
�� Two modes of operationTwo modes of operation
—— Rotation ModeRotation Mode
—— Vector ModeVector Mode
Modes of OperationModes of Operation
Cordic Cordic AlgorithmsAlgorithms
xxi+1i+1 = x= xii--yyii*d*dii*2*2--ii
yyi+1i+1 = y= yii+x+xii*d*dii*2*2--ii
zzi+1i+1 = z= zii -- ddii*tan*tan--11(2(2--ii))
Rotation Mode of OperationRotation Mode of Operation
•Initialize three accumulators
by x0, y0 and z0
•Rotate to make the angle
accumulator z0 equal to 0.
•di = -1 if zi < 0
•di = 1 otherwise
•Final accumulator
values are xn, yn
and zn
xn=An*(x0cos(z0) - y0sin(z0))
yn=An*(y0cos(z0) + x0sin(z0))
zn= 0
Cordic Cordic AlgorithmsAlgorithms
Rotation ModeRotation Mode
�� General Vector Rotator : General Vector Rotator :
—— Rotates a vector Rotates a vector (x(x00,y,y00)) by an angleby an angle zz00..
�� Sine and Cosine Generator : Sine and Cosine Generator :
—— Initial Values Initial Values xx00=1/A=1/Ann, , yy00=0=0 and and zz00==θθθθθθθθ
—— Final Values Final Values xxnn=cos(=cos(θθθθθθθθ)), , yynn=sin(=sin(θθθθθθθθ)) and and zznn=0=0
�� Polar to Rectangular Coordinate Conversion :Polar to Rectangular Coordinate Conversion :
—— Initial Values Initial Values xx00=r=r, , yy00=0=0 and and zz00==θθθθθθθθ
—— Final Values Final Values xxnn=A=Annr cos(r cos(θθθθθθθθ)), , yynn= A= Annr sin(r sin(θθθθθθθθ)) and and zznn=0=0
xxnn = A= Ann*(x*(x
00cos(zcos(z00)) -- yy00sin(zsin(z
00))))
yynn = A= Ann*(y*(y
00cos(zcos(z00)) + x+ x
00sin(zsin(z00))))
zznn = 0= 0
Cordic Cordic AlgorithmsAlgorithms
xxi+1i+1 = x= xii--yyii*d*dii*2*2--ii
yyi+1i+1 = y= yii+x+xii*d*dii*2*2--ii
zzi+1i+1 = z= zii -- ddii*tan*tan--11(2(2--ii))
Vectoring Mode of OperationVectoring Mode of Operation
•Initialize three accumulators
by x0, y0 and z0
•Rotate to make the y
accumulator y0 equal to 0.
•di = -1 if yi > 0
•di = 1 otherwise
•Final accumulator
values are xn, yn
and zn
xn=An
yn = 0
zn = z0 + tan-1(y0/x0)
x y0
2
0
2+
Cordic Cordic AlgorithmsAlgorithms
Vectoring ModeVectoring Mode
�� Rectangular to Polar Coordinate ConversionRectangular to Polar Coordinate Conversion
—— xxnn is scaled magnitude and is scaled magnitude and zznn is the angle.is the angle.
�� zznn is is tantan--11(y)(y) if if xx00=1=1 and and zz00=0=0
xn=An
yn = 0
zn = z0 + tan-1(y0/x0)
x y0
2
0
2+
Cordic Cordic AlgorithmsAlgorithms
ConvergenceConvergence
X
Y
θ
V0 aligning with X axis.
V1 is incorrect.
Subsequent rotations to
V2, V3, … must correct
the error
Condition
tan-1(yi+1/xi+1) >
0.5*tan-1(yi/xi)
ensures convergence
V0
V1
V2
V3
V4
Cordic Cordic AlgorithmsAlgorithms
ConvergenceConvergence
�� Cordic Equations in the Rotation Mode and Vectoring Cordic Equations in the Rotation Mode and Vectoring Mode converge.Mode converge.
�� Error reduces in each iteration.Error reduces in each iteration.
�� Each Rotation makes the accumulators more correct. Each Rotation makes the accumulators more correct. Decide on the number of rotations from your Decide on the number of rotations from your application.application.
Cordic Cordic AlgorithmsAlgorithms
Functions covered Functions covered ……..
�� Vector Rotation.Vector Rotation.
�� Rectangular to Polar Coordinate ConversionRectangular to Polar Coordinate Conversion
�� Polar to Rectangular Coordinate ConversionPolar to Rectangular Coordinate Conversion
�� Sine, Cosine and Arctan GeneratorsSine, Cosine and Arctan Generators
Cordic Cordic AlgorithmsAlgorithms
Arcsine using Inverse CordicArcsine using Inverse Cordic
X
Y
X’
Y’
θθθθ
c
x0X-Y rotates to
X’-Y’
θθθθ = sin-1(c/x0) x c0
2 2−
Cordic Cordic AlgorithmsAlgorithms
ArcsineArcsineRotate the vector so thatRotate the vector so that yynn is equal to is equal to cc, a constant, a constant
xxi+1i+1 = x = x I I -- yyii*d*dii*2*2--ii
yyi+1i+1 = = yyii ++ xxii*d*dii*2*2--ii
zzi+1i+1 = z= zii -- ddii*tan*tan--11(2(2--ii))
wherewhere
ddii = +1= +1 if if y y ii< c< c, , --11 otherwiseotherwise
—— Initial Values : Initial Values : xx00=x=x00, , yy00=0=0 and and zz00=0=0
—— Final Values : Final Values : xxnn== , , yynn=c=c and and zznn=sin=sin--11(c/A(c/Annxx00))
(A x ) cn 0
2−
Cordic Cordic AlgorithmsAlgorithms
Arccosine using Inverse CordicArccosine using Inverse Cordic
X
Y
X’
Y’
θθθθ
c
x0X-Y rotates to
X’-Y’
θθθθ = cos-1(c/x0)
x c0
2 2−
Cordic Cordic AlgorithmsAlgorithms
ArccosineArccosineRotate the vector so thatRotate the vector so that xxnn is equal to is equal to cc, a constant, a constant
xxi+1i+1 = = xxii -- yyii*d*dii*2*2--ii
yyi+1i+1 = = yyii ++ xxii*d*dii*2*2--ii
zzi+1i+1 = z= zii -- ddii*tan*tan--11(2(2--ii))
wherewhere
ddii = = --11 if if xxii < c< c, , +1+1 otherwiseotherwise
—— Initial Values : Initial Values : xx0 0 = x= x00, , yy0 0 = 0= 0 and and zz0 0 = 0= 0
—— Final Values : Final Values : xxnn== , , yynn = c= c and and zznn==coscos--11(c/A(c/Annxx00))
(A x ) cn 0
2 2−
Cordic Cordic AlgorithmsAlgorithms
Convergence of Arcsine and Convergence of Arcsine and ArccosineArccosine
X
Y
c
y1
y3
Gain of 1/Ki in
each iteration
1 2 2i+ −1/Ki =
y2
• Due to gain 1/Ki , (y1-y3)/(y1-c) < 1/2, which does not
guarantee convergence
Cordic Cordic AlgorithmsAlgorithms
Convergence of Arcsine and Convergence of Arcsine and ArccosineArccosine
�� Double Iteration AlgorithmDouble Iteration Algorithm
—— For each iteration, rotate the vector twice For each iteration, rotate the vector twice instead of once.instead of once.
�� Double Iteration Algorithm makes the results of Double Iteration Algorithm makes the results of arcsine and arccosine more accurate. arcsine and arccosine more accurate.
Cordic Cordic AlgorithmsAlgorithms
General Cordic EquationGeneral Cordic Equation
�� Circular Coordinate Transforms : What has been Circular Coordinate Transforms : What has been presented so far.presented so far.
�� Cordic Equations can be extended to calculate Cordic Equations can be extended to calculate more functionsmore functions
—— Linear FunctionsLinear Functions
—— Hyperbolic Functions Hyperbolic Functions
Cordic Cordic AlgorithmsAlgorithms
Linear Cordic EquationsLinear Cordic Equations
xxi+1i+1 = x= xi i -- 0 * 0 * yyii * * ddii * 2* 2--i i = x= xii
yyi+1i+1 = y= yi i + + xxii * * ddii * 2* 2--ii
zzi+1i+1 = z= zii -- ddii * 2* 2--ii
�� Rotation ModeRotation Mode ((ddi i = = --11 if if zzii < 0< 0, , +1+1 otherwise) otherwise)
—— A multiplier with shifts and addsA multiplier with shifts and adds
—— Final Values:Final Values:
xxnn = x= x00
yynn = y= y0 0 + x+ x00zz00
zzn n = 0= 0
Cordic Cordic AlgorithmsAlgorithms
Linear Cordic EquationsLinear Cordic Equations
xxii+1+1 == xxii
yyii+1+1 == yyii ++ xxii ** ddii * 2* 2--ii
zzii+1+1 == zzii -- ddii * 2* 2--ii
�� Vectoring Mode (Vectoring Mode (ddi i = +1= +1 if if yyii<0<0, , --11 otherwise) otherwise)
—— Calculates the ratio Calculates the ratio yy00/x/x00 in in zz accumulatoraccumulator
—— xxn n = x= x00
yyn n = 0= 0
zzn n = z= z0 0 -- yy00/x/x00
Cordic Cordic AlgorithmsAlgorithms
x x i+1i+1 = cosh(= cosh(φφφφφφφφii) * ( ) * ( xxii + + yyii ** tanhtanh((φφφφφφφφii) )) )
y y i+1i+1 = cosh(= cosh(φφφφφφφφii) * ( ) * ( yyii + + xxii ** tanhtanh((φφφφφφφφii) )) )
z z i+1i+1 = = zzii -- φφφφφφφφii
Assume Assume tan(tan(φφφφφφφφii) = ) = ddii * 2* 2--ii where where ddi i = +1= +1 or or --11
φφφφφφφφii = = ddii ** tanhtanh--11(2(2--ii))
KKi i = cosh(= cosh(φφφφφφφφii) = cosh(tanh) = cosh(tanh--11(2(2--ii)) = 1/)) = 1/
HyperbolicHyperbolic CORDIC EquationsCORDIC Equations
1 2 2i− −
Cordic Cordic AlgorithmsAlgorithms
xxi+1i+1 = = xxii + + yyii * * ddii * 2* 2--ii
yyi+1i+1 = = yyii + + xxii * * ddii * 2* 2--ii
zzi+1i+1 = z= zii -- ddii ** tanhtanh--11(2(2--ii))
Multiply by Multiply by AAnn after n iterations to account for after n iterations to account for constants constants KKii
AAn n ==
Hyperbolic CORDIC EquationsHyperbolic CORDIC Equations
1 2 2i
i 1
n
− −
=
∏
Cordic Cordic AlgorithmsAlgorithms
Rotation ModeRotation Mode
�� Initialize with Initialize with xx00, , yy00 and and zz00..
�� The Hyperbolic Cordic Equations converge toThe Hyperbolic Cordic Equations converge to
xxnn = A= An n * ( x* ( x00 coshcosh(z(z00)) + y+ y00 sinhsinh(z(z00) )) )
yynn = A= An n * ( y* ( y00 coshcosh(z(z00)) + x+ x00 sinhsinh(z(z00) )) )
zznn = 0= 0
xi+1 = xi + yi * di * 2-i
yi+1 = yi + xi * di * 2-i
zi+1 = zi - di * tanh-1(2-i)
•Converge Angle Accumulator
z to 0.
•di = -1 if zi < 0, +1 otherwise
Cordic Cordic AlgorithmsAlgorithms
Vectoring ModeVectoring Mode
�� Initialize with Initialize with xx00, , yy00 and and zz00..
�� The Hyperbolic Cordic Equations converge toThe Hyperbolic Cordic Equations converge to
xxnn = A= Ann
yynn = 0= 0
zznn = z= z00 + + tanhtanh--11(y(y00/x/x00))
xi+1 = xi + yi * di * 2-i
yi+1 = yi + xi * di * 2-i
zi+1 = zi - di * tanh-1(2-i)
•Converge Accumulator y to
0.
•di = +1 if yi < 0, +1 otherwise
x y0
2
0
2−
Cordic Cordic AlgorithmsAlgorithms
�� Hyperbolic Equations require double iteration for Hyperbolic Equations require double iteration for convergenceconvergence
�� Hyperbolic functions similar to Trigonometric Hyperbolic functions similar to Trigonometric functions described earlier can be calculatedfunctions described earlier can be calculated
�� For more informationFor more information
—— Walther, J.S., Walther, J.S., ““A Unified algorithm for A Unified algorithm for elementary functionselementary functions””, Spring Joint Computer , Spring Joint Computer Conf, 1971, proc, pp. 379Conf, 1971, proc, pp. 379--385.385.
Hyperbolic Cordic EquationsHyperbolic Cordic Equations
Cordic Cordic AlgorithmsAlgorithms
Unified EquationsUnified Equations
xxii+1+1 = = xxi i -- m*m*yyii **ddii*2*2--ii
yyi+1i+1 = y= yi i + x+ xii*d*dii*2*2--ii
zzi+1i+1 = z= zii -- ddii**eeii
Unified Cordic EquationUnified Cordic EquationLinear Functions
m = 0 and ei = 2-i
xi+1 = xi
yi+1 = yi + xi * di * 2-i
zi+1 = zi - di * 2-i
Hyperbolic Functions
m = 1 and ei = tanh-1(2-i)
xi+1 = xi + yi * di * 2-i
yi+1 = yi + xi * di * 2-i
zi+1 = zi - di * tanh-1(2-i)
Trigonometric Functions
m = -1 and ei = tan-1(2-i)
xi+1 = xi - yi*di*2-i
yi+1 = yi + xi*di*2-i
zi+1 = zi - di*tan-1(2-i)
Cordic Cordic AlgorithmsAlgorithms
Bit Parallel ImplementationBit Parallel Implementation
>> i+-
register
register
>> i
x0
sign(yi)
y0
-mdi
+-
+-
register
ROM
sign(zi)
z0
-di
xi
yi
zi
Unified EquationsUnified Equations
xxii+1+1 = = xxi i -- m*m*yyii **ddii*2*2--ii
yyi+1i+1 = y= yi i + x+ xii*d*dii*2*2--ii
zzi+1i+1 = z= zii -- ddii**eeii
di
Cordic Cordic AlgorithmsAlgorithms
Bit Parallel ImplementationBit Parallel Implementation
+-
register
ROM
sign(zi)
z0
-di
zi
Hardwire for
constant ROM
contents
>> i
High Fanout
Slow in FPGAs
Cordic Cordic AlgorithmsAlgorithms
Unrolled Bit Parallel Unrolled Bit Parallel
+| +|
+|
>>0 >>0 const
signx0
y0 z0
+| +|
+|
>>1 >>1 const
sign
More Unrolled Cordic units …..
+| +|
+|
>>n >>n const
sign
xn ynzn
Hardwire if
possible
Cordic Cordic AlgorithmsAlgorithms
Bit Serial ImplementationBit Serial Implementation
Serial
Add-Sub
Serial
Add-Sub
X Register
Y Register
Z RegisterSerial
Add-SubSerial ROM
x0
y0
z0
xn
yn
zn
sign
sign
Cordic Cordic AlgorithmsAlgorithms
Bit Serial Implementation in VirtexBit Serial Implementation in Virtex
Z Register
Serial ROM
sign
D Q
C
CE
A[3:0]
SRL16E
4Tie to
Vcc
LUT used as
Serial In Serial Out
Shift Register
Cordic Cordic AlgorithmsAlgorithms
Bit Serial Implementation in VirtexBit Serial Implementation in Virtex
Serial
Add-Sub
X Register
x0
xn
16x1
Dual Port
RAM
Serial Data Out
Shifted Serial
Data OutModulo 16
Counter_1
Counter_1
lags
Counter_0
for
required
delay
A
DPRA
SPO
DPO
DSerial Data In
Modulo 16
Counter_0
Cordic Cordic AlgorithmsAlgorithms
�� Good hardware algorithm Good hardware algorithm
—— calculate various trigonometric and hyperbolic calculate various trigonometric and hyperbolic functions functions
—— Rotate Vectors appropriatelyRotate Vectors appropriately
—— Convert from one coordinate system to anotherConvert from one coordinate system to another
�� Pay attention to the convergence of the algorithm.Pay attention to the convergence of the algorithm.
Conclusion Conclusion
Cordic Cordic AlgorithmsAlgorithms
Andraka, R.J., Andraka, R.J., ““A survey of CORDIC algorithms for FPGA based A survey of CORDIC algorithms for FPGA based
computerscomputers””, FPGA , FPGA ‘‘98, Proc. Of the 1998 ACM/SIGDA sixth 98, Proc. Of the 1998 ACM/SIGDA sixth international symposium on Field Programmable Gate Arrays, Feb international symposium on Field Programmable Gate Arrays, Feb 2222--24, 1998, Monterey CA, pp 19124, 1998, Monterey CA, pp 191--200.200.
Volder, J., Volder, J., ““The CORDIC Trigonometric Computing TechniqueThe CORDIC Trigonometric Computing Technique””, IRE , IRE Trans. Electronic Computing, Vol ECTrans. Electronic Computing, Vol EC--8, pp3308, pp330--334, Sept 1959.334, Sept 1959.
Walther, J.S., Walther, J.S., ““A unified algorithm for elementary functionsA unified algorithm for elementary functions””, Spring , Spring Joint Computer Conf., pp. 379Joint Computer Conf., pp. 379--385, proc., 1971.385, proc., 1971.
Volder, J., Volder, J., ““Binary Computation algorithms for coordinate rotation and Binary Computation algorithms for coordinate rotation and function generationfunction generation””, Convair Report IAR, Convair Report IAR--1 148 Aeroelectrics Group, 1 148 Aeroelectrics Group, June 1956.June 1956.
ReferencesReferences