主要内容

cordicsin

基于 CORDIC 的正弦逼近

说明

y = cordicsin(theta) 使用 CORDIC 算法逼近计算 theta 的正弦值。

y = cordicsin(theta,niters) 使用具有指定迭代次数 niters 的 CORDIC 算法逼近计算 theta 的正弦值。

示例

示例

全部折叠

此示例将 cordicsin 算法产生的结果与双精度 sin 函数的结果进行比较。

创建 [0, 2*pi) 之间的 1024 个点。

stepSize = pi/512;
thRadDbl = 0:stepSize:(2*pi - stepSize);
thRadFxp = sfi(thRadDbl,12);		% signed, 12-bit fixed point
sinThRef = sin(double(thRadFxp));	% reference results

将迭代次数设置为 10。

niters = 10;
cdcSinTh  = cordicsin(thRadFxp,niters);
errCdcRef = sinThRef - double(cdcSinTh);

将定点 cordicsin 函数的结果与双精度 sin 函数的结果进行比较。

figure
hold on
axis([0 2*pi -1.25 1.25])
plot(thRadFxp,sinThRef,'b');
plot(thRadFxp,cdcSinTh,'g');
plot(thRadFxp,errCdcRef,'r');
ylabel('sin(\Theta)');
gca.XTick = 0:pi/2:2*pi;
gca.XTickLabel = {'0','pi/2','pi','3*pi/2','2*pi'};
gca.YTick = -1:0.5:1;
gca.YTickLabel = {'-1.0','-0.5','0','0.5','1.0'};
ref_str = 'Reference: sin(double(\Theta))';
cdc_str = sprintf('12-bit CORDIC sine; N = %d',niters);
err_str = sprintf('Error (max = %f)', max(abs(errCdcRef)));
legend(ref_str,cdc_str,err_str);

Figure contains an axes object. The axes object with ylabel sin( Theta ) contains 3 objects of type line. These objects represent Reference: sin(double(\Theta)), 12-bit CORDIC sine; N = 10, Error (max = 0.005278).

经过 10 次迭代后,CORDIC 算法已将 theta 的正弦逼近到与双精度正弦结果相差 0.005492 内。

输入参数

全部折叠

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

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

如果未指定 niters 或指定的值太大,算法将使用最大值。对于定点运算,最大迭代次数为 theta 的字长减 1。对于浮点运算,最大值是 52(双精度)或 23(单精度)。增加迭代次数可以得出更准确的结果,但也会增加计算开销和延迟。

输出参量

全部折叠

theta 的基于 CORDIC 的正弦逼近,以标量、向量、矩阵或多维数组形式返回。

当函数的输入是浮点数时,输出数据类型与输入数据类型相同。当输入为定点时,输出的字长与输入相同,小数长度等于 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 中推出