⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fcontrol_word_r.m

📁 用于matlab仿真的
💻 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 + -