www.gusucode.com > 基于matlab编程(31,25)RS编码及解码源码程序 > 基于matlab编程(31,25)RS编码及解码源码程序/code/rs_decode_iterate.m

    % a function to calculate the locator polynomial according to the syndrome polynomial
function sigma_x=rs_decode_iterate(synd_x)
% for debug, matrix 'x' can storage values of every iteration
% the last row is the final result
sigma=zeros(8,7);
% initial values
x(-1+2,1)=1;
D=zeros(1,8);
D(-1+2)=0;
d=zeros(1,8);
d(-1+2)=1;
sigma(0+2,1)=1;
D(0+2)=0;
d(0+2)=synd_x(1+1);
j=0;
% 'flag' is to record the last non-zero d
flag=-1;
for j=0:5
% massey arithmetic
   if d(j+2)==0
       sigma(j+2+1,:)=sigma(j+2,:);
       D(j+2+1)=D(j+2);
   else
       % to find the 'flag' for the iterate
    sigmaji=circshift(sigma(flag+2,:),[0 j-flag]);
    % iteration to calculate locator polynomial
    for l=1:7
%         if cc(l)==0
%             x(j+2+1,l)=0;
%         else
            sigma(j+2+1,l)=rs_add(sigma(j+2,l),rs_mul(rs_mul(d(j+2),rs_rev(d(flag+2))),sigmaji(l)));
%         end
    end 
    % to get the D(j)
    for h=1:7
        if sigma(j+2+1,h)~=0
            D(j+2+1) =h-1;
        end  
    end
    flag=j;
end
% calculate d for every iteration
if j~=5
    r=j+1;
   d(r+2)=synd_x(r+1+1);
    for k=1:D(r+2)
          d(r+2)=rs_add(d(r+2),rs_mul(sigma(r+2,k+1),synd_x(r+1-k+1)));
   end   
end
end
sigma_x=sigma(6+2,1:(D(8)+1));