CORDIC--HLS实现

1. 背景

CORDIC(Coordinate Rotation Digital Computer)坐标旋转数字计算机是一种计算三角函数,双曲函数和其他数学函数的有效技术。CORDIC仅使用加法,减法,位移和表查找来执行简单计算,这些计算在FPGA中以及更一般地在硬件中实现是有效的。设计人员必须在结果的准确性,性能和设计的资源利用率之间进行仔细权衡。
CORDIC背后的核心思想是在二维平面中有效地执行一组矢量旋转。 通过用一些简单的控制决策使用这些旋转,我们可以执行各种基本操作,例如三角函数,双曲线函数和对数函数,实数和复数乘法,以及矩阵分解和分解。 CORDIC已广泛应用于各种应用,包括信号处理,机器人,通信和许多科学计算。 CORDIC通常用于FPGA设计,因为它的资源使用量很小。
CORDIC算法的基本目标是以有效的方式执行一系列旋转。 让我们首先考虑如何进行轮换。 在二维中,旋转矩阵是

R(θ)=[cosθsinθsinθcosθ] R ( θ ) = [ cos ⁡ θ − sin ⁡ θ sin ⁡ θ cos ⁡ θ ]

CORDIC使用迭代算法将矢量v旋转到某个角度目标,这取决于CORDIC正在执行的功能。 一次旋转是 vi=Rivi1 v i = R i ⋅ v i − 1 形式的矩阵向量乘法。 因此,在CORDIC的每次迭代中,我们执行以下操作来执行一次旋转,即矩阵向量乘法:

[cosθsinθsinθcosθ][xi1yi1]=[xiyi] [ cos ⁡ θ − sin ⁡ θ sin ⁡ θ cos ⁡ θ ] [ x i − 1 y i − 1 ] = [ x i y i ]

写出线性方程,新旋转矢量的坐标是:

xi=xi1cosθyi1sinθ  x i = x i − 1 cos ⁡ θ − y i − 1 sin ⁡ θ  

yi=xi1sinθ+yi1cosθ  y i = x i − 1 sin ⁡ θ + y i − 1 cos ⁡ θ  

再次考虑旋转矩阵

Ri(θ)=[cos(θi)sin(θi)sin(θi)cos(θi)] R i ( θ ) = [ cos ⁡ ( θ i ) − sin ⁡ ( θ i ) sin ⁡ ( θ i ) cos ⁡ ( θ i ) ]

cos(θi)=11+tan2(θi) cos ⁡ ( θ i ) = 1 1 + tan 2 ⁡ ( θ i )

sin(θi)=tan(θi)1+tan2(θi) sin ⁡ ( θ i ) = tan ⁡ ( θ i ) 1 + tan 2 ⁡ ( θ i )

我们可以得到:
Ri=11+tan2(θi)[1tan(θi)tan(θi)1] R i = 1 1 + tan 2 ⁡ ( θ i ) [ 1 − tan ⁡ ( θ i ) tan ⁡ ( θ i ) 1 ]

如果 tan(θi)=2i tan ⁡ ( θ i ) = 2 − i ,则
vi=Ki[12i2i1][xi1yi1] v i = K i [ 1 − 2 − i 2 − i 1 ] [ x i − 1 y i − 1 ]

Ki=11+22i K i = 1 1 + 2 − 2 i

使用 σi σ i 来表示旋转的方向,则
vi=Ki[1σi2iσi2i1][xi1yi1] v i = K i [ 1 − σ i 2 − i σ i 2 − i 1 ] [ x i − 1 y i − 1 ]

累积比例因子是:
K(n)=i=0n1Ki=i=0n111+22i K ( n ) = ∏ i = 0 n − 1 K i = ∏ i = 0 n − 1 1 1 + 2 − 2 i

K=limnK(n)0.6072529350088812561694 K = lim n → ∞ K ( n ) ≈ 0.6072529350088812561694

处理增益(processing gain):
A=1K=limni=0n11+22i1.64676025812107 A = 1 K = lim n → ∞ ∏ i = 0 n − 1 1 + 2 − 2 i ≈ 1.64676025812107

i 2i 2 − i Rotating AngleScaling FactorCORDIC Gain
01.0 45.000 45.000 ∘ 1.414211.41421
10.5 26.565 26.565 ∘ 1.118031.58114
20.25 14.036 14.036 ∘ 1.030781.62980
30.125 7.125 7.125 ∘ 1.007781.64248
40.0625 3.576 3.576 ∘ 1.001951.64569
50.03125 1.790 1.790 ∘ 1.000491.64649
60.015625 0.895 0.895 ∘ 1.000121.64669
3. 计算正余弦
#include "ap_int.h"
#include "ap_fixed.h"

#define NUM_ITERATIONS 7

typedef ap_fixed<8, 2, AP_RND, AP_SAT> COS_SIN_TYPE;
typedef ap_fixed<8, 2, AP_RND, AP_SAT> THETA_TYPE;
// The file cordic.h holds definitions for the data types and constant values
#include "cordic.h"

// The cordic_phase array holds the angle for the current rotation
THETA_TYPE cordic_phase[NUM_ITERATIONS] = {45, 26.565, 14.036, 7.125,
                                           3.576, 1.790, 0.895};

void cordic(THETA_TYPE theta, COS_SIN_TYPE &s, COS_SIN_TYPE &c)
{
  // Set the initial vector that we will rotate
  // current_cos = I; current_sin = Q
  COS_SIN_TYPE current_cos = 0.60735;
  COS_SIN_TYPE current_sin = 0.0;

  // Factor is the 2^(-L) value
  COS_SIN_TYPE factor = 1.0;

  // This loop iteratively rotates the initial vector to find the
  // sine and cosine values corresponding to the input theta angle
  for (int j = 0; j < NUM_ITERATIONS; j++) {
    // Determine if we are rotating by a positive or negative angle
    int sigma = (theta < 0) ? -1 : 1;

    // Save the current_cos, so that it can be used in the sine calculation
    COS_SIN_TYPE temp_cos = current_cos;

    // Perform the rotation
    current_cos = current_cos - current_sin * sigma * factor;
    current_sin = temp_cos * sigma * factor + current_sin;

    // Determine the new theta
    theta = theta - sigma * cordic_phase[j];

    // Calculate next 2^(-L) value
    factor = factor >> 1;
  }

  // Set the final sine and cosine values
  s = current_sin;  c = current_cos;
}

这里写图片描述

此代码接近“软件”版本。它可以通过多种方式进行优化,以提高性能,减少面积。

位宽的改变

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值