<<

ISSN: 2278 – 909X International Journal of Advanced Research in Electronics and Communication Engineering (IJARECE) Volume 1, Issue 3, September 2012 COMPUTING TECHNIQUE OF CORDIC ALGORITHM WITH MATLAB

DEEPESH RAWAT, ANKIT RAWAT

 . INTRODUCTION The CORDIC algorithm was first introduced by Volder[1] for Digital signal processing (DSP) algorithms exhibit Abstract— the computation of [2], multiplication, an increasing need for the efficient implementation of complex division and datatype conversion, and later on generalized to arithmetic operations. The computation of trigonometric by Walther . The CORDIC algorithm has functions, coordinate transformations or rotations of complex found its application in various field including the 8087 math valued phasors is almost naturally involved with modern DSP coprocessor[6], HP-35 calculator, radar signal processor, robotics algorithms. There are many hardware efficient algorithm, one etc. It is also used in computing Discrete Fourier, Discrete of which is set of shift add algorithm collective name as Cosine,Singular Value Decomposition and solving linear system. CORDIC for computing wide range of including Two basic CORDIC modes are known leading to the trigonometric functions, coordinate transformations or computation of different functions, the rotation mode and the rotations of complex valued phasors. In digital communications, vectoring mode. For both modes the algorithm can be realized as the straightforward evaluation of the cited functions is an iterative sequence of additions/subtractions and shift important, numerous matrix based adaptive signal processing operations, which are rotates by a fixed rotation (sometimes algorithms require the solution of systems of linear , called microrotations) but with variable rotation direction. In QR factorization or the computation of eigenvalues, MATLAB two main CORDIC functions are cordicpol2cart and eigenvectors or singular values. All these tasks can be efficiently cordicrotate, which are used to converts polar coordinates to implemented using processing elements performing vector Cartesian coordinates and to rotates a complex input respectively. rotations. The COordinate Rotation Digital Computer Each of these functions uses efficient CORDIC-based algorithm (CORDIC) offers the opportunity to calculate all the approximations to perform the their operation desired functions in a rather simple and elegant way. There are many articles covering various aspects of CORDIC algorithm CORDIC ALGORITHM but very few of them concentrate on the implementation in MATLAB. This paper is an attempt to define CORDIC The CORDIC method can be employed in two different algorithm how it works and explore the implementation using modes, namely, the rotation mode and the vectoring mode. In MATLAB. The CORDIC algorithm was first introduced by the rotation mode, the coordinate components of a vector and Volder the computation of trigonometric functions, an angle of rotation are given, and the coordinate components multiplication, division and datat type conversion, and later on of the original vector, after rotation through a given angle, are generalized to hyperbolic functions by Walther .Volder was inspired by the following formula in the 1946 edition of computed. In the vectoring mode, the coordinate the CRC Handbook of Chemistry and Physics: components of a vector are given, and the magnitude and -n angular argument of the original vector are computed. The KnRsin(θ ± ø) = R sin (θ) ± 2 R cos(θ) CORDIC algorithm performs the rotation of a vector in both -n KnRcos(θ ± ø) = R cos (θ) ± 2 R sin(θ) modes as a sequence of micro-rotations by elementary With K = (1+ 2-2n1/2 ) ½ , recalled from ROM. The number of micro-rotations for a n given precision is decided by radix being used for the -n tan(ø) =2 implementation of CORDIC algorithm. In this section we present the basic CORDIC iteration before discussing the implementation in MATLAB, which consists of a sequence Index Terms — CORDIC, Cos, MATLAB, Rotation magnitude, of these iterations. , Vector magnitude. CORDIC can be used to calculate a number of different functions. This explanation shows how to use CORDIC in rotation mode to calculate sine and cosine of an angle, and Manuscript received Aug 15, 2012. assumes the desired angle is given in radians and represented DEEPESH RAWAT, MTECH (DIGITAL COMMUNICATION)/ BTKIT in a fixed point format. To determine the sine or cosine for an DWARAHAT/,UTTARAKHAND TECHNICAL UNIVERSITY., angle β, the y or x coordinate of a point on the unit SRINAGARGARHWAL UTTARAKHAND, INDIA/MOBILE NO .8791137906 corresponding to the desired angle must be found. Using ANKIT RAWAT, MTECH (DIGITAL COMMUNICATION)/ BTKIT CORDIC, we would start with a circle of radius 1, and DWARAHAT/,UTTARAKHAND TECHNICAL UNIVERSITY., represent by vactor v0, = (1,0) SRINAGARGARHWAL UTTARAKHAND, INDIA/MOBILE NO. 8171494899

51 All Rights Reserved © 2012 IJARECE ISSN: 2278 – 909X International Journal of Advanced Research in Electronics and Communication Engineering (IJARECE) Volume 1, Issue 3, September 2012

checking if n + 1 is positive and we need to rotate clockwise or if it is negative we must rotate counterclockwise in order to get closer to the wanted angle β. -1 Example : Rewriting angle in terms of φ j so that φ j = tan (2-j) Let chosse angle 600 and decompose by performing micro rotation as shown in Fig 3

Fig 1 Rotation Of Unit Circle by β Fig 2. Rotation to next coordinate by φ

The CORDIC method depends on the Givens rotation transform, which expresses the coordinates of a point in two Fig 3. Calculation of φ by Micro Rotation different coordinate systems, rotated by a certain angle about their common origin. In the first system point has Let us start with φ = 450(< 600) coordinates (x,y) and in the second system the same point P 0 φ = 26.60 , 450 + 26.60= 71.60 (>600) has coordinates (x'y'),where 1 φ = 140 , 71.60 – 140 = 57.60 (< 600) x= cosβ; 2 φ = 7.10, 57.60 +7.10 = 64.70 (> 600) y=sinβ; 3 φ = 3.10, 64.70 – 3.10 = 61.40 (>600) Now after rotation of vector at coordinates (x'y'), 4 φ = 1.80, 61.40 – 1.80 = 59.60 (< 600) x'=cos(β +φ)=cosβcosφ –s inβsinφ 5 φ = 0.90,59.60 + 0.90 = 60.50 (> 600) = xcosφ-ysinφ…………………………….…….(1) 6 φ = 0.40, 60.50 – 0.40 = 60.10 (> 600 y’= sin(β+φ)=sinβcosφ – cosβsinφ 7

= ycosφ+xsinφ………………………………….(2) Rotation Mode: In this mode the initial vector (X , Y ) is Rearrange these as-: in in rotated by an angle θ. The resulting values of x and y provide x’= cosφ(x – ytan φ) the trigonometric functions, and follows the sequence below: y’= cosφ(y + xtanφ) To avoid the multiplication, rotation is decompose into 1. An initial vector (Xin , Yin ) is rotated by an angle θ; number of microrotation,thus above equation can be written 2. The angle accumulator is initialized with the value of θ; as-: x R[j + 1] = cos(φ j)(x R [j] - y R [j] tan(φ j)) 3. A sequence of rotations where each angle is of magnitude -1 -n y R [j + 1] = cos(φ j)(y R [j] + x R [j] tan(φj)) tan (2 )is applied; Elementary angle can be taken as -1 -j -1 -j 4. At each step the of the angle ρN is chosen to reduce the φ j = tan ρ j (2 ) = ρ j tan (2 ) with ρ j = {-1,1} so the above result in rotation extension can be written as-: angle accumulator; -j x R[j + 1] = cos(φ j)(x R [j] - y R [j] ρ j (2 )) 5. So ρn is simply chosen according to the value of the angle -j y R [j + 1] = cos(φ j)(y R [j] + x R [j] ρ j (2 )) accumulator . Rotation ρ j extension modulus is n n -j -1/2 The equations for rotation mode are: K= ∏ j=1 cos(φ j) = ∏ j=1(1 + 2 ) = 1.646760258121 n and ρ j can have the values of −1 or 1 and is used to determine Xn+1=Xn-Yn.ρn.2 the direction of the rotation: if the angle β is positive then ρj is n 1, otherwise it is −1. Yn+1=Yn+Xn.ρN.2 -1 -n We can ignore K i in the iterative process and then apply it Zn+1=Zn - ρn tan (2 ) afterward by a scaling factor:[3] Where ρN = -1 if ZN. <0,+1otherwise. At the end of the algorithm, the results are:

X=K[Xin cos(θo)-Yin. sin(θo)]

Y=K[Yin cos(θo)+Xin. sin(θo)] which is calculated in advance and stored in a table, or as a single constant if the number of iterations is fixed. This θn= 0 correction could also be made in advance, by scaling and hence saving a multiplication. To allow further reduction of the algorithm's complexity. After a sufficient number of iterations, the vector's angle will be close to the wanted angle These equations provide both the length of the vector and add β. The only task left is to determine if the rotation should be the tangent to any initial angle placed in clockwise or counterclockwise at every iteration. This is done by keeping track of how much we rotated at every angle accumulator. The sine and cosine functions are iteration and subtracting that from the wanted angle, and then performed in the rotation mode. In order to compute the sine

52 All Rights Reserved © 2012 IJARECE

ISSN: 2278 – 909X International Journal of Advanced Research in Electronics and Communication Engineering (IJARECE) Volume 1, Issue 3, September 2012 or cosine of an angle θ, the Z register will be initialized with Zn = Z0 + asin(c/KnX0) θ, Y with 0, and the X with 1. The X register corresponds to Start with a vector on the x axis and rotate it so that its y the scaled cosine value, and the Y register to the sine value. component is c. The algorithm has good precision when We can determine the unscaled value by dividing the final -1< c/KnX0<+1 values by K (1.6468). As the input approaches +/- 1, the error increases rapidly. The loss of accuracy is due to the gain of the rotation. When the Software Implementation vector is close to the y axis, the vector is shorter than the The software implementation is developed in MATLAB reference. language and provides niters, cordicsine, cordiccosine, cordicpol2cart and cordicrotate, in the toolbox. Niters which represent the number of iterations input argument is now an optional input to all CORDIC functions. If the number of iterations is not specify or if value specify is too large for the word length, the maximum reasonable number of iterations is used automatically. Cordicpol2cart converts polar coordinates to Cartesian coordinates. Cordicrotate rotates a complex input. Each of these functions uses efficient CORDIC-based approximations to perform the conversion and rotation. To calculate the sine and cosine functions, the CORDIC algorithm in rotational mode is used. The initial conditions are:

X0 = 1/K

Y0= 0 Using these condition above equation reduce to-

Xn = cos(θo)

Yn= sin(θo)

For the arccosine, we can use the same equation as we used for arcsine and replace the condition for ρ: ρn is +1 if Yn < c, -1 otherwise, or simply calculate arcsine and use the following equality acos(θo) = π/2- asin(θo)

To calculate the arcsine function, the CORDIC algorithm is used in vector mode. The condition for ρ is: ρn is +1 if Yn < c, -1 otherwise, c= input argument rotation produce following equation 2 2 1/2 Xn = ((K0 X0 ) - c ) Y = c n

53 All Rights Reserved © 2012 IJARECE ISSN: 2278 – 909X International Journal of Advanced Research in Electronics and Communication Engineering (IJARECE) Volume 1, Issue 3, September 2012

CONCLUSION

The CORDIC Algorithm presented in this paper is well known in the research and is especially suitable for use in a special purpose computer where the majority of computation involve trigonometric relationships. This algorithm have been developed for many other mathematical operation such as multiplication, division square root, hyperbolic function logarithms and exponential. Increasing the number of CORDIC iterations can produce more accurate results, but it also increases the expense of the computation and adds latency REFERENCES [1] J. E. Volder, The CORDIC trigonometric computing technique," IRE Trans.Electronic Computers. [2]J.E. Volder. The Birth of Cordic. The Journal of VLSI Signal Processing, 25(2):101-105, 2000. [3] Wikipedia. Cordic.http://en.wikipedia.org/wiki/CORDIC. [4] Wikipedia. Hp-35. http://en.wikipedia.org/wiki/HP-35. [5] J. S. Walther, ―A unified algorithm for elementary functions‖, Proc. AFIPS spring Joint Comput. [6]Survey of CORDIC algorithms for FPGA based computers –R.Andraka. [7]. Ed Agis et. al. Global, Interoperable Broadband Wireless Networks: Extending WiMAX Technology to Mobility. Intel Technology Journal, 8(3):173-187, 2004. [8].Z. Becvar and J. Zelenka. Handovers in Mobile WiMAX. Research in Telecommunication Technology, 1:147-150, 2006, ISBN 80-214-3243-8. [9]. S. Das et al. System Aspects and Handover Management for IEEE 802.16e. Bell Labs Technical Journal, 11(1): 123-142, 2006.

Deepesh Rawat received BTech degree in Electronics And Communication from Grukula Kangri Vishwavidyalaya,Haridwar Uttarakhand in 2010 and present pursuing MTech from BTKIT Dwarahat. His current research interests work include digital image processing, computer network and digital communication.

Ankit Rawat received BTech degree in Electronics And Communication from Uttranchal Institute of Technology, Uttarakhand in 2010 and present pursuing MTech from BTKIT Dwarahat. His current research interests work include digitsl signal processing and digital communication

54 All Rights Reserved © 2012 IJARECE