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
%add 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;
%add 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(cols);
end
parity_check(i,j)=1;
row_flag(i)=row_flag(i)+1;
end
if row_flag(i)==0
for k=1:2
j=unidrnd(cols);
while parity_check(i,j)==1
j=unidrnd(cols);
end
parity_check(i,j)=1;
row_flag(i)=row_flag(i)+1;
end
end
end
%try to distribute the ones so that the number of ones per row is as uniform as possible
for i=1:rows
j=1;
a=randperm(cols);
while row_flag(i)>max_ones_per_row;
if parity_check(i,a(j))==1
parity_check(i,a(j))=0;
row_flag(i)=row_flag(i)-1;
newrow=unidrnd(rows);
k=0;
while row_flag(newrow)>=max_ones_per_row | parity_check(newrow,a(j))==1
newrow=unidrnd(rows);
k=k+1;
if k>=rows
break;
end
end
if parity_check(newrow,a(j))==0
parity_check(newrow,a(j))=1;
row_flag(newrow)=row_flag(newrow)+1;
else
parity_check(i,a(j))=1;
row_flag(i)=row_flag(i)+1;
end
end%if loop
j=j+1;
end%while loop
end%for loop
row_flag;
parity_check;
parity_check;
%try to eliminate cycles of length 4 in the factor graph
for loop=1:10
ones_position(1)=0;
for r=1:rows
ones_count=0;
for c=1:cols
if parity_check(r,c)==1
ones_count=ones_count+1;
ones_position(ones_count)=c;
end
end
for i=1:r-1
common=0;
for j=1:ones_count
if parity_check(i,ones_position(j))==1
common=common+1 ;
if common==1
thecol=ones_position(j);
end
end
if common==2
common=common-1;
if(round(rand)==0)
coltoberearranged=thecol;
thecol=ones_position(j);
else
coltoberearranged=ones_position(j);
end
parity_check(i,coltoberearranged)=3; %make this entry 3 so that we dont use
%of this entry again while getting rid
%of other cylces
newrow=unidrnd(rows);
%while ((newrow==i)|(parity_check(newrow,ones_position(j))==1))
iteration=0;
while parity_check(newrow,coltoberearranged)~=0
newrow=unidrnd(rows);
iteration=iteration+1;
if iteration==5
break;
end
end
if iteration==5
while parity_check(newrow,coltoberearranged)==1
newrow=unidrnd(rows);
end
end
parity_check(newrow,coltoberearranged)=1;
end
end
end
for i=r+1:rows
common=0;
for j=1:ones_count
if parity_check(i,ones_position(j))==1
common=common+1 ;
if common==1
thecol=ones_position(j);
end
end
if common==2
common=common-1;
if(round(rand)==0)
coltoberearranged=thecol;
thecol=ones_position(j);
else
coltoberearranged=ones_position(j);
end
parity_check(i,coltoberearranged)=3;%make this entry 3 so that we dont use
%of this entry again while getting rid
%of other cylces
newrow=unidrnd(rows);
%while ((newrow==i)|(parity_check(newrow,ones_position(j))==1))
iteration=0;
while parity_check(newrow,coltoberearranged)~=0
newrow=unidrnd(rows);
iteration=iteration+1;
if iteration==5
break
end
end
if iteration==5
while parity_check(newrow,coltoberearranged)==1
newrow=unidrnd(rows);
end
end
parity_check(newrow,coltoberearranged)=1;
end
end
end
end
end;
parity_check;
for i=1:rows
row_flag(i)=0;
for j=1:cols
if parity_check(i,j)==1
row_flag(i)=row_flag(i)+1;
end
if eq(parity_check(i,j),3) %replace the 3's with 0's
parity_check(i,j)=0;
end
end
end
variance=var(row_flag)
H=parity_check;
%Get the Parity Checks
%A=0;
%B=0;
%for i=1:rows
% for j=1:rows
% A(i,j)=parity_check(i,j);
% end
%end
%for i=1:rows
% for j=rows+1:cols
% B(i,j-rows)=parity_check(i,j);
% end
%end
%ainvb=inv(sparse(A))*sparse(B);
%ainvb=inv(A)*B;
%toc
阿里matlab建模师
- 粉丝: 4361
- 资源: 2852
最新资源
- CO2半自动焊接小车在电力变压器油箱制造中的应用.pdf
- CO2焊接飞溅产生原因与防止方法探究.pdf
- CO2焊接在起重机轨道焊接中的应用.pdf
- 基于智慧医疗系统—全部资料+高分项目+详细文档.zip
- 基于智慧医院信息管理系统HIS 全部资料+高分项目+详细文档.zip
- CO2气体保护焊横焊接头无损检测方法研究.pdf
- CO2气保焊机与焊接工艺参数的匹配.pdf
- CO2气体保护焊焊接工艺试验与应用.pdf
- 基于智慧园区管理系统:基于园区业务,深度挖掘流程与系统的关键结合点,发挥互联网的优势,系统主要实现园区的资产管理,企业服务及档案管理,园区的活动及商城的搭建。全部资料+高分项目+详细文档.zip
- Cr25Ni20耐热不锈钢的焊接工艺 - .pdf
- 基于智慧园区 园区大脑-平台管理系统全部资料+高分项目+详细文档.zip
- CRHl型动车组构架焊接制造工艺分析 - .pdf
- CRH350横梁管和连接座选材与OTC机械手焊接工艺分析 - .pdf
- CR技术在超薄焊接结构件中的研究与应用.pdf
- CSA W47.1-1992 中文版 钢结构熔化焊的公司资格 焊接.pdf
- CT20低温钛合金氩弧焊接接头显微组织及性能 - .pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
前往页