www.pudn.com > communicationmatlab.rar > SCONVENC.M


function [sys, x0, str, ts] = sconvenc(t, x, u, flag, tran_func); 
%SVITERBI SIMULINK file for convolution encoding. 
%       This file is designed to be used in a SIMULINK S-Function block. 
%       The function requires the system inputs 
%       tran_func  is one of the two forms of convolution code transfer function. 
% 
 
%       Wes Wang 
%       Copyright (c) 1995-96 by The MathWorks, Inc. 
 
if (flag == 2) % refresh discrete-time states 
  % the major processing routine. 
  if u(length(u)) < .2 
    % in the case of no signal, no processing. 
    return; 
  end; 
 
  % otherwise, there is a signal, have to process. 
 
  % initial parameters. 
  [A, B, C, D, N, K, M] = gen2abcd(tran_func); 
  u = u(1:K); 
  if isempty(C) 
    sys = zeros(M, 1); 
    msg_i = bi2de(u(:)'); 
%    tran_indx = x(1) + 1 + msg_i * 2^K; 
    tran_indx = x(1) + 1 + msg_i * 2^M; 
    sys(1) = tran_func(tran_indx+2, 1); 
  else 
    x = x(:); u = u(:); 
    sys = A * x + B * u; 
    sys = rem(sys, 2); 
  end; 
elseif flag == 3 % output 
  if u(length(u)) < .2 
    % in the case of no signal, no processing. 
    return; 
  end; 
 
  % otherwise, there is a signal, have to process. 
  % initial parameters. 
  [A, B, C, D, N, K, M] = gen2abcd(tran_func); 
  u = u(1:K); 
  if isempty(C) 
    msg_i = bi2de(u(:)'); 
%    tran_indx = x(1) + 1 + msg_i * 2^K; 
    tran_indx = x(1) + 1 + msg_i * 2^M; 
    sys = B(tran_indx, :)'; 
  else 
    x = x(:); u = u(:); 
    sys = C * x + D * u; 
    sys = rem(sys, 2); 
  end; 
elseif flag == 0 
  [A, B, C, D, N, K, M] = gen2abcd(tran_func); 
  x0 = zeros(M, 1); 
  sys = [0; length(x0); N; K+1; 0; 0; 1]; 
  ts = [-1, 0]; 
else 
  sys = []; 
end;