主要内容

cordictanh

基于 CORDIC 的双曲正切

说明

T = cordictanh(theta) 返回 theta 的双曲正切。

示例

T = cordictanh(theta, niters) 通过执行 niters 次 CORDIC 算法迭代返回 theta 的双曲正切。

示例

示例

全部折叠

使用具有默认迭代次数的 CORDIC 实现找到 fi 对象 theta 的双曲正切。

theta = fi(-2*pi:.1:2*pi-.1);
T_cordic = cordictanh(theta);

使用 tanh 函数及其 CORDIC 逼近绘制 theta 的双曲正切。

T = tanh(double(theta));
plot(theta, T_cordic);
hold on;
plot(theta, T);
legend('CORDIC approximation of tanh', 'tanh');
xlabel('theta');
ylabel('tanh(theta)');

Figure contains an axes object. The axes object with xlabel theta, ylabel tanh(theta) contains 2 objects of type line. These objects represent CORDIC approximation of tanh, tanh.

计算 cordictanh 函数结果与 tanh 函数结果之间的差。

figure;
err = abs(T - double(T_cordic));
plot(theta, err);
xlabel('theta');
ylabel('error');

Figure contains an axes object. The axes object with xlabel theta, ylabel error contains an object of type line.

通过使用 CORDIC 实现并指定 CORDIC 核应执行的迭代次数,找到 fi 对象 theta 的双曲正切。绘制具有不同迭代次数的 theta 的双曲正切的 CORDIC 逼近。

theta = fi(-2*pi:.1:2*pi-.1);
for niters = 5:10:25
T_cordic = cordictanh(theta,niters);
plot(theta,T_cordic);
hold on;
end
xlabel('theta');
ylabel('tanh(theta)');
legend('5 iterations','15 iterations',...
    '25 iterations','Location','southeast');

Figure contains an axes object. The axes object with xlabel theta, ylabel tanh(theta) contains 3 objects of type line. These objects represent 5 iterations, 15 iterations, 25 iterations.

输入参数

全部折叠

以弧度为单位的角度值,指定为标量、向量、矩阵或 N 维数组。

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

CORDIC 算法执行的迭代次数,指定为正整数值标量。如果您不指定 niters,算法将使用默认值。对于定点输入,niters 的默认值为输入数组 theta 的字长减一。对于双精度输入,niters 的默认值为 52。对于单精度输入,默认值为 23。

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

输出参量

全部折叠

Ttheta 的基于 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.

扩展功能

全部展开

版本历史记录

在 R2017b 中推出