主要内容

cordiccexp

基于 CORDIC 的复指数逼近

说明

y = cordiccexp(theta) 使用 CORDIC 算法逼近计算 cos(theta) + j*sin(theta) 并在 y 中返回逼近的复数结果。

y = cordiccexp(theta,niters) 执行 niters 次算法迭代。

示例

示例

全部折叠

查看迭代次数对 cordiccexp 逼近结果的影响。

wl = 8;
theta = fi(pi/2,1,wl);

output_type = fi([], 1,wl,wl - 2);
results_array = zeros(wl - 1,1,'like',output_type)';

for niters = 1:(wl - 1)
  cis    = cordiccexp(theta,niters);
  fl     = cis.FractionLength;
  x      = real(cis);
  y      = imag(cis);

  x_dbl  = double(x);
  y_dbl  = double(y);

  x_err  = abs(x_dbl - cos(double(theta)));
  y_err  = abs(y_dbl - sin(double(theta)));

  result = [niters,y_dbl,y_err,(y_err*pow2(fl)),...
      x_dbl,x_err,(x_err*pow2(fl))];
  results_array = [results_array; result];
end

results_table = array2table(results_array,'VariableNames',{'NITERS',...
    'Y (SIN)','Y ERROR','Y LSBs','X (COS)','X ERROR','X LSBs'})
results_table=8×7 table
    NITERS    Y (SIN)    Y ERROR     Y LSBs    X (COS)     X ERROR     X LSBs 
    ______    _______    ________    ______    ________    ________    _______

         0          0           0         0           0           0          0
         1    0.70312     0.29688    1.9844    -0.70312     0.70312     1.9844
    1.9844     0.9375      0.0625    1.9844     -0.3125      0.3125     1.9844
    1.9844    0.96875     0.03125    1.9844     -0.0625      0.0625     1.9844
    1.9844    0.96875     0.03125    1.9844      0.0625      0.0625     1.9844
    1.9844    0.98438    0.015625         1           0           0    0.46875
    1.9844    0.98438    0.015625         1     0.03125     0.03125     1.9844
    1.9844          1           0         0    0.015625    0.015625     1.4688

输入参数

全部折叠

输入数组,指定为有符号或无符号的标量、向量、矩阵或多维数组。theta 的所有值必须为实数且在 [-2π 2π) 范围内。

如果输入是 fi 对象,它必须使用二进制小数点定标。

数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi

CORDIC 算法执行的迭代次数,指定为正标量整数。增加迭代次数可以得出更准确的结果,但会增加计算开销和延迟。

如果未指定 niters 或指定的值太大,算法将根据输入的数据类型使用最大值:

  • 定点输入 - 最大迭代次数为 theta 的字长减 1。

  • 浮点输入 - 最大值为 52(对于 double)或 23(对于 single)。

数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi

输出参量

全部折叠

逼近的复指数 e^(j*theta),以标量、向量、矩阵或多维数组形式返回。输出的数据类型取决于输入:

  • 当输入 theta 是浮点时,输出数据类型与输入类型相同。

  • 当输入 theta 为定点时,输出的字长与输入相同,小数长度等于字长减 2。

算法

全部折叠

参考

[1] Volder, Jack E. “The CORDIC Trigonometric Computing Technique.” IRE Transactions on Electronic Computers. EC-8, no. 3 (Sept. 1959): 330–334.

[2] Andraka, Ray. “A Survey of CORDIC Algorithm for FPGA Based Computers.” In Proceedings of the 1998 ACM/SIGDA Sixth International Symposium on Field Programmable Gate Arrays, 191–200. https://dl.acm.org/doi/10.1145/275107.275139.

[3] Walther, J.S. “A Unified Algorithm for Elementary Functions.” In Proceedings of the May 18-20, 1971 Spring Joint Computer Conference, 379–386. https://dl.acm.org/doi/10.1145/1478786.1478840.

[4] Schelin, Charles W. “Calculator Function Approximation.” The American Mathematical Monthly, no. 5 (May 1983): 317–325. https://doi.org/10.2307/2975781.

扩展功能

全部展开

版本历史记录

在 R2010a 中推出