www.pudn.com > ldpc802.16.rar > ldpc_decode_llr.m, change:2006-08-03,size:2483b


function [x_hat, success, k] = ldpc_decode(f,H,qq) 
% decoding of LDPC over GFqq, qq = 2,4,8,16,32,64,128 and 256 
% outputs the estimate "x_hat" of the ENCODED sequence for 
% the received vector with channel log likelihoods ratio "f". 
% "f" ([2^qq][n]) stores the log likelihoods ratio for "n" symbols in natural ordering 
% "H" is the parity check matrix. Success==1 signals 
% successful decoding. Maximum number of iterations is set to 10. 
% k returns number of iterations until convergence. 
% 
%   Copyright (c) 2005 by liuyu 
%   $Revision: 1.0 
%   fixed high-SNR decoding 
%   works for GFq, q= 2^m now 
 
if qq == 2                        % binary case first, just use the old code 
    
   [m,n] = size(H);  
   if m > n,  
       H=H';  
       [m,n] = size(H);  
   end 
    
   if ~issparse(H)                % make H sparse if it is not sparse yet 
      [ii,jj,sH] = find(H); 
      H = sparse(ii,jj,sH,m,n); 
   end 
 
   Yn = f(:); 
   Zmn = zeros(m,n); 
   for k1 = 1:m 
       Zmn(k1,:) = Yn(:); 
   end 
    
   %iterations 
   k=0; 
   success = 0; 
   max_iter = 50; 
   Lmn = zeros(m,n); 
   while ((success == 0) & (k < max_iter)), 
      k = k+1; 
    
      %horizontal step         
      for k1 = 1:m 
           
          loc = find(H(k1,:)); 
          tmp=exp(Zmn(k1,loc)); 
          tmp(find(tmp==0))=1e-200; 
          tmp(find(tmp==inf))=1e200; 
          Tmn_tmp=(1-tmp)./(1+tmp); 
          Tmn=prod(Tmn_tmp)./Tmn_tmp; 
          numerator=1-Tmn; 
          denominator=1+Tmn; 
          loc_num=find(Tmn==1); 
          numerator(loc_num)=1e-200; 
          loc_deno=find(Tmn==-1); 
          denominator(loc_deno)=1e-200; 
          Lmn(k1,loc)=log(numerator./denominator); 
                     
      end 
    
      %vertical step 
      Zn=zeros(1,n); 
      for k1 = 1:n 
           
          tmp = find(H(:,k1)); 
          Zn(k1) = Yn(k1) + sum(Lmn(tmp,k1)); 
          Zmn(tmp,k1)=Zn(k1)-Lmn(tmp,k1); 
           
      end 
    
      %tentative decoding    
 
      x_hat(find(Zn(:)>0)) = 1; 
      x_hat(find(Zn(:)<0)) = 0; 
 
      rs = rem(H*x_hat',2); 
      dim = size(rs,1); 
      count = 0; 
      for i = 1:dim 
          if rs(i) ~= 0,  
              count = count + 1; 
          end 
      end 
      if count == 0,  
          success = 1; 
      end 
       
   end 
   % end of binary case 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 
else  
end % end of nonbinary case