www.pudn.com > ldpc802.16.rar > test_spreading1.m, change:2005-10-28,size:2716b


clear all; 
close all; 
 
seed=randint(1,1,100000); 
seed=13058; 
randn('state',seed); 
rand('state',seed); 
 
snr=4.5; %dB 
 
load matr960_480_3 
load matr960_480_3g 
 
[m,n]=size(H); 
 
N=8;  
Nc=8; 
sym_num=(n-m)*Nc; 
tone_num=(n-m)*N; 
W=hadamard(N)/sqrt(N); 
mod_sch='qask'; 
mod_order=4; 
 
trial=10; 
percount=0; 
 
for tr=1:trial 
    bit=randint(sym_num,1); 
 
    % encoding 
    for i=1:Nc 
        tmp=bit((i-1)*(n-m)+1:i*(n-m)); 
        bit1((i-1)*n+1:i*n)=ldpc_encode(tmp,G,2); 
    end 
 
    % interleaving 
%     bit1=reshape(bit1,2*Nc,length(bit1)/2/Nc)'; 
%     bit1=bit1(:); 
 
    sym=reshape(bit1,2,length(bit1)/2)'; 
    sym=bi2de(sym,'left-msb'); 
    s=qammod4(sym); 
 
    % interleaving 
%     s1=reshape(s,n/log2(mod_order),length(s)*log2(mod_order)/n).'; 
%     s1=s1(:); 
 
    %channel 
    h=randn(tone_num,1)+sqrt(-1)*randn(tone_num,1); 
    h=h/sqrt(mean(abs(h).^2));%*10^(snr/20); 
 
    % spreading 
    s1=reshape(s,Nc,length(s)/Nc); 
    h1=reshape(h,N,length(h)/N); 
    Ws=W(:,1:Nc); 
    x1=zeros(Nc,length(s)/Nc); 
    for i=1:length(s)/Nc, 
        x1(:,i)=diag(h1(:,i))*Ws*s1(:,i); 
    end; 
 
    % add noise 
%     seed=13058; 
%     randn('state',seed); 
%     rand('state',seed); 
 
    x1=awgn(x1,snr,0); 
 
    % mmse detection and demodulation 
    demod=zeros(1,length(s)*2); 
    se1=zeros(Nc,length(s)/Nc); 
    for i=1:length(s)/Nc, 
        H1=diag(h1(:,i))*Ws; 
 
        % mmse detection 
        A=inv(H1'*H1+eye(Nc)*10^(-snr/10))*H1'; 
        se1(:,i)=A*x1(:,i); 
 
        % demodulation 
        B=inv(H1'*H1+eye(Nc)*10^(-snr/10))*H1'*H1; 
        for j=1:size(B,1) 
            a=A(j,:); 
            b=B(j,:);b(j)=0; 
            sigma2=sum(abs(a).^2)*10^(-snr/10)+sum(abs(b).^2); 
            demod((i-1)*size(se1,1)*2+2*j-1:(i-1)*size(se1,1)*2+2*j)=qamdemod4soft_mmse(se1(j,i),B(j,j),sigma2); 
        end 
    end; 
 
    % deinterleaving 
%     demod1=reshape(demod,Nc*2,length(demod)/Nc/2); 
% %     demod1=demod1(:); 
%     demod=zeros(1,length(s)*2); 
%     for i=1:size(demod1,1)/2 
%         temp=demod1((i-1)*2+1:i*2,:); 
%         temp=temp(:); 
%         demod((i-1)*n+1:i*n)=temp; 
%     end 
 
    % de=demod>0.5; 
    % de=reshape(de,2,length(de)/2)'; 
    % desym=bi2de(de,'left-msb'); 
    % err=desym-sym; 
    % sercount=length(find(err)~=0); 
    % ser=sercount/length(err) 
    % 
    % % decoding 
    for i=1:Nc 
        tmp=demod((i-1)*n+1:i*n); 
        [zz,succ,kk]=ldpc_decode(tmp,H,2);kk 
        debit((i-1)*(n-m)+1:i*(n-m))=zz(size(G,2)+1-size(G,1):size(G,2)); 
        if succ~=1 
            percount=percount+1; 
        end 
    end 
end 
err=debit-bit'; 
ber=length(find(err))/length(err) 
bler=percount/(trial*Nc)