cordic算法详解

合集下载

cordic算法求角度的verilog实现

cordic算法求角度的verilog实现

cordic算法求角度的verilog实现摘要:1.引言2.Cordic 算法简介3.Verilog 实现角度计算的Cordic 算法4.结论正文:1.引言Cordic 算法是一种高效的计算三角函数的算法,特别是在数字信号处理、图像处理和通信系统等领域中。

Cordic 算法的基本思想是将三角函数的计算分解为简单的移位、加法和查表操作。

在此文中,我们将讨论如何使用Verilog 硬件描述语言实现Cordic 算法来计算角度。

2.Cordic 算法简介Cordic 算法是一种用于计算正切、余切、正割和余割等三角函数的算法。

其优点在于避免了除法运算,从而降低了计算的复杂度。

Cordic 算法的核心思想是将三角函数的计算分解为一系列简单的移位、加法和查表操作。

3.Verilog 实现角度计算的Cordic 算法在Verilog 中实现Cordic 算法非常简单。

首先,我们需要定义一个查找表,用于存储Cordic 算法所需的所有参数。

接下来,我们需要实现一个状态机,用于控制算法的执行流程。

最后,我们需要实现一个查表模块,用于根据输入角度和查找表的参数值计算三角函数值。

下面是一个简单的Verilog 代码示例,用于实现Cordic 算法计算角度的功能:```verilogmodule cordic_algorithm(input wire clk,input wire reset,input wire [15:0] in_angle,output reg [15:0] out_angle);// 定义查找表reg [15:0] lookup_table [0:15] = "{16"h0000, 16"h0024, 16"h0048, 16"h0072, 16"h0096, 16"h00B0, 16"h00D4, 16"h00F8,16"h010C, 16"h012E, 16"h014C, 16"h0168, 16"h0184,16"h01AD, 16"h01CE, 16"h01EF};// 定义状态机reg [3:0] state;reg [31:0] accumulator;reg [31:0] result;always @(posedge clk or posedge reset) beginif (reset) beginstate <= 4"b0;accumulator <= 32"b0;result <= 32"b0;end else begincase (state)4"b0: begin// 初始化累积器和结果寄存器accumulator <= 32"b0;result <= 32"b0;state <= 4"b1;end4"b1: begin// 计算结果result = accumulator;state <= 4"b2;end4"b2: begin// 查找表查找result = lookup_table[result];state <= 4"b3;end4"b3: begin// 更新累积器accumulator = (accumulator << 1) + (in_angle << (32 - 1));state <= 4"b0;endendcaseendendassign out_angle = result;endmodule```4.结论本文介绍了如何使用Verilog 硬件描述语言实现Cordic 算法来计算角度。

cordic算法求角度的verilog实现

cordic算法求角度的verilog实现

cordic算法求角度的verilog实现摘要:1.引言2.CORDIC 算法原理3.Verilog 实现4.测试与结果5.结论正文:1.引言CORDIC(Coordinate Rotation Digital Computer,坐标旋转数字计算法)算法是一种求解正切、余切、正弦、余弦等三角函数的算法。

该算法通过迭代坐标旋转的方式,实现角度的精确计算。

在FPGA 设计和数字信号处理领域,CORDIC 算法有着广泛的应用。

本文将介绍一种基于Verilog 的CORDIC 算法实现,以及如何用于求解角度。

2.CORDIC 算法原理CORDIC 算法的基本思想是利用简单的移位、加法和查表运算,迭代计算三角函数值。

以计算正切函数为例,假设输入角度为θ,初始化两个坐标轴(I 和Q)的值都为1,然后进行迭代计算:1)计算k*I + d*Q,其中k 为角度的整数部分,d 为角度的小数部分,I 为余弦值,Q 为正弦值。

2)更新I 和Q 的值:I = I * cos(d) - Q * sin(d),Q = I * sin(d) + Q *cos(d)。

3)判断是否达到精度要求,如果满足则输出结果,否则继续迭代。

3.Verilog 实现以下是一个基于Verilog 的CORDIC 算法求角度的实现:```verilogmodule cordic_algorithm(input wire clk,input wire reset,input wire angle_in,output reg angle_out);reg [31:0] I;reg [31:0] Q;reg [31:0] k;reg [31:0] d;always @(posedge clk or posedge reset) beginif (reset) beginI <= 1;Q <= 1;k <= 0;d <= 0;end else begin// 计算k*I + d*Q[31:0] temp_k = {angle_in[31:0], k[31]};[31:0] temp_d = {angle_in[31:0], d[31]};k <= temp_k;d <= temp_d;// 更新I 和Q 的值I <= I * cos(d) - Q * sin(d);Q <= I * sin(d) + Q * cos(d);// 判断是否达到精度要求if (abs(angle_in - (I + Q)) < 1) beginangle_out <= 32"b0;end else beginangle_out <= 32"b1;endendendendmodule```4.测试与结果为了验证CORDIC 算法的正确性,我们可以编写测试平台并在FPGA 上运行。

cordic算法估算相位和幅度值

cordic算法估算相位和幅度值

CORDIC(COordinate Rotation DIgital Computer)算法是一种基于硬件实现的迭代算法,常用于数字信号处理中的相位和幅度值的估算。

该算法通过迭代旋转输入的坐标,从而快速计算出所需的值。

在估算相位和幅度值的应用中,CORDIC算法可以有效地降低硬件资源的消耗,提高计算效率。

下面将详细介绍CORDIC算法在估算相位和幅度值中的应用。

相位值的估算------相位是描述信号在时间上的相对位置的参数。

在数字信号处理中,通常需要快速估算信号的相位。

CORDIC算法可以通过迭代旋转输入的坐标,快速得到信号的相位值。

具体来说,CORDIC 算法通过旋转输入的坐标,使得相位差逐渐减小,最终达到所需的相位值。

CORDIC算法的实现步骤如下:1. 初始化输入坐标为零,迭代次数为零。

2. 执行迭代过程,每次迭代旋转输入坐标一次,根据旋转角度和迭代次数计算出新的坐标。

3. 判断迭代是否达到所需的相位值,如果没有达到则继续迭代,否则输出结果。

通过CORDIC算法估算相位值具有以下优点:* 硬件资源消耗少,适用于资源受限的环境。

* 计算效率高,能够快速得到所需的相位值。

幅度值的估算------幅度是描述信号振幅大小的参数。

在数字信号处理中,通常需要快速估算信号的幅度。

CORDIC算法同样可以通过迭代旋转输入的坐标,快速得到信号的幅度值。

具体来说,CORDIC 算法通过旋转输入的坐标,使得幅度逐渐增大,最终达到所需的幅度值。

CORDIC算法的实现步骤如下:1. 初始化输入坐标为零,迭代次数为零,幅度值为零。

2. 执行迭代过程,每次迭代旋转输入坐标一次,根据旋转角度和迭代次数更新输入坐标、迭代次数和幅度值。

3. 判断迭代是否达到所需的幅度值,如果没有达到则继续迭代,否则输出结果。

通过CORDIC算法估算幅度值具有以下优点:* 适用于各种信号处理场景,包括调制、解调、滤波等。

* 计算效率高,能够快速得到所需的幅度值。

cordic反旋转迭代算法

cordic反旋转迭代算法

cordic反旋转迭代算法
CORDIC(Coordinate Rotation Digital Computer)反旋转迭代算法是一种用于计算旋转、平移和缩放的数学算法。

它可以用于计算三角函数、对数函数以及其他一些数学函数。

CORDIC算法的核心思想是通过迭代的方式将一个向量旋转到目标方向,同时伴随着一个缩放因子的变化。

具体步骤如下:
1. 初始化:给定一个初始向量(x, y)和一个目标旋转角度θ。

2. 迭代计算:重复以下步骤直到达到预设的精度或迭代次数:
- 对于每一次迭代,计算旋转角度d为θ的2^(-n)倍,其中n为迭代次数。

- 根据旋转角度d,计算cos(d)和sin(d)的近似值。

- 根据近似值和当前向量的x、y分量,计算旋转后的新向量(x', y')。

- 更新当前向量的x、y分量为新向量的x、y分量。

3. 输出结果:当达到预设的精度或迭代次数后,向量(x, y)即为旋转后的结果。

CORDIC算法的关键之处在于通过迭代的方式逼近旋转角度,并且利用三角函数的近似值进行计算,从而减少了计算量。

此外,CORDIC算法还可以通过反向迭代来实现反旋转操作。

总结起来,CORDIC反旋转迭代算法是一种通过迭代逼近旋转角度,并利用三角函数的近似值计算旋转后向量的算法。

它可以用于计算旋转、平移和缩放等数学运算。

cordic核相位计算

cordic核相位计算

cordic核相位计算
CORDIC(Coordinate Rotation Digital Computer,坐标旋转数字计算机)是一种用于计算三角函数(如正弦、余弦、反正弦、反余弦)和超越函数(如对数、指数)的算法。

它最初是为了在数字计算机上执行旋转和平移操作而开发的,但后来被发现可以用于计算各种三角函数和超越函数。

CORDIC算法通过迭代的方式,将旋转操作分解为一系列微小的旋转步骤,每一步都只涉及简单的移位和加减运算。

这种迭代的特性使得CORDIC算法非常适合硬件实现,尤其是在没有专门的三角函数计算单元的情况下。

因此,CORDIC算法被广泛应用于数字信号处理、通信系统、图形处理器和其他需要高效计算三角函数的领域。

在CORDIC算法中,相位计算是其中一个重要的应用。

通过迭代的方式,CORDIC可以有效地计算给定角度的正弦和余弦值,从而间接地计算出该角度的相位值。

通过不断迭代,CORDIC可以在有限的步骤内逼近任意给定的相位角度,因此在相位计算中具有很高的效率和精度。

总的来说,CORDIC算法通过迭代的方式,将复杂的三角函数和
超越函数计算转化为简单的移位和加减运算,使得在没有专门的三角函数计算单元的情况下,也能高效地进行这些计算。

在相位计算中,CORDIC算法可以通过迭代逼近任意给定的相位角度,具有高效和精确的特点。

因此,CORDIC算法在相位计算以及其他三角函数和超越函数计算方面有着广泛的应用。

cordic算法求角度的verilog实现 -回复

cordic算法求角度的verilog实现 -回复

cordic算法求角度的verilog实现-回复Cordic算法,全称为Coordinate Rotation Digital Computer算法,是一种用于计算三角函数以及其它相关函数的数值方法,它以固定点运算和迭代的方式实现高效的角度计算。

在本文中,我们将详细解释Cordic算法的原理,并给出一个Verilog的实现。

一、Cordic算法的原理Cordic算法是通过将一个向量旋转到目标角度来求角度的方法。

具体而言,Cordic算法使用一个旋转矩阵,通过一系列迭代将原始向量旋转到目标角度。

在每一次迭代中,算法会根据当前向量的角度与目标角度的差值,选择旋转矩阵中的一个旋转角度,将当前向量旋转一定的角度。

二、Cordic算法的基本流程Cordic算法的基本流程如下:1. 初始化:将初始向量以及目标角度设置为输入参数;2. 迭代计算:通过一系列的迭代,将原始向量旋转到目标角度;3. 输出结果:将最终的向量的角度作为输出结果。

三、Cordic算法的迭代计算在Cordic算法的迭代计算中,每一次迭代都会选择一个旋转角度,并将当前向量旋转到该角度。

为了提高计算效率,Cordic算法中使用了一种近似的旋转角度,称为Cordic常数。

四、Cordic常数的计算Cordic常数是在Cordic算法中用于近似旋转角度的固定常数。

Cordic常数的计算是一个关键的步骤,通常使用二进制表示法进行计算。

Cordic 常数可以根据所需的精度和性能来调整,一般越精确的结果会需要更多的迭代次数。

五、Cordic算法的Verilog实现下面是Cordic算法的Verilog实现的基本代码框架:verilogmodule cordic(input [N-1:0] x_in,input [N-1:0] y_in,input [M-1:0] angle_in,output [N-1:0] x_out,output [N-1:0] y_out);定义Cordic常数parameter M = 32; Cordic常数的位宽parameter [M-1:0] c = ; Cordic常数的值定义迭代次数parameter K = ; 迭代次数定义内部变量reg [N-1:0] x_internal;reg [N-1:0] y_internal;always *begin初始化内部变量x_internal = x_in;y_internal = y_in;迭代计算for (i = 0; i < K; i = i + 1)beginif (y_internal > 0)beginx_internal = x_internal + (y_internal >> i);y_internal = y_internal - (x_internal >> i);angle_in = angle_in - c[i];endelsebeginx_internal = x_internal - (y_internal >> i);y_internal = y_internal + (x_internal >> i);angle_in = angle_in + c[i];endendendassign x_out = x_internal;assign y_out = y_internal;endmodule六、Cordic算法的应用Cordic算法在计算机图形学、数字信号处理等领域有着广泛的应用。

cordic 正弦算法 c语言

cordic 正弦算法 c语言

cordic 正弦算法 c语言Cordic(COordinate Rotation DIgital Computer)算法是一种用于计算三角函数(如正弦和余弦)的快速算法。

它可以在没有乘法器的情况下实现高效的三角函数计算,因此在一些资源受限的环境中非常有用,比如嵌入式系统或者硬件设计中。

Cordic算法的核心思想是通过迭代的方式,将一个给定角度的旋转分解成一系列微小的旋转,每次旋转都可以通过简单的移位和加减操作来实现。

这样的迭代过程可以在有限的步数内逼近目标角度,从而计算出正弦和余弦值。

下面是一个简单的C语言实现的Cordic正弦算法的示例:c.#include <stdio.h>。

#include <math.h>。

#define N 15 // 迭代次数。

void cordic_sine_cosine(double beta, double s, double c) {。

int i;double factor = 1.0;double angle = 0.0;double K = 0.6072529350088812561694; // K =0.6072529350088812561694 for 16 iterations.for (i = 0; i < N; i++) {。

double sigma = (beta < 0) ? -1 : 1;double temp = c;c += sigma factor s;s -= sigma factor temp;beta -= sigma angle;factor = K;angle = atan(1.0 / (1 << i));}。

}。

int main() {。

double angle = 45.0; // 输入角度。

double radian = angle M_PI / 180; // 角度转换为弧度。

cordic 指数运算 c

cordic 指数运算 c

cordic指数运算cCORDIC(Coordinate Rotation Digital Computer)是一种用于计算三角函数和其它复杂函数的算法。

在CORDIC中,指数运算通常是通过迭代旋转操作实现的。

以下是CORDIC中指数运算的简要描述:1.初始化:首先,需要初始化一些参数,如初始角度、旋转方向等。

2.迭代旋转:CORDIC使用一系列旋转操作,每次旋转一个小角度,通过迭代达到目标角度。

这些旋转操作通常是通过微调旋转矩阵实现的。

3.计算指数:在每次旋转后,可以通过一系列的位移和累加操作来逼近目标指数。

这涉及到一些查表和迭代的过程。

4.迭代终止:当达到预定的迭代次数或满足精度要求时,迭代过程终止,得到最终的指数值。

在C语言中,CORDIC算法的实现可能涉及到使用循环结构和一些基本的数学运算,例如加法、乘法和位移操作。

以下是一个简单的伪代码示例:```c#include<stdio.h>#include<math.h>#define ITERATIONS16double cordic_exp(double angle){double x=1.0;//初始值double y=0.0;double z=angle;for(int i=0;i<ITERATIONS;++i){double x_temp=x;x+=y*pow(2,-i);y-=x_temp*pow(2,-i);z-=atan(pow(2,-i));}return x;}int main(){double result=cordic_exp(1.0);//计算e的近似值printf("e的近似值:%f\n",result);return0;}```请注意,这只是一个简单的示例,实际的CORDIC实现可能会更加复杂,具体取决于所需的精度和性能。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

CORDICThe calculus courses provide us with tools to compute the values of trigonometric functions,for example,via series expansions, polynomial,and rational function approximations.However,these implementations tend to require multiplication and division operations that make them expensive in hardware.In contrast,CORDIC(COrdinate Rotation Digital Computer)algorithms need only adders,shifters and comparators for computing a wide range of elementary functions.The method is especially efficient whenfixed point implementations of signal processing algorithms on hardware are considered.For example,CORDIC is extremely popular in hardware accelerators and also in SIMD(Single-Instruction Multiple Data)realizations.Furthermore,almost all function calculators employ CORDIC. Intel processors used CORDIC for trigonometric functions till80486.CORDIC is a good choice for hardware solutions such as FPGA in which cost(gate count)minimization is more important than throughput maximization.In software implementations CORDIC enables most of the code and data be shared between routines for trigonometric and hyperbolic functions,helping to conserve memory.CORDIC algorithm is often used to implement rotations needed in modulators and demodulators.CORDIC algorithm was introduced in1959by Volder for implementing a real-time navigation computer for aeronautical appli-cations.The algorithm was initially formulated for computing the values of trigonometric functions.In early1970s the CORDIC techniques were extended to exponential,logarithm,forward and inverse circular and hyperbolic functions,ratios and square roots(Walther1971).Its concepts have also been developed to include calculation of the Discrete Fourier Transform(Despain 1974).More recently(Bajard et al1994)efficient hardware technique known as BKM for computing complex exponentials and trigonometric functions was proposed and has since been very widely applied.13.1CORDIC Fundamentals:Vector RotationIn this section,we consider computation of vector rotation illustrated in Fig.1,which maps vector(x,y)to(x′,y′)according to the equationsx′=x cosφ−y sinφ(1)y′=y cosφ+x sinφwhereφis a rotation angle.Note that four multiplications and two additions are needed to compute x′and y′provided that the values of cosφand sinφare available.1If this is not the case,we might consider computing them digitally by series expansion, which is obviously complex.Figure1:Rotation of vector(x,y)vector byφdegrees.3.1.1Concatenation of rotationsAs afirst step towards the CORDIC implementation,we note that ifφ=φa+φb,we mayfirst map(x,y)to(x′′,y′′)using the angleφa,and then map(x′′,y′′)to(x′,y′)using the angleφb.So,it is possible to concatenate mappings for angles φi,(i=0,...,N−1)in order to evaluate the mapping forφ= N−1i=0φi.In the following,we will denote with(x i,y i)and(x i+1,y i+1)the input and output to the rotation byφi:x i+1=x i cosφi−y i sinφi(2)y i+1=y i cosφi+x i sinφi3.1.2Applying arithmetic shift and additionTo proceed,let us assume that−π/2<φi<π/ing tanφ=sinφ/cosφ,equation(2)can be rewritten asx i+1=cosφi(x i−y i tanφi)(3)y i+1=cosφi(y i+x i tanφi)which suggests the computational structure shown in Fig.2.Note that cosφi=cos(−φi)and tanφi=−tan(−φi),so the mapping for a negative angle−φi is the same as forφi except the change of signs in the terms involving the tangent. Multiplication by a power of two corresponds to the arithmetic shift operation,which is cheap to implement.The main idea of the CORDIC algorithm is that multiplication by tanφi can be based on shifting,whentanφi=±2−i,i∈{0,1,2,...}.Under this condition,(3)becomesx i+1=cosφi(x i−d i·y i·2−i)y i+1=cosφi(y i+d i·x i·2−i)(4)3Figure2:Organizing computations of the transform.For some specific anglesφi,multiplication by tanφi can be replaced by an arithmetic shift and some sign manipulation.where d i=+1,ifφi>0,and d i=−1,ifφi<0.Thus,substituting d i=−1for d i=+1corresponds to swapping of signs of the second terms within parentheses,that is,subtraction becomes addition and vice versa.3.1.3Gain compensationHowever,(4)contains still multiplications by cosφi,and if several rotations were concatenated,we would have lots of multipli-cations.To solve the problem,wefirst notice thatφi=arctan(2−i),i∈{0,1,2,...}and√cosφi=cos(arctan(2−i))=1/√Then we divide both sides of(4)by cosφi=1/√1+2−2i.Now,the right hand sides contain just the the shift-and-addition parts of computation,and we get x i+1 and y i+1amplified by the gain a i.To see,how to compensate for the gain,let us multiply by a constant A i both sides in(5),and let A i+1=a i A i.As a result,we get recursive equationsx i+1·A i+1=x i A i−d i·y i A i·2−iy i+1·A i+1=y i A i+d i·x i A i·2−i.(6) These equations give the output of a chain of blocks,where just the shift-add parts of the rotations are computed,and multiplications by cosφi are neglected.After N such steps,we must multiply the results by1/A N to get x N and y N.The value of the gain A N can be calculated usingA N=N−1 i=0√Table1:The gain values tabulated till iteration9.Iteration i Iteration i0516273849component might not be needed as d i’s can be precomputed and tabulated.In the table below we have precalculated thefirst six entries of an arctan(2−i)look-up table.Table2:Precalculated thefirst six entries of an arctan(2−i).Iteration i arctan(2−i)[deg]0.7854126.570.245037.130.06245 1.793.2Using the CORDIC algorithmThe CORDIC algorithm is usually employed in two ways with the number of iterations isfixed in the beginning:1.rotate an input vector by given angle and output the resulting vector2.rotate the given input vector onto the x axis and output the require rotation angle73.2.1Example:Rotating an input vectorLet us initialize z i with the value of the desired rotation angle and then start the iterations of the algorithm using the following equationsx i+1·a i=x i−d i·y i·2−iy i+1·a i=y i+d i·x i·2−iz i+1=z i−d i·arctan(2−i)whered i= −1if z i<0+1otherwiseThe following is an example on rotating an input vector by30degreesFor the reasons of simplicity we initially calculate the resulting angle at four bits of precision(for some reason this expression is used in literature although the relationship between the angle and2−i is a non-linear one).Initially,we let z0=30and start iterating the angle calculations.Notice that this gives us the values of d(direction)needed in calculating the vector coordinates at each iteration.i d i z i+1[deg][deg]0+130.00−45.00=−15.00−15.0026.570.500/0.10002+111.57−14.04=−2.47−2.477.130.125/0.00104......We assume(x0,y0)=(1,0),and notice that z0=30is greater or equal to0,so d0=1,and getx1=x0−d0·y0·2−0=1y1=y0+d0·x0·2−0=1z1=z0−d0·arctan(2−0)=−15degreesNow z1=−15<0,so d1=−1,and the next iteration becomesx2=x1−d1·y1·2−1=1.5y2=y1+d1·x1·2−1=1.5z2=z1−d1·arctan(2−1)=11.57degreesFor convenience,in this example the outcomes of the calculations are presented decimal to avoid the additional understanding effort from binary-to-decimel conversions.In reality,everything should be done in binary arithmetics.As the angle z2is now positive,d2=1.Thenx3=x2−d2·y2·2−2=1.375y3=y2+d2·x2·2−2=0.875z3=z2−d2·arctan(2−2)=−2.47degreesThe angle z3is negative,so d3=−1.We getx4=x3−d3·y3·2−3=1.484y4=y3+d3·x3·2−3=0.703z4=z3−d3·arctan(2−3)=4.66degreesFinally,we perform(a rough)gain correction to obtain0.6073·x4=0.9010.6073·y4=0.4269We can repeat the above calculation in binary representation in which the multiplications by2−i become respective arithmetic shifts to the right.3.3Angle/radius calculation using rotatorThe rotator algorithm can be modified to compute the polar coordinates of the Cartesian coordinates2.The idea is to determine rotationφfor which y′=0in(1).Let us denote the unknown radius with r and the unknown angle withα.When y′=0,φmust be−α,and thereforex′=x cosφ−y sinφ=(r cosα)cos(−α)−(r sinα)sin(−α)=r,so after rotation x′will give the unknown radius(see Fig.4).3.3.1Determining rotation directionsLogic for determining the rotation direction d i must be based on checking the value of y i.Let us assume that the point(x i,y i) lies in the I or IV quadrant,that is,x i≥0.We note that if y i<0we should rotate counterclockwise,and if y i>0,we should rotate clockwise.Let z i correspond to the sum of rotations in clockwise direction,that is,it will converge toα.Then,we have the angle accumulation formulaz i+1=z i−d i·arctan(2−i)(10) with the decision rule(11)d i= −1if y i A i>0+1otherwise.Figure4:Rectangular to polar transform problem:determine the transform,which maps(x,y)to a point on x-axis.3.3.2Extending the range of x coordinateTo use the algorithm for negative x,we must perform an initial rotation which gives x0≥0.One approach is just to consider the sign of ly,if y≥0and we rotate by−π/2,then x0=−y sin(−π/2)=y≥0.On the other hand,if y≤0and we rotate byπ/2,then x0=−y≥0.d init= −1if y>0+1otherwise.(12) and the initial values arex0=−d init·y y0=d init·x z0=−d init·π/2(13)With this initialization,the result z N will converge toαin the range[−π,π].113.3.3The algorithmTo summarize,the rotator transform defined in(1)can be solved with the following steps:ing(12)and(13),compute the initial values of x0=x0A0,y0=y0A0and z0.2.Iterate N times(i=0,...,N−1):(a)Determine the rotation direction d i using(11).(b)Compute x i+1A i+1and y i+1A i+1using shift-add arithmetic based on(6).(c)Update the sum of angles,z i+1,using(10).pensate for the gain A N in the result to obtain x N,which corresponds to the radius coordinate r.z N gives the anglecoordinateα.Example2.Let(x,y)=(3,4).As y>0,d init=−1.First iterations of the algorithm are shown in Fig.5.As A5=1.6457, x5after gives quite accurately the radius r=i y i A i d i[deg][deg]0−3.00+1+7.00+45.0026.572−2.50+1+8.13+57.537.134+0.39−1+8.23+53.98Figure5:CORDIC iterations for mapping(3,4)to polar coordinates.3.4Implementation aspectsAn important notice:in particular the inverse trigonometric function calculations using the simpliest CORDIC algorithms may in some cases suffer from numerical precision problems.Consult the literature for techniques that avoid the problems.They are only slightly more complicated.The benefits of CORDIC algorithms are usually best achived in hardware and SIMD implementations.A rule of thumb in scalar software implementations is that if a hardware multiplier is available,it should be used.Then the trigonometric functions can be conveniently and efficiently computed via series expansions.Notice,however,that in many cases the CORDIC algorithms may converge faster!Many practical CORDIC implementations are based on bit serial binary arithmetics,because bit parallel operations and iterative implementations require a versatile arithmetic shifter(barrel shifter).A pipelined multistage realization may then be an attractive alternative as such an approach also provides a higher throughput.There are several possible optimizations available with CORDIC implementations.For instance,the rotation angles may be13known beforehand.This is the case when rotators are parts in DCT transform computations.Then we dont need to accumulate the angles,and we only need to know the sequence of directions d i.Furthermore,if the sign of the direction may get values-1,0,1,the number of iterations can be reduced.Figure6:A sketch of CORDIC hardware in which the iteration loops have been rolled open.143.4.1Historical noteVolder wasnt thefirst one to invent the CORDIC algorithm.Henry Briggs(1561-1630)in his book Arithmetica Logaritmica in 1624(!),described similar methods to calculate tables of logarithms(btw,invented by Neper,1550-1617).In his start of studies in1977Olli spent a fortune on a programmable HP calculator,and he was astonished to read from the manual that the algorithm for computing the logarithms etc.was based on a method devised by Briggs more than350year earlier.If you are interested you canfind a partial English translation of Arithmetica Logaritmica at /his-tory/Miscellaneous/Briggs/index.html3.5CORDIC example in binary formIn the following we present the earlier example in a binary form progressing through the solution step by step.For the purpose of demonstration we will use s9.5fixed point number format recognizing that this selection may not yield the most precise results.However,this enables us to see some of the difficulties in maintaining the precision.3.5.1ScalingStarting from the easiest element,the scale factor to compensate for CORDIC algorithm gain when the number of iterations is infinite is approximately0.6073.As this scale factor may be needed to correct for thefinal results of CORDIC viax=0.6073·x iy=0.6073·y i15we notice that it would be convenient to be able to implement the multiplication with arithmetic shifts and adds.We immediately see that0.6073·x≈0.5·x+0.125·x−0.015625·x=0.6093·xHere the error due to scaling is approximately0.33%if the number of iterations is infinite.That can be implemented as the following combination of shifts and adds(ashr(x,n)is arithmetic shift right of x by n bits and, ashl(x,n)is arithmetic shift left of x by n bits):0.6073·x≈ashr(x,1)+ashr(x,3)−ashr(x,6)Now,if x=1that is expressed as0001.00000in binary s9.5format,we get0.6073·x≈0000.10000+0000.00100+0000.00000=0000.10100=0.625The error is2.9%,10times the one with our decimal experiment!Another alternative that results in a better precision with s9.5format is0.6073·x≈ashr[(ashl(x,2)+x−ashr(x,3)),3]=ashr[0100.00000+0001.00000+1111.11100,3]=ashr[0100.11100,3]=0000.10011=0.59375The error is2.2%is now smaller,but still a sizable one.In practical implementations we simply connect the signal lines in a manner that corresponds to each shift.3.5.2Using the CORDIC iterations for vector rotationOur task is to rotate an input vector by30degrees.So,first z0=30=0.523rad=0000.10001.What are the errors in this case?16i d i z i+1rad/s9.5rad/s9.50+10000.10001−0000.11001=0111.110000000.011110.500/0.10002+10000.001000.125/0.00104......=0.25=−14.33degrees32We may recall that in our decimal arithmetics solution the result for the angle in thefirst iteration was−15degrees.However, there is nothing to worry,the error is just a characteristic of binary arithmetics.When designing a CORDIC implementation we need to pay careful attention to the precision of the solution.In theory,each iteration gives one more bit of precision,but the tabulated atan(2−i)values set the limit for the number of iterations.When the number of iterations increases,the more precision is needed for the atan(2−i)to determine the direction of rotations. At this point it is also good to remember that the location of the decimal point is only an agreement.As a reminder of the reality,we do not mark it in the binary words in the formulas.17Now z1=111111000<0,so d1=−1,and the next iteration becomesx2=x1−d1·y1·2−1=000100000+ahsr(000100000,1)=1.5y2=y1+d1·x1·2−1=000100000+ahsr(000010000,1)=0.5z2=z1−d1·arctan(2−1)=000000111==7。

相关文档
最新文档