www.pudn.com > ldpc802.16.rar > transceiver.m, change:2006-08-10,size:4222b


%tranceiver 
close all; 
clear all; 
 
seed=randint(1,1,10000); 
seed=34085; 
rand('state',seed); 
randn('state',seed); 
 
fdm=300; 
 
% Vector channel model 
VectChan.M=1; 
VectChan.BtsAngleSpread=50; 
VectChan.ArrayGeometry='linear'; 
VectChan.AntSpace=0.5; 
 
Nbs=1024; 
Npref=6;    % ofdm prefix is 6e-6 (s) 
Npostf=4;     % ofdm postfix is 3.5e-6 (s) 
Ncarr=128;  % subcarrier number 
Nsub=16;   %number of subchannels in each carrier group 
N=8;    % full loading factor 
Nc=8;   % loading factor 
Nup=8;  % oversampling rate is 8e6 (Hz) 
Ndown=8;    % downsampling rate is 2e6 (Hz) 
Nsym=8;     % symbol length in one time slot 
 
%control parameter 
snr=35;%[12,16,20,24,28,32];  
trial=1; 
 
%modulation 
mod_order=4;    scale=sqrt(0.5); % modulation is QAM4 
W1=hadamard(N)/sqrt(N);  % spreading matrix 
 
%subchannel definition 
tone_st=(Nbs-Ncarr)/2; 
for j=1:Nsub, 
    sc_tone_ind{j}=j:Nsub:Ncarr; 
end; 
 
if Nc~=8 
    W=W1; 
else 
    W=eye(N); 
end 
 
tic; 
for sn=1:length(snr) 
    sercount=0; 
    bercount=0; 
    sss=zeros(Nc*Nsub,Nsym*trial); 
    err=zeros(Nc*Nsub,Nsym*trial); 
    for tr=1:trial 
        x=zeros(Ncarr,Nsym); 
        xp=zeros(Ncarr,Nsym); 
        for j=1:Nsub 
            sym{j}=randint(Nc,Nsym,mod_order);  % source symbol 
            s{j}=de2bi(sym{j},log2(mod_order),'left-msb');  % source bit 
            sp{j}=exp(sqrt(-1)*2*pi*rand(N,Nsym))*sqrt(Nc/N);   % pilot, power is equal to traffic power 
            x(sc_tone_ind{j},:)=W(:,1:Nc)*qammod(sym{j},4,0,'gray')*scale; 
            xp(sc_tone_ind{j},:)=sp{j}; 
             
            sss((j-1)*Nc+1:j*Nc,(tr-1)*Nsym+1:tr*Nsym)=qammod4(sym{j}); 
        end; 
        y=zeros(Nbs,Nsym); 
        y(tone_st+(1:Ncarr),:)=x; 
        yp=zeros(Nbs,Nsym); 
        yp(tone_st+(1:Ncarr),:)=xp; 
 
        %ifft, add prefix and postfix 
        yt=ifft(ifftshift(y,1))*sqrt(Ncarr)*Nup; 
        yt=[yt(end-Npref*Nup+1:end,:); yt; yt(1:Npostf*Nup,:)]; 
        yt=yt(:).'; 
        ypt=ifft(ifftshift(yp,1))*sqrt(Ncarr)*Nup; 
        ypt=[ypt(end-Npref*Nup+1:end,:); ypt; ypt(1:Npostf*Nup,:)]; 
        ypt=ypt(:).'; 
 
        %fading channel 
        rx=vector_fading_doppler_channel_mx(yt, 'itu', '3A', VectChan, [num2str(fdm),'Hz'], Nup, Ndown, tr); 
        rxp=vector_fading_doppler_channel_mx(ypt, 'itu', '3A', VectChan, [num2str(fdm),'Hz'], Nup, Ndown, tr); 
 
        %awgn channel 
%         rx=awgn(rx{1}, snr(sn), 10*log10(Ndown)); 
        rx=rx{1};%awgn(rxp{1}, snr(sn), 10*log10(Ndown)); 
        rxp=rxp{1}; 
 
        %receiver 
        %delete prefix and postfix 
        zt=reshape(rx,Nbs+(Npref+Npostf)*Ndown,Nsym); 
        zt(1:Npref*Ndown,:)=[]; zt(end-Npostf*Ndown+1:end,:)=[]; 
        zpt=reshape(rxp,Nbs+(Npref+Npostf)*Ndown,Nsym); 
        zpt(1:Npref*Ndown,:)=[]; zpt(end-Npostf*Ndown+1:end,:)=[]; 
 
        %fft 
        zf=fftshift(fft(zt),1)/sqrt(Ncarr)/Ndown; 
        zpf=fftshift(fft(zpt),1)/sqrt(Ncarr)/Ndown; 
 
        %mmse detection 
        %channel estimation 
        for j=1:Nsub, 
            zpef{j}=zpf(tone_st+sc_tone_ind{j},:)./sp{j};%qammod(sym{j},4,0,'gray')/scale; 
            zef{j}=zf(tone_st+sc_tone_ind{j},:); 
             
            %mmse detection 
            for t=1:Nsym, 
                H=diag(zpef{j}(:,t))*W(:,1:Nc); 
                A=inv(H'*H+eye(Nc)*10^(-snr/10))*H'; 
                sd{j}(:,t)=A*zef{j}(:,t); 
            end; 
             
            err((j-1)*Nc+1:j*Nc,(tr-1)*Nsym+1:tr*Nsym)=sd{j}; 
             
            se{j}=qammod(qamdemod(sd{j}/scale,4),4)*scale; 
            errsym{j}=se{j}-sd{j}; 
            sdint{j}=qamdemod(sd{j}/scale,4); 
            snr_out(j)=10*log10(1/mean(abs(errsym{j}(:)).^2)); 
            sererr=sdint{j}-sym{j}; 
            sdb{j}=de2bi(sdint{j},log2(mod_order),'left-msb'); 
            bererr=sdb{j}-s{j}; 
             
            sercount=sercount+length(find(sererr)); 
            bercount=bercount+length(find(bererr)); 
        end; 
    end 
    ser(sn)=sercount/(trial*Nc*Nsub*Nsym); 
    ber(sn)=bercount/(trial*Nc*Nsub*Nsym*log2(mod_order)); 
     
%     eval(['save e:\liuyu\simdata\fdm',num2str(fdm),'snr',num2str(snr(sn)),'mod',num2str(mod_order),'.mat ']); 
end 
toc 
 
snr_out