📄 ms_sfun_interleaver.asv
字号:
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=mdlInterleaverInit(interleaver_size)
switch interleaver_size
case {378 570 762 1146 1530 2298 3066 4602 6138 9210 12282 20730}
n=ceil(log2(interleaver_size/32);
otherwise
error('Error:Invalid Interleaver Size in MS_SFUN_TurboInterleaver');
end
function index=mdlLookupTable(lsb,n)
LookupTable=[5 27 3 15 3 13 1;
15 3 27 127 1 335 349;
5 1 15 89 5 87 303;
15 15 13 1 83 15 721;
1 13 29 31 19 15 973;
9 17 5 15 179 1 703;
9 23 1 61 19 333 761;
15 13 31 47 99 11 327;
13 93 127 23 13 453;
15 3 9 17 1 1 95;
7 15 15 119 3 121 241;
11 3 31 15 13 155 187;
15 13 17 57 13 1 497;
3 1 5 123 3 175 909;
15 13 39 95 17 421 769;
5 29 1 5 1 5 349;
13 21 19 85 63 509 71;
15 19 27 17 131 215 557;
9 1 15 55 17 47 197;
3 3 13 57 131 425 499;
1 29 45 15 211 295 409;
3 17 5 41 173 229 259;
15 25 33 93 231 427 335;
1 29 15 87 171 83 253;
13 9 13 63 23 409 677;
1 13 9 15 147 387 717;
9 23 15 13 243 193 313;
15 13 31 15 213 57 757;
11 13 17 81 189 501 189;
3 1 5 57 51 313 15 ;
15 13 15 31 15 489 75;
5 13 33 69 67 391 163];
index=LookupTable(lsb+1,n-3);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -