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

    % a function to realize a decoder, summation of some of the other functions
% the input 'r_x' is the output sequence of the function rs_channel()
% the output 'm_x' is the sequence after decoding
function m_x=rs_decoder(r_x);
disp('伴随多项式:')
synd_x=rs_decode_syndrome(r_x);
% to view the results clearly, pause, press any key to continue
disp('Press any key to continue...')
pause
disp('错误位置多项式:')
sigma_x=rs_decode_iterate(synd_x);
disp('Press any key to continue...')
pause
disp('错误位置多项式的根:')
root=rs_decode_root(sigma_x);
disp('Press any key to continue...')
pause
% if number of error is more than t, cases of no root and few or more root will occur
if length(root)==0
   disp('检测不到错误发生,解码输出:')
   m_x=r_x(7:31);
else
   disp('错误数值和错误位置:')
   [value,site]=rs_decode_forney(synd_x,sigma_x,root);
   disp('Press any key to continue...')
   pause
   temp=r_x;
   for i=1:length(site)
        temp(site(i)+1)=rs_add(r_x(site(i)+1),value(i));
   end
   if length(root)>3
       disp('Too many errors occur, can not correct them all')
       disp('部分纠错解码输出:')
       m_x=temp(7:31);
   else
       disp('解码输出:')
       m_x=temp(7:31);
    end
end