function [dec,success] = LDPC_decoder(receiveword,sigma,H,IterNum)
[M,N] = size(H);
K = N-M;
rate = K/N;
H = int8(H);
maxrowdegree = max(sum(H'));
maxcolumndegree = max(sum(H));
VNlen=zeros(1,N);
VNset=zeros(N,maxcolumndegree);
CNlen=zeros(1,M);
CNset=zeros(M,maxrowdegree);
for i=1:N
temp=find(H(:,i));
VNlen(i)=length(temp);
for j=1:Vnlen(i)
VNset(i,j)=temp(j);
end
end
for i=1:M
temp=find(H(i,:));
CNlen(i)=length(temp);
for j=1:CNlen(i)
CNset(i,j)=temp(j);
end
end
%参数初始化
success=0;
p0=(1+exp(-2*(sigma^(-2)).*receiveword)).^(-1);
p1=(1+exp(2*(sigma^(-2))).*receiveword)).^(-1);
messQ0=zeros(M,N);
messQ1=zeros(M,N);
messR0=zeros(M,N);
messR1=zeros(M,N);
for i=1:N
for j=1:VNlen(i)
messQ0(VNset(i,j),i)=p0(i);
messQ1(VNset(i,j),i)=p1(i);
end
end
iter=0;
%迭代译码
for i=1:IterNum
iter=iter+1;
for j=1:M;
for k=1:CNlen(j)
delta=1;
for t=1:CNlen(j)
if(CNset(j,k)~=CNset(j,t))
delta=delta*(1-2*messQ1(j,CNset(j,t)));
end
end
messR0(j,CNset(j,k))=0.5+0.5*delta;
messR1(j,CNset(j,k))=1-messR0(j,CNset(j,k));
end
end
for j=1:N
for k=1:VNlen(j)
alpha1=1;
alpha2=1;
alpha=1;
for t=1:VNlen(j)
if(VNset(j,k)~=VNset(j,t))
alpha1=alpha1*messR0(VNset(j,t),j);
alpha2=alpha2*messR1(VNset(j,t),j);
end
end
alpha=1/(p0(j)*alpha1+p1(j)*alpha2);
messQ0(VNset(j,k),j)=alpha*p0(j)*alpha1;
messQ1(VNset(j.k),j)=alpha*p0(j)*alpha2;
end
end
%加权值统计
Q0=zeros(1,N);
Q1=zeros(1,N);
for j=1:N
gama1=1;
gama2=1;
gama=1;
for k=1:VNlen(j)
gama1=gama1*messR0(VNset(j,k),j);
gama2=gama2*messR1(VNset(j,k),j);
end
gama=1/(p0(j)*gama1+p1(j)*gama2);
Q0(j)=gama*p0(j)*gama1;
Q1(j)=gama*p1(j)*gama2;
end
%译码判决
for j=1:N
if(Q0(j)>=0.5)
decodeword(j)=0;
else
decodeword(j)=1;
end
end
%检查校验方程
CH=mod(double(H)*decodeword',2);
if(CH==0)
success=1;
break;
end
end
%译码输出
dec = decodeword(1,N-M);
|