?? fcontrol_word_r.m
字號:
function [sys,x0,str,ts] = fcontrol_word_r(t,x,u,flag,rfwnSample,rfwout,rDT,fre_mod,Tcapture,num)
format long e;
warning off all
switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
[sys,x0,str,ts]=mdlInitializeSizes(rfwnSample,rfwout,rDT,fre_mod,Tcapture,num);
%%%%%%%%%%%%%%%
% Derivatives %
%%%%%%%%%%%%%%%
% case 1,
% sys=mdlDerivatives(t,x,u);
%%%%%%%%%%
% Update %
%%%%%%%%%%
case 2,
sys=mdlUpdate(t,x,u,rfwnSample,rfwout,rDT,fre_mod,Tcapture,num);
%%%%%%%%%%%
% Outputs %
%%%%%%%%%%%
case 3,
sys=mdlOutputs(t,x,u);
%%%%%%%%%%%%%%%%%%%%%%%
% GetTimeOfNextVarHit %
%%%%%%%%%%%%%%%%%%%%%%%
% case 4,
% sys=mdlGetTimeOfNextVarHit(t,x,u);
%%%%%%%%%%%%%
% Terminate %
%%%%%%%%%%%%%
% case 9,
% sys=mdlTerminate(t,x,u);
case {1,4,9}
sys=[];
%%%%%%%%%%%%%%%%%%%%
% Unexpected flags %
%%%%%%%%%%%%%%%%%%%%
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
% end sfuntmpl
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts]=mdlInitializeSizes(rfwnSample,rfwout,rDT,fre_mod,Tcapture,num)
%
% call simsizes for a sizes structure, fill it in and convert it to a
% sizes array.
%
% Note that in this example, the values are hard coded. This is not a
% recommended practice as the characteristics of the block are typically
% defined by the S-function parameters.
%
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 6;
sizes.NumOutputs = 3;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
%
% initialize the initial conditions
%
x0 = [1,0,0,0,0,0];
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts = [1/(1000), 0];
% end mdlInitializeSizes
%
%=============================================================================
% mdlDerivatives
% Return the derivatives for the continuous states.
%=============================================================================
%
% function sys=mdlDerivatives(t,x,u)
%
% sys = [];
% end mdlDerivatives
%
%=============================================================================
% mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%=============================================================================
%
function sys=mdlUpdate(t,x,u,rfwnSample,rfwout,rDT,fre_mod,Tcapture,num)%%%接收端進行跳頻的同步
rfwreg=x;
rfwnSample=rfwreg(1)+1;
rfwh = zeros(1,20);
for i=1:20
rfwh(i)= 1342177280+(i-1)*22369621;
end;
rtodh=fix(80000/120000);
if u(1)<1
if rfwreg(1)<=120000
rj=ceil((rfwreg(1))/7);
if (rj<=6)|(rj>54)
rfwout = rfwh(mod((rj+rtodh),20));
else
rfwout = rfwh(mod((mod(rj,6)+rtodh),20));
end;
else
rk=ceil(rfwreg(1)/120000);
if ((rfwreg(1)-rk*120000)<6)|((rfwreg(1)-rk*120000)>54)
rfwout = rfwh(mod((rfwreg(1)-rk*120000+rtodh+rk),20));
else
rfwout = rfwh(mod((mod(rfwreg(1)-rk*120000,6)+rtodh+rk),20));
end;
end;%%%若沒捕獲相關峰,則1000/7跳/秒 進行掃描
else
if rfwreg(3)<1
rwalsh=ceil((rfwreg(1)-1)/7);
if mod(rfwreg(1),6)==0
fre_mod=rwalsh-2;
else
fre_mod=rwalsh-(mod(rfwreg(1)-2,6));
end;%%%%進行todh的校正(在捕獲第一個相關峰時,延遲了一跳)
rDT=1;
Tcapture=rfwnSample;
num=1;
else
fre_mod=rfwreg(4);
Tcapture=rfwreg(5);
if rfwreg(1)<rfwreg(5)+5
num=rfwreg(6)+1;
rDT=rfwreg(3);
elseif rfwreg(1)==rfwreg(5)+5
if rfwreg(6)<3
rDT=0;
else
rDT=rfwreg(3);
end;
num=rfwreg(6);
else
num=rfwreg(6);
rDT=rfwreg(3);
end;
end;
if rfwreg(1)<=120000
if (rfwreg(1)<=6)
rfwout = rfwh(mod((rfwreg(1)+fre_mod),20)+rtodh);
elseif (rfwreg(1)>6)&(rfwreg(1)<=54)
if mod(rfwreg(1),6)==0
rfwout=rfwh(6+rtodh+fre_mod);
else
rfwout = rfwh(mod((mod(rfwreg(1),6)+rtodh),20)+fre_mod);
end;
else
if (mod((rfwreg(1)),20)+rtodh+fre_mod==0)|(mod((rfwreg(1)),20)+rtodh+fre_mod==20)
rfwout = rfwh(20);
else
rfwout = rfwh(mod(mod(rfwreg(1),20)+rtodh+fre_mod,20));
end;
end;
else
rk=fix(rfwreg(1)/120000);
if ((rfwreg(1)-rk*120000)<=6)|((rfwreg(1)-rk*120000)>54)
rfwout = rfwh(mod((rfwreg(1)-rk*120000+rtodh+rk),20));
else
rfwout = rfwh(mod((mod(rfwreg(1)-rk*120000,6)+rtodh+rk),20));
end;
end;%%%捕獲到相關峰之后,則1000跳/秒 跟跳
end;
rfwreg=[rfwnSample,rfwout,rDT,fre_mod,Tcapture,num];
sys = rfwreg;
% end mdlUpdate
%
%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,x,u,rfwnSample,rfwout,rDT,fre_mod,Tcapture,num)
sys = [x(1),x(2),x(3)];%%%給出4個頻率,按照順序依次輸出
% end mdlOutputs
%
%=============================================================================
% mdlGetTimeOfNextVarHit
% Return the time of the next hit for this block. Note that the result is
% absolute time. Note that this function is only used when you specify a
% variable discrete-time sample time [-2 0] in the sample time array in
% mdlInitializeSizes.
%=============================================================================
%
% function sys=mdlGetTimeOfNextVarHit(t,x,u)
%
% sampleTime = 1; % Example, set the next hit to be one second later.
% sys = t + sampleTime;
% end mdlGetTimeOfNextVarHit
%
%=============================================================================
% mdlTerminate
% Perform any end of simulation tasks.
%=============================================================================
%
% function sys=mdlTerminate(t,x,u)
%
% sys = [];
% end mdlTerminate
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -