function [N, M, VD, V, CD, C, H]=circulants_to_vasic_coding_lab(input_file,output_file) %perm_to_tanner(input_file,output_file) %converts the parity QC LDPC check matrix given as the list of %powers of permutation matrices into a conventional Tanner graph form used %in Error Correction Coding Lab. %It works only for binary matrices H. %The H Matrix is stored in a text file in a compact form described as follow: %- The first line gives the number of varible nodes(VN) and the number of check nodes(CN) % - The subsequent VN lines describe the check node connection of variable nodes. Each line % corresponds to a variable node. The first entry of a line is the number of check nodes that % the particular variable is connected to. The remaining entries on the line give the check nodes. % - The next CN lines describe the variable node connection of check nodes in a similar fashion. % ____________________________________________________________________________________________________ % IMPORTANT NOTICE: The function will automatically detect the convention of indexing variable nodes % and check nodes from 0 or 1. However, the indexing convention of the Tanner graph output of the % *function will be: VARIABLE NODES AND CHECK NODES ARE INDEXED STARTING FROM 0 (ZERO). %____________________________________________________________________________________________________ % % **************************************************************************************************** % * Notation % * VN : Number of variable nodes (code length). % * CN : Number of check nodes. % * VariableDegree[i]: Degree of variable node i % * VariableConnections[i][:]: Check nodes to which variable node i is connected. % * CheckDegree[k]: Degree of check node k % * CheckConnections[i][:] : Variable nodes to which check node k is connected. if nargin<2 output_file='output.txt' end if nargin<1 input_file='K8400M560Mod_Flash_464_dv4_L140_parsed_CL.txt' end f=fopen(input_file,'r'); x=fscanf(f,'%d',inf); fclose(f); M=x(1); N=x(2); L=x(3); GFOrder=x(4); if GFOrder>2 fprintf('The code in %s is nonbinary. The coefficients will not be written in the output file\n', input_file); end I=eye(L); P=[I(2:L,:);I(1,:);]; x=x(5:length(x)); if length(x)==2*M*N coef=x(M*N+1:length(x)); end x=x(1:M*N); p_qc=reshape(x,N,M)'; coef=reshape(coef,N,M)'; %building binary matrix Hb=[];Hn=[]; for i=1:M Xb=[]; Xn=[]; for j=1:N if p_qc(i,j)<0 Xb=[Xb zeros(L,L)]; Xn=[Xn zeros(L,L)]; else Xb=[Xb P^p_qc(i,j)]; Xn=[Xn coef(i,j).*P^p_qc(i,j)]; end end Hb=[Hb;Xb]; Hn=[Hn;Xn]; end H=Hb; [M,N]=size(Hb); MaxVarDegree=max(sum(Hb,1)); MaxCheckDegree=max(sum(Hb,2)); V=zeros(N,MaxVarDegree); C=zeros(M,MaxCheckDegree); for i=1:N VD(i)=sum(Hb(:,i)); V(i,1:VD(i))=find(Hb(:,i))-1; end VD=reshape(VD,N,1); for i=1:M CD(i)=sum(Hb(i,:)); C(i,1:CD(i))=find(Hb(i,:))-1; end CD=reshape(CD,M,1); f=fopen(output_file,'w'); fprintf(f,'%d %d \n',N,M); for i=1:N fprintf(f,'%2d ',VD(i)); fprintf(f,'%5d ',V(i,1:VD(i))-1); fprintf(f,'\n'); %-1 is to force indexing from 0 end %fprintf(f,'\n'); for i=1:M fprintf(f,'%2d ',CD(i)); fprintf(f,'%5d ',C(i,1:CD(i))-1); fprintf(f,'\n'); %-1 is to force indexing from 0 end % fprintf(f,'\n'); % if GFOrder>2 % for i=1:M % fprintf(f,'%2d ',Hn(i,Hn(i,:)>0)); fprintf(f,'\n'); % end % fprintf(f,'\n'); % end fclose(f);