標題: LDPC編解碼程序 [打印本頁] 作者: 金銀有名 時間: 2018-4-13 20:04 標題: LDPC編解碼程序 LDPC編解碼程序:
function [x_hat, success, k] = ldpc_decode(f0,f1,H)
% outputs the estimate x_hat of the ENCODED sequence for
% the received vector y with channel likelihoods of '0' and '1's
% in f0 and f1 and parity check matrix H. Success==1 signals
% successful decoding. Maximum number of iterations is set to 100.
% k returns number of iterations until convergence.
%
% Example
% We assume G is systematic G=[A|I] and, obviously, mod(G*H',2)=0
% sigma = 1; % AWGN noise deviation
% x = (sign(randn(1,size(G,1)))+1)/2; % random bits
% y = mod(x*G,2); % coding
% z = 2*y-1; % BPSK modulation
% z=z + sigma*randn(1,size(G,2)); % AWGN transmission
%
% f1=1./(1+exp(-2*z/sigma^2)); % likelihoods
% f0=1-f1;
% [x_hat, success, k] = ldpc_decode(z,f0,f1,H);
% x_hat = z_hat(size(G,2)+1-size(G,1):size(G,2));
% x_hat = x_hat';
% fixed high-SNR decoding
[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,m,n);
end
%initialization
[ii,jj] = find(H); %subscript index to nonzero elements of H
index = sub2ind(size(H),ii,jj); %linear index to nonzero elements of H
q0 = H*spdiags(f0(:),0,n,n);
sq0 = full(q0(indx));
sff0 = sq0;