sconvenc.m

来自「通信系统的matlab仿真程序」· M 代码 · 共 62 行

M
62
字号
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;

⌨️ 快捷键说明

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