Computing Technique of Cordic Algorithm with Matlab
Total Page:16
File Type:pdf, Size:1020Kb
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 trigonometric functions[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 hyperbolic functions 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 function 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 angle (sometimes algorithms require the solution of systems of linear equations, 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 angles 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. Sine, 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 circle 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 equation 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 sign 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.