📄 testsinecosine.m
字号:
%% Test sine/cosine
% 0<z0<pi/2
% test cordic
clc,clear all
theta=linspace(0,pi/2,100)';
% function [xn,gain,Fs,Ds,yn,zn]=cordic(x0,y0,z0,mode,...
% dv_n,ROM,wordwidth)
wordwidth=64;
Fs=-ones(wordwidth,length(theta));
Ds=zeros(size(Fs));
n=-(0:64)';ROM=[-n,atan(2.^n)];
for i=1:length(theta)
[xn(i),An(i),F,D,zn(i),yn(i)]...
=cordic(1,0,theta(i),1,'z',ROM);
Fs(1:length(F),i)=F;
Ds(1:length(D),i)=D;
%sprintf('theta=%f',theta(i))
end
cosine=xn./An;
sine=yn./An;
true_cosine=cos(theta);% true values
true_sine=sin(theta);
%theta=theta/pi*180;
figure(1),hold on
plot(theta,cosine,'LineWidth',1.5)
plot(theta,sine,'LineWidth',1.5)
plot(theta,true_cosine,'g')
plot(theta,true_sine,'g')
plot(theta,true_cosine-cosine','r')
plot(theta,true_sine-sine','m')
plot(theta,zn,'y')
legend('Cordic cosine','Cordic sine',...
'true cosine','true sine',...
'error cosine','error sine','zn')
xlabel('\theta'),ylabel('value')
hold off
% some statistics
save F1.dat Fs -ascii
save D1.dat Ds -ascii
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -