📄 ms_sfun_interleaver.m
字号:
function [sys,x0,str,ts] = ms_sfun_interleaver(t,x,u,flag,interleaver_size)
switch flag
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
[sys,x0,str,ts]=mdlInitializeSizes(interleaver_size);
%%%%%%%%%%
% Update %
%%%%%%%%%%
case 2,
sys=mdlUpdate(t,x,u,interleaver_size);
case 3,
sys=mdlOutputs(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(interleaver_size)
%
% 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 = 2;
sizes.NumOutputs = -1;
sizes.NumInputs = -1;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
%
% initialize the initial conditions
%
[m J]=mdlInterleaverInit(interleaver_size);
x0 = [m J]';
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts = [-1 0];
% end mdlInitializeSizes
%
%=============================================================================
% mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%=============================================================================
%
function sys=mdlUpdate(t,x,u,interleaver_size)
[m J]=mdlInterleaverInit(interleaver_size);
sys = [m J]';
% end mdlUpdate
%
%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,x,u)
m=x(1);
J=x(2);
exp_m=2^m;
A=zeros(exp_m*J,1);
for i=0:length(u)-1
quotient=fix(i/J);
BRO=0;
for k=1:m
if bitget(quotient,k)==1
BRO=bitset(BRO,m-k+1);
end
end
A(exp_m*mod(i,J)+BRO+1)=u(i+1);
end
sys=A;
function [m,J]=mdlInterleaverInit(interleaver_size)
switch interleaver_size
case 384
m=6;
J=6;
case 768
m=6;
J=12;
case 1536
m=6;
J=24;
case 3072
m=6;
J=48;
case 6144
m=7;
J=48;
case 12288
m=7;
J=96;
case 576
m=5;
J=18;
case 2304
m=6;
J=36;
case 4608
m=7;
J=36;
case 9216
m=7;
J=72;
case 18432
m=8;
J=72;
case 36864
m=8;
J=144;
otherwise
error('交织长度不可用!');
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -