www.pudn.com > ldpc802.16.rar > ldpc_decode_bp_based.m, change:2005-11-28,size:2771b


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 
    
   %initialization 
%    [ii,jj,sH] = find(H);          % subscript index to nonzero elements of H  
%    indx = sub2ind(size(H),ii,jj); % linear index to nonzero elements of H 
%    q0 = sign(Zmn(:)); 
%    Dmn = H * spdiags(q0(:),0,n,n); 
    
   %iterations 
   k=0; 
   success = 0; 
   max_iter = 10; 
   Lmn = zeros(m,n); 
   while ((success == 0) & (k < max_iter)), 
      k = k+1; 
    
      %horizontal step       
      for k1 = 1:m 
           
          tmp = find(H(k1,:)); 
          [fmin,loc] = min(abs(Zmn(k1,tmp))); 
          location = tmp(loc); 
          si(find(sign(Zmn(k1,tmp))>0)) = 1; 
          si(find(sign(Zmn(k1,tmp))<0)) = 0; 
          sig = mod(sum(si),2); 
          si = ~xor(sig,si); 
          Lmn(k1,tmp) = (-1).^si * fmin; 
          tmp(loc) = []; 
          smin = min(abs(Zmn(k1,tmp))); 
          Lmn(k1,location) = sign(Lmn(k1,location)) * smin; 
           
          si=[]; 
                     
      end 
    
      %vertical step 
      Zn=zeros(1,n); 
      for k1 = 1:n 
           
          tmp = find(H(:,k1)); 
          Zn(k1) = Yn(k1) + sum(Lmn(tmp,k1)); 
          for i=1:length(tmp) 
              Zmn(tmp(i),k1) = Zn(k1) - Lmn(tmp(i),k1);      
          end 
           
      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