www.pudn.com > ldpc802.16.rar > generate_ldpc_mcwill.m, change:2005-11-10,size:2278b


 
clear all 
close all 
 
per=0.21 
 
seed=randint(1,1,10000); 
randn('state',seed); 
rand('state',seed); 
 
load ldpc_80216e_66r3_r12.mat 
[m,n]=size(ldpc_80216e); 
for i=1:n-m+1 
    loc{i}=find(ldpc_80216e(:,i)~=-1); 
end 
 
while per>0.006 
    Ncol=24; 
    Nrow=12; 
    zmax=96; 
 
    ldpc_mcwill=zeros(Nrow,Ncol)-1; 
    for j=Ncol-Nrow+2:Ncol 
        for i=mod(j,Ncol-Nrow+2)+(1:2) 
            ldpc_mcwill(i,j)=0; 
        end 
    end 
     
    for i=1:n-m 
        location=loc{i}; 
        value=randint(1,length(location),zmax-1)+1; 
%         ldpc_mcwill(mod(location+2,Nrow)+1,i)=value; 
        ldpc_mcwill(location,i)=value; 
    end 
    value=randint(1,1,zmax-1)+1; 
    location=loc{n-m+1}; 
    ldpc_mcwill(location,n-m+1)=value; 
    ldpc_mcwill(location(2),n-m+1)=0; 
%     save ldpc_mcwill ldpc_mcwill 
 
    % Test the performance 
 
    mod_order=4; 
    snr=2.2; 
 
    z=24; 
    zmax=96; 
    H1=ldpc_genHbm_3gpp(ldpc_mcwill,zmax,z); 
    H=ldpc_genH_3gpp(H1,z); 
 
    [m,n]=size(H1); 
    s=randint(1,(n-m)*z); 
    s1=ldpc_encode_80216e(s,H1,z); 
    check=sum(rem(H*s1,2)); 
    [zz,suc,k]=ldpc_decode(s1,H,2); 
     
    for sn=1:length(snr) 
        bercount=0; 
        percount=0; 
        len=0; 
 
        disp(['snr=',num2str(snr(sn))]); 
        tic; 
        for k=1:5e2 
            infonum=n-m; 
            bit=randint(infonum*z,1); 
 
            %Encoding 
            cbit=ldpc_encode_80216e(bit,H1,z); 
 
            %Modulation 
            sym=reshape(cbit,log2(mod_order),length(cbit)/log2(mod_order))'; 
            sym=bi2de(sym,'left-msb'); 
            msym=qammod4(sym); 
 
            %Channel 
            rsym=awgn(msym,snr(sn)); 
 
            %Demodulation 
            demsym=qamdemod4soft(rsym,10^(-snr(sn)/10)); 
 
            %Decoding 
            [zz,suc,kk]=ldpc_decode(demsym,H,2); 
            x=zz(1:(n-m)*z); 
 
            %Error calculate 
            bererr=x-bit; 
            bercount=bercount+length(find(bererr(:))); 
            len=len+length(bererr(:)); 
 
            if length(find(bererr))~=0 
                percount=percount+1; 
            end 
        end 
        ber(sn)=bercount/len 
        per(sn)=percount/(len/(n-m)/z) 
        len 
 
        toc 
    end 
    clear seed 
end