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

📄 ms_sfun_turbopuncture.m

📁 CDMA通过MAtlab仿真的各个模块源程序
💻 M
字号:
function [sys,x0,str,ts] = MS_SFUN_TurboPuncture(t,x,u,flag)
switch flag,

  %%%%%%%%%%%%%%%%%%
  % Initialization %
  %%%%%%%%%%%%%%%%%%
  case 0,
    [sys,x0,str,ts]=mdlInitializeSizes(interleaver_size,code_rate);

  %%%%%%%%%%%
  % Outputs %
  %%%%%%%%%%%
  case 3,
    sys=mdlOutputs(t,x,u,interleaver_size,code_rate);
  case {1,2,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,code_rate)

%
% 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  = 0;
len=(interleaver_size+6)*6;
switch code_rate
    case 1
        out_len=len/3;
    case 2
        out_len=len/2;
    case 3
        out_len=len*2/3;
    otherwise
        error('Error:Invalid Code Rate in MS_SFUN_TurboPuncture');
end
sizes.NumOutputs     = out_len;
sizes.NumInputs      = len;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;   % at least one sample time is needed

sys = simsizes(sizes);

%
% initialize the initial conditions
%
x0  = [];

%
% str is always an empty matrix
%
str = [];

%
% initialize the array of sample times
%
ts  = [-1 0];

% end mdlInitializeSizes


function sys=mdlOutputs(t,x,u,interleaver_size,code_rate)
len=(interleaver_size+6)*6;
index1=1;
index2=len/2+1;
A=zeros(1,len);
for i=1:len
    if mod(i-1,6)<3
        A(i)=u(index1);
        index1=index1+1;
    else
        A(i)=u(index2);
        index2=index2+1;
    end
end
switch code_rate
    case 1
        pattern=[1 1 0 0 0 0 1 0 0 0 1 0];
        pattern1=[1 1 0 0 0 0];
        pattern2=[0 0 0 1 1 0];
        out_len=len/3;
    case 2
        pattern=[1 1 0 0 1 0 1 1 0 0 1 0];
        pattern1=[2 1 0 0 0 0];
        pattern2=[0 0 0 2 1 0];
        out_len=len/2;
    case 3
        pattern=[1 1 1 0 0 1 1 1 0 0 1 1];
        pattern1=[2 1 0 0 0 0];
        pattern2=[0 0 0 2 1 1];
        out_len=len*2/3;
    otherwise
        error('Error:Invalid Code Rate in MS_SFUN_TurboPuncture');
end 

B=zeros(1,out_len);
index=1;

for i=1:(len-36)
    if pattern(mod(i-1,12)+1)==1
        B(index)=A(i);
        index=index+1;
    end
end
        
for i=(len-36)+1:len-18
    for k=1:pattern(mod(i-1,6)+1)
        B(index)=A(i);
        index=index+1;
    end
end

for i=(len-18)+1:len
    for k=1: pattern(mod(i-1,12)+1)
        B(index)=A(i);
        index=index+1;
    end
end

sys = B;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -