Detailed CORDIC algorithm (a) - rotation mode (Rotation Mode) systems circumference of the CORDIC algorithm

Disclaimer: This article is a blogger original article, follow the CC 4.0 by-sa copyright agreement, reproduced, please attach the original source link and this statement.
This link: https: //blog.csdn.net/Pieces_thinking/article/details/83512820

   Detailed CORDIC algorithm (a) - rotation mode (Rotation Mode) systems circumference of the CORDIC algorithm

Online there are many similar reports, but this article will be introduced with examples, as far as possible in the most simple language parsing.

CORDIC (Coordinate Rotation Digital Computer) is referred to as the coordinate rotation digital computer algorithms,
• Vloder in 1959 by the United States in air navigation control system design process first proposed [1], mainly used to solve navigation systems trigonometric functions, inverse trigonometric Real-time calculation functions and square root operations. 1971, Walther will be circumference system, linear system to a unified system and hyperbolic CORDIC iterative equation in order to put forward a unified form CORDIC algorithm [2].
CORDIC algorithm is widely used, such as discrete Fourier transform, discrete cosine transform, discrete Hartley transform, Chirp-Z transformation, various filtering and singular value decomposition of the matrix can be applied CORDIC algorithm. Broadly speaking, CORDIC algorithm provides a method for approximating mathematical calculations. Since it eventually resolved into a series of subtraction and shift operation, it is suitable for hardware implementation. For example, a CORDIC algorithm in direct digital frequency synthesizer engineering. On the basis of this section describes three kinds of CORDIC rotation mode algorithms, we describe the theory calculated with the CORDIC-algorithm trigonometric functions, inverse trigonometric complex modulus and the like. On this basis, we describe the design and implementation of its engineering application FPGA-based CORDIC algorithm.

Circumference system and its mathematical application 1 CORDIC Algorithms

At a peripheral system, the CORDIC algorithm was computed trigonometric function, wherein the system is divided into a circumferential rotation mode and vector mode.

1.1 rotating circumferential modes of the system (Rotation Mode)

FIG. 3.69, on the unit circle, and the upside of the angle between the vector OP [alpha] X-axis, so the coordinates of the point P can be expressed as Formula (3.91):

  The angle [theta] vector OP is rotated counterclockwise to vector OQ, OQ case with positive X axis an angle of α + θ, so the coordinates of the point Q can be expressed as:


 It is defined herein as the target rotation angle θ. The trigonometric formula may be Formula (3.92) expands to:

Formula (3.91) into equation (3.93) can be obtained:

Extracting cosθ, of Formula (3.94) may be rewritten as:

From formula (3.95) As can be seen, cosθ target vector only changes the length of OQ mold. If you remove the cos [theta], as shown in FIG. 3.70, this time from OR OP after the rotation angle θ, this rotation is called pseudo-rotation (Pseudo Rotation). It is easy to see the difference in amplitude OQ and OR, and may prove vectors OP and the PR are orthogonal. At this time, the coordinates of point R may be expressed as:

This can be compensated by the output of pseudo-rotation results to obtain the real rotation.
PS: Comparative known per rotation angle is correct, but the modulus increased 1 / cosθ
Note: not mathematically removing cos [theta], cos [theta] is removed but can simplify the calculation of the rotation operation of the coordinate plane.

  For pseudo-rotation, [theta] can be decomposed into a series of slight angle and, namely:

In this way, the first rotation broken down into a series of micro-rotation. By the formula (3.96) can be seen, the results of the i + 1 after rotation is:

The next step is critical, it makes it very easy hardware implementation of the algorithm, and even if:

Here di∈ {-1,1}, of Formula (3.99) and (3.98) can be rewritten as:

By the formula (3.100), easy to see, each micro rotation only addition, subtraction and shift operations can be completed. To determine the value of di, the introduction of a new variable Z, is defined as:

z 初 始 化 为θ,即z0=θ,根据条件,对zi执行加或者减tan-12-i操作,使得z的最终值为0 ,该条件由di决定,即:

di为+1时表示逆时针旋转,为-1时表示顺时针旋转 。z的迭代过程是将z收敛于零的过程,也正是将θ分解为一系列θi的过程, 故zi可认为是第i次旋转剩余的角度。至此 ,CORDIC 算法之圆周系统的旋转模式迭代过程可表示为:

1.2 思考

  • (1 ) 由式 (3.99) 所确定的目标旋转角度的范围;

  (2)如何确定伪旋转到真实旋转的模长补偿因子。

(1)根据式 (3.99 ) 可确定一系列θi的值, 如表 3.17 所示, 还可确定目标旋转角度θ的最大值 θmax 和 最 小 值 θmin , 如式( 3.104 ) 所示。

以目标旋转角度 55° 为例, 它可分解为
55° = 45.0° + 26.6° -14.0°- 7.1° + 3.6° + 1.8° - 0.9°
其迭代过程中角度的变化状况如表 3.18 所示。 假设初始向量位于X轴 正 半 轴, 前 3 次 的 微旋转如图 3.71 所示。

(2)在很多场合中需要目标旋转角度可以覆盖[-180°,180°], 这就需要预处理。 预处理的机制如表 3.19 所示, 不难看出, 只有当目标旋转角度|θ|>π/2 时需要预旋转 π/2 , 用公式表示如式 (3.105) 所示。

据此, 旋转过程可如图 3.72 所示。

由图 3.71 可以看出, 每次微旋转都导致向量模长发生了变化。以Ki表示第 i次微旋转模长补偿因子, 故第 i次微旋转真实旋转的结果应为:

其中,由于在伪旋转中,去掉了cosθi,所以Ki=cosθi 由式 (3.99) 可知:

若总的旋转次数为n, 则总的模长补偿因子K可表示为:

当n趋于无穷大时,K 逼近 0.607252935。
这部分计算,可以由matlab进行迭代计算:
具体如下:

close all;
clear;
clc;
% 初始化
die = 16;%迭代次数
jiao = zeros(die,1);%每次旋转的角度
cos_value = zeros(die,1);%每次旋转的角度的余弦值
K = zeros(die,1);%余弦值的N元乘积
K_1 = zeros(die,1);%余弦值的N元乘积的倒数
for i = 1 : die
    a = 2^(-(i-1));
    jiao(i) = atan(a);
    cos_value(i) = cos(jiao(i));
    if( i == 1)
        K(i) = cos_value(i);
        K_1(i) = 1/K(i);
    else
        K(i) = K(i-1)*cos_value(i);
        K_1(i) = 1/K(i);
    end
end
jiao = vpa(rad2deg(jiao)*256,10) 
cos_value = vpa(cos_value,10)
K = vpa(K,10)
K_1 = vpa(K_1,10)

 从上表也可以看出,当迭代次数为16,i=15时,cosθi的值已经非常趋近于1了,∏cosθi的值则约等于0.607253,1/∏cosθi为1.64676。所以当迭代次数等于16时,通过迭代得到的点坐标已经非常接近之前假设中的点坐标。

1.3 CORDIC算法应用

1.3.1 目标旋转角度的正、 余弦函数值

经过 n(n–>∞)次微旋转, 得到的最终结果可表示为:

式中, 当 n 趋于无穷大时, An逼近 1.646760258。 根据式 (3.109 ) 可知, 令 x0=1/An且y0 = 0 可得目标旋转角度的正、 余弦函数值, 如图 3.73 所示。 此时, 初始化 z0 即为目标旋转角度 。 需要注意的是当目标旋转角度|θ|>π/2 时应先预处理
 

1.3.1 极坐标系向直角坐标系的转换

  同样地, 由式 ( 3.109 ) 出发, 令 x0=r且y0 = 0,z0 =θ,则可以实现极坐标系向直角坐标系的转换, 如图 3.75 所示。 显然, 这里x0代表了极径, z0 代表了极角。

1.4 举例

  利用CORDIC算法,计算cosθ和sinθ,其中θ=π/4(迭代次数16)

  解析:

关参数转换如下:

  • x0=1/An=1/1.646760258=0.607253;
  • y0 = 0;
  • z0=π/4(由于|θ|<π/2,所以不需要进行预处理);
  • 经过16次迭代计算后,得到的x16 和y16分别为cosθ和sinθ。
    相关程序如下:
  • close all;
    clear;
    clc;
    % 初始化
    die = 16;%迭代次数
    x = zeros(die+1,1);
    y = zeros(die+1,1);
    z = zeros(die+1,1);
    x(1) = 0.607253;%初始设置
    z(1) = pi/4;%待求角度θ
    %迭代操作
    for i = 1:die
        if z(i) >= 0
            d = 1;
        else
            d = -1;
        end
        x(i+1) = x(i) - d*y(i)*(2^(-(i-1)));
        y(i+1) = y(i) + d*x(i)*(2^(-(i-1)));
        z(i+1) = z(i) - d*atan(2^(-(i-1)));
    end
    cosa = vpa(x(17),10)
    sina = vpa(y(17),10)
    c = vpa(z(17),10)
    

    最后得到的结果:

  • x16=0.707095876358217
  • y16=0.707117836980767
  •   证明算法思路正确。

发布了49 篇原创文章 · 获赞 138 · 访问量 30万+

Guess you like

Origin blog.csdn.net/lz0499/article/details/100002361