%具体说明见:http://arun-10。tripod。com/ldpc/generate。html
%GENERATING THE PARITY CHECK MATRIX
function [H]=gen_ldpc(rows,cols)
%H=gen_ldpc(rows,cols)
%For examples and more details, please refer to the LDPC toolkit tutorial at
%http://arun-10。
tripod。com/ldpc/ldpc。
htm
bits_per_col=3;
for i=1:rows
row_flag(i)=0;
for j=1:cols
parity_check(i,j)=0;
end
end
�d bits_per_col 1's to each column with the only constraint being that the 1's should be
%placed in distinct rows
for i=1:cols
a=randperm(rows);
for j=1:bits_per_col
parity_check(a(j),i)=1;
row_flag(a(j))=row_flag(a(j)) 1;
end
end
row_flag;
max_ones_per_row=ceil(cols*bits_per_col/rows);
parity_check;
�d 1's to rows having no 1(a redundant row) or only one 1(that bit in the codeword becomes
%zero irrespective of the input)
for i=1:rows
if row_flag(i)==1
j=unidrnd(cols);
while parity_check(i,j)==1
j=unidrnd