www.pudn.com > ldpc802.16.rar > test_spreading.m, change:2005-11-02,size:2292b


clear all; 
close all; 
 
seed=randint(1,1,100000); 
seed=13058; 
randn('state',seed); 
rand('state',seed); 
 
snr=4; %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; 
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,Nc,sym_num/Nc).'; 
% 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,sym_num/Nc); 
h1=reshape(h,N,tone_num/N); 
Ws=W(:,1:Nc); 
x1=zeros(Nc,sym_num/Nc); 
for i=1:sym_num/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,sym_num*2); 
se1=zeros(Nc,sym_num/Nc); 
for i=1:sym_num/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,sym_num*2/Nc,Nc); 
% % demod1=demod1(:); 
% demod=zeros(1,sym_num*2); 
% for i=1:size(demod1,1)/2 
%     temp=demod1((i-1)*2+1:i*2,:); 
%     temp=temp(:); 
%     demod((i-1)*Nc*2+1:i*Nc*2)=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 
    tt(i)=succ; 
end 
 
se1=se1(:).'; 
sd1=(sign(real(se1))+sqrt(-1)*sign(imag(se1)))*0.7071; 
err1=sd1-s; 
ser1=length(find(err1(:)>0))/length(err1(:)), 
plot(se1,'.'),