% The Program to test the girth 4 of Gallager LDPC codes
% Copyright (C) Yang XIAO, BJTU, July 26, 2007, E-Mail: yxiao@bjtu.edu.cn,
%
% The program analyzes the girth 4 for Gallager LDPC codes.The figures show
% the parity check matrix H and the girth test matrix O.
% Theorem in Ref [1]: The H matrix has no gith4, iff the O matrix in Fig.2 has no entry value to
% larger than 1.
% Ref:
% [1] Y. Xiao, M -H Lee,Low complexity MIMO-LDPC CDMA systems over multipath channels,
% IEICE Transactions on Communications, v E89-B, n 5, May, 2006, p 1713-1717
% [2] J. Fan, Y. Xiao, A method of counting the number of cycles in LDPC codes,
% 8th International Conference on Signal Processing, ICSP 2006,Volume: 3,
% ISBN: 0-7803-9737-1, Digital Object Identifier: 10.1109/ICOSP.2006.345906
% [3] MOHAMMED ALKHANBASH, Gallager LDPC, Matlab center, File Exchange, 2007
%
% The papers [1] and [2] can be downloaded from Web site of IEICE and IEEE Explore.
%
clear;
% Example: To obtain a H, I revised the program of:MOHAMMED ALKHANBASH, Gallager LDPC, Matlab Center, File Exchange, 2007.
% The code generated by the program of:MOHAMMED ALKHANBASH is not good, we
% only use it to demo the test procedure for girth 4.
% If you have own H, you need not use the sub-program.
%
n=1200 %Code length
c=n/2 %Length of parity check bits
wc=3 %wc: the number of ones in each columns
wr=(n.*wc)./c %wr:the number of ones in each row
h=zeros(c,n); %generate the empty matrix and start
%assigning the 1s
%Step 1:LDPC Code Generatio
onesvector=ones(1,wr);
start=1;
finish=wr;
for ii = 1:c./wc
h(ii,start:finish)=1;
start=start+wr;
finish=(ii.*wr)+wr;
end
for i=1:wc-1
r=1;
for ii=1:n
col_index = (round(rand(1) * (n-1) ))+1;
randomCol=h(1:fix(c/wc),col_index);
h((i*fix(c/wc))+1 : ((i*(c/wc))+1 + fix(c/wc)-1),ii )=randomCol;
end
r=r+1;
end
%%%%%%% Girth4 Test %%%%%
% Here, we only concern whether a parity matrix H has girth4, instead of
% the number of girth4. If you need know the nember of girth 4, please
% refer Ref. [2].
% get the number of H
rows=size(h,1);
cols=size(h,2);
% We can test girth 4 by using the matrix O, see [1].
O=h*h';
for i=1:rows
O(i,i)=0;
end
for i=1:rows
girth(i)=max(O(i,:));
end
girth4=max(girth);
if girth4<2
fprintf('No girth 4')
else
fprintf('The H matrix has girth 4\n') % Provde the test result.
end
% Display the matrice H and O
% If H matrix has no gith4, the O matrix in Fig.2 has no entry value to
% larger than 1.
figure(1)
mesh(h)
figure(2)
mesh(O)
fprintf('Please see your H matrix in Fig. 1, and the O matrix in Fig.2')