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


function [sys, x0, str, ts] = simrscod(t, x, u, flag, n, k, pg, tp, dim); 
%SIMBCHDC SIMULINK S-function for Reed-Solomon encode. 
%       The m-dile is designed to be used in a SIMULINK S-Function block. 
%       This function will encode the input integer vector using RS-code. 
%       Parameters: n -- length of code word. 
%                   k -- length of message. 
%                   pg-- generator polynomial 
%                   tp-- list of all GF(2^M) elements. n=2^M-1. 
%                   dim -- M. 
% 
%       The output has length n. 
 
%       Wes Wang 
%       Copyright (c) 1995-96 by The MathWorks, Inc. 
 
if (flag == 3) 
    % refresh the state only when there is a trigger signal 
    len_u = length(u); 
    if u(len_u) 
        % main calculation 
        t2 = n - k; 
        pgg = fliplr(pg(1:length(pg)-1));       % pg is a monic polynomial 
        msg = u(1 : len_u-1) - 1; 
        msg = [flipud(msg); -ones(t2,1)]; 
        for main_j = 1 : len_u-1 
            if msg(main_j)>= 0 
                for main_k = 1: t2 
                    msg(main_j + main_k) = gfadd(msg(main_j + main_k), gfmul(msg(main_j), pgg(main_k), tp), tp); 
                end; 
            end; 
        end; 
        sys = [flipud(msg(len_u:n))+1; u(1:len_u-1)]; 
        indx = find(~(sys >= 0)); 
        sys(indx) = indx - indx; 
    else 
        % if there is no trigger, no calculation. 
        sys = zeros(n, 1); 
    end; 
elseif flag == 0 
    if 2^dim-1 ~= n 
        error('Ree-Solomon encode has illegal code word length') 
    end; 
    sys(1) = 0; % no continuous state 
    sys(2) = 0; 
    sys(3) = n;   % number of output, code word length plus one. 
    sys(4) = k + 1;       % number of input, message length. 
    sys(5) = 0; 
    sys(6) = 1;       % direct through flag. 
    sys(7) = 1;       % one sample rate 
    x0 = []; 
    ts = [-1, 0]; 
else 
    sys = []; 
end;