做字体网站,用wordpress设计html,wordpress主题报错,手机回收站一、前言
单片机或者FPGA等计算能力弱的嵌入式设备进行加减运算还是容易实现#xff0c;但是想要计算三角函数#xff08;sin、cos、tan#xff09;#xff0c;甚至双曲线、指数、对数这样复杂的函数#xff0c;那就需要费些力了。通常这些函数的计算需要通者查找表或近似…一、前言
单片机或者FPGA等计算能力弱的嵌入式设备进行加减运算还是容易实现但是想要计算三角函数sin、cos、tan甚至双曲线、指数、对数这样复杂的函数那就需要费些力了。通常这些函数的计算需要通者查找表或近似计算如泰勒级数逼近等技术来转换为硬件易于实现的方式。
CORDIC(Coordinate Rotation Digital Computer, 坐标旋转数字计算方法)算法就是一种化繁为简的算法通过基本的加减和移位运算代替乘法运算逐渐逼近目标值得出函数的数值解。
二、Cordic算法理论推导
理论推导参考CORDIC算法理论详解_cordic算法详解-CSDN博客这篇博客的推导仔细而全面。
Cordic算法的基石在于一个规律从tan45°开始角度每减半tan值也接近减半。这一规律直接将三角函数运算变成2的幂运算而这在数字电路中可直接用移位运算来实现。
三、Cordic算法 matlab实现
3.1 已知相位角度求坐标正弦余弦
function [sin_theta,cos_theta] cordic_sincos(theta,n)
% n:iterations
% theta: -180~180
tan_table 2.^-(0 : n-1);
angle_rad_lut atan(tan_table);
%angle_deg_lut rad2deg( atan(tan_table) );k 1;
for i 0 : n-1k k*(1/sqrt(1 2^(-2*i)));
endx k;
y 0;
theta_tar theta*pi/180; % to be rad
ztheta_tar;% preprocess
if (theta_tar pi/2) theta_tar theta_tar - pi/2;
elseif (theta_tar -pi/2)theta_tar theta_tar pi/2;
endfor i 0 : n-1 if (z 0) d 1;elsed-1;endx_temp x;y_temp y;z_temp z;x x_temp - d*y_temp*2^(-i);y y_temp d*x_temp*2^(-i);z z_temp - d*angle_rad_lut(i1);endif (theta_tar pi/2) sin_theta -x;cos_theta y;
elseif (theta_tar -pi/2)sin_theta x;cos_theta -y;
elsesin_theta y;cos_theta x;
end
end
3.2 已知坐标求相位
待实现
四、cordic算法的verilog实现
待实现