www.pudn.com > matlab.rar > rs_decode_iterate.m, change:2015-04-15,size:1293b


% 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(34,33); 
% initial values 
x(-1+2,1)=1; 
D=zeros(1,34); 
D(-1+2)=0; 
d=zeros(1,34); 
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:31 
% 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:33 
%         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:33 
        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~=31 
    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(32+2,1:(D(32)+1));