📄 testcordic.html
字号:
if(dv_n=='x')dv=xi;elseif(dv_n=='y')dv=yi;
else dv=zi;% default decision variable
end
% termination testREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH-
disable=terminator(dv,acc);
if(disable)break;
end%if
% iteration beginsREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH-
% REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHdiREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH-
di=direction(dv,dv_n);
D(iteration+1)=di;
% REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH-Fi/eREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH
if(ROM=='d')
NumOfData=wordwidth+1;
[Fi ei]=Angle2rotate(dv,m,di,NumOfData,wordwidth);
else
[Fi ei]=Angle2rotate(dv,m,di,length(ROM),...
wordwidth,ROM);
end
F(iteration+1)=Fi;% record Fi
% REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHAnREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH-
An=An*gainKi(Fi,m);% calculate An
% REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHxi/yi/ziREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH-
xi=xi-m*yi*di*2^(-Fi);
yi=yi+xi*di*2^(-Fi);
zi=zi-di*ei;
end% iteration
% postprocess================================================
%check outputs===============================================
if(nargout<0 || nargout>6)
xn=0;yn=0;
disp('too few or too many outputs.\n')
end
if(nargout>0)
xn=xi;end
if(nargout>1)
gain=An;end
if(nargout>2)
[row,column]=size(F);
if(row<column)Fs=reshape(F,column,row);
else Fs=F;end
end
if(nargout>3)
Ds=D';
end
if(nargout>4)
zn=zi;end
if(nargout>5)
yn=yi;end
%ends function
end
%% subfunction1-direction
% In order to find the right direction to rotate, this
% program was provided.According to the algorithm, it's
% much too easy to choose di. However, this file was
% provided separately to make the structure of the
% program clear.
% inputs/outputs refer to cordic.m,while dv_name denotes
% the name of the decision variable
%% code
function di=direction(dv,dv_name)
% check the No. of inputs
if(nargin<2)
dv_name='z'; % default decision variable:z
end
% main code section
di=1;
if(dv_name=='x' || dv_name=='y' || dv_name=='z')
% main code section
if(dv_name=='z') % z is decision variable
if(dv<0) di=-1; end
else % x/y is decision variable
if(dv>=0) di=-1; end
end
else printf('Wrong decision name!\n');
end
%end of function
end
%% subfunction2-Angle2rotate
% this file is very important for at least two reasons.
% the one is DATAs, which is suppose to be stored in ROM,
% will be provided in the first part of the routine. The
% other is, in fact, it has great effect on the steps of
% iteration.Of course, the angle to rotate at each step
% is based on the stored DATAs. And angles will be chosen
% to get the result as quickly as possible accordingly.
% How many DATAs are required to obtain the acceptable
% results,further study is badly needed.
% inputs
% y or z can be both chosen to decrease.HOWEVER,
% the same algorithm was employed.
% NumofData and wordwidth offer the parameters to
% generate those DATAs. The method is discussed
% below.
% Since wordwidth limits range of the datas,
% and the smallest angle to rotate is
% arctan(2^(-wordwidth)),the second smallest
% one is arctan(2^(-wordwidth+1)), and so on.
% There will be NumOfData of those smallest
% datas generated and stored unless the last
% parameter is provided.Or those angles are
% defined in ROM.
% outputs
% out, the best choice for the places to shift
% and the current angle to rotate
% format Fi arctan(2^(-Fi))
% data format in ROM
% F0 arctanh(2^-(F0))
% F1 arctanh(2^-(F1))
% ...
% and so on
%% code
function [Fi ei]=Angle2rotate(z,m,di,NumOfData,wordwidth,ROM)
% DATAs generator
if(nargin<6)
% F is in an increasing order
F=wordwidth-(NumOfData-1:-1:0)';
theta=2.^(-F);
if(m~=-1)
ROM=[F atan(theta)];
else% m=-1
ROM=[F atanh(theta)];
if(~F(1))% F0=0 must be removed
ROM=[F(2:end),atanh(theta(2:end))];
end
end
save ROM.dat ROM -ascii
end
% FIND THE BEST CHOICE FOR ANGLE TO ROTATE
% there's only one angle stored
if(NumOfData==1 || length(ROM)==1)
Fi=ROM(1);ei=ROM(2);
% there's more than one choice
else% find the minumal difference
for i=1:length(z)
[v,index]=min(abs(z(i,1).*ones(size(ROM,1),1)...
-di*ROM(:,2)));
% v is useless
Fi(i)=ROM(index(1),1);
ei(i)=ROM(index(1),2);
end
Fi=Fi';ei=ei';
end
% ends function
end
%% subfunction3-terminator
% Terminator play an important role in iterative
% algorithms.In this project, there are mainly two
% conditions which terminate the process,zi=0 or
% yi=0.However, the word width for every digital
% system is finite, which relaxes the conditions.
% Therefore, we get
% zi < 2^(-wordwidth)
% or yi < 2^(-wordwidth)
% input
% z or y can play such a role
% wordwidth is a system parameter
% output
% signals the end of the process
%% code
function disable=terminator(z,wordwidth)
if(nargin<2)
wordwidth=64;
end
if(abs(z)<2^(-wordwidth+1))
disable=1;
else disable=0;
end
end
%% subfunction4-gainAn
% this routine is written to analysis the relationship
% between n and An. Theoretically, as n approach infinite,
% An will be a constant. What's more important, we will
% study on the difference between the constant and An to
% look into how many steps the algorithm takes to make
% the precision of the results up to our expectation.
% Input
% F, shifting sequences in the form of comun vector(s)
% m, mode
% Output
% An, gain of the algorithm
%% code
function An=gainAn(F,m)
[row,column]=size(F);
An=ones(column);% initialize An
if(m)% m!=0 No linear mode
for j=1:column
Ki=gainKi(F(:,j),m);% select Fi=i, mode
%compute An for j-th column
for i=1:row
An(j)=An(j)*Ki(i);
end
end
end
% %plot
% plot(n,An,'ro'),hold on
% plot(n,An,'g'),hold off
% ends function
end
%% subfunction5-gainKi
% this program can be used to compute the gain of CORDIC
% processing systems at each iterative step
% Inputs:
% m, represents the mode of the computing system
% Fi, elementary shifts for the i-th iteration
% CAUTION: m and Fi can be both vectors
% Outputs:
% Ki, i-th processing gain
%% code
function Ki=gainKi(Fi,m)
Ki=sqrt(1+m.*2.^(-2*Fi));
if(m==-1 && Fi(1)==0)% when m=-1, Fi can't be 0
Ki(1)=1;
end
end##### SOURCE END #####--> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -