主要内容

cordicsincos

基于 CORDIC 的正弦和余弦逼近

说明

[y,x] = cordicsincos(theta) 使用 CORDIC 算法逼近计算 theta 的正弦和余弦。y 包含逼近的正弦结果,x 包含逼近的余弦结果。

[y,x] = cordicsincos(theta,niters) 执行 niters 指定的 CORDIC 算法迭代次数。

示例

示例

全部折叠

查看迭代次数对正弦和余弦的 CORDIC 逼近结果的影响。

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

fprintf('\n\nNITERS\t\tY (SIN)\t ERROR\t LSBs\t\tX (COS)\t ERROR\t LSBs\n');
fprintf('------\t\t-------\t ------\t ----\t\t-------\t ------\t ----\n');

for niters = 1:(wordlength - 1)
  [y,x] = cordicsincos(theta,niters);
  y_FL   = y.FractionLength;
  y_dbl  = double(y);
  x_dbl  = double(x);
  y_err  = abs(y_dbl - sin(double(theta)));
  x_err  = abs(x_dbl - cos(double(theta)));
  fprintf(' %d\t\t%1.4f\t %1.4f\t %1.1f\t\t%1.4f\t %1.4f\t %1.1f\n', ...
      niters,y_dbl,y_err,(y_err*pow2(y_FL)),x_dbl,x_err, ...
      (x_err*pow2(y_FL)));
end

fprintf('\n');

NITERS		Y (SIN)	 ERROR	 LSBs		X (COS)	 ERROR	 LSBs
------		-------	 ------	 ----		-------	 ------	 ----
 1		0.7031	 0.2968	 19.0		-0.7031	 0.6958	 44.5
 2		0.9375	 0.0625	 4.0		-0.3125	 0.3052	 19.5
 3		0.9688	 0.0312	 2.0		-0.0625	 0.0552	 3.5
 4		0.9688	 0.0312	 2.0		0.0625	 0.0698	 4.5
 5		0.9844	 0.0156	 1.0		0.0000	 0.0073	 0.5
 6		0.9844	 0.0156	 1.0		0.0312	 0.0386	 2.5
 7		1.0000	 0.0000	 0.0		0.0156	 0.0230	 1.5

输入参数

全部折叠

以弧度为单位的输入角度,指定为标量、向量、矩阵或多维数组。所有 theta 值必须在范围 [-2*pi,2*pi) 内。当 theta 具有定点数据类型时,它必须为有符号数。

CORDIC 算法执行的迭代次数,指定为正整数值标量。

如果未指定 niters 或指定的值太大,算法将使用最大值。对于定点运算,最大迭代次数为 theta 的字长减 1。对于浮点运算,最大值为 52(双精度)或 23(单精度)。

增加迭代次数可以得出更准确的结果,但会增加计算开销和延迟。

输出参量

全部折叠

theta 的基于 CORDIC 的正弦逼近,以标量、向量、矩阵或多维数组形式返回。当函数的输入是浮点数时,输出数据类型与输入数据类型相同。当输入为定点时,输出的字长与输入相同,小数长度等于 Wordlength - 2

基于 CORDIC 的 theta 的逼近余弦,以标量、向量、矩阵或多维数组形式返回。当函数的输入是浮点数时,输出数据类型与输入数据类型相同。当输入为定点时,输出的字长与输入相同,小数长度等于 Wordlength - 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 中推出