www.pudn.com > ldpc802.16.rar > transceiver_ldpc_comp_80216e.m, change:2005-11-07,size:5671b


%tranceiver 
close all; 
clear all; 
 
seed=randint(1,1,10000); 
% seed=89438; 
rand('state',seed); 
randn('state',seed); 
 
Nbs=512; 
Npref=64;    % ofdm prefix is 6e-6 (s) 
Npostf=0;     % ofdm postfix is 3.5e-6 (s) 
 
Nup=2;  % oversampling rate is 8e6 (Hz) 
Ndown=2;    % downsampling rate is 2e6 (Hz) 
Nsym=6; 
 
%modulation 
mod_order=4;    % modulation is QAM4 
 
%LDPC parameter 
load ldpc_80216e_66r3_r12 
z=96; 
zmax=96; 
H1=ldpc_genHbm_3gpp(ldpc_80216e,zmax,z); 
H=ldpc_genH_3gpp(H1,z); 
[Nrow,Ncol]=size(H); 
 
Ncode=1; 
Nslot=1; 
 
%control parameter 
interflag=0; 
snr=[11,10,9,8,7];  
fdm=300; 
trial=1e4;  
 
%define profile 
profile.sys='80216e'; 
profile.num=4; 
profile.n=1; 
profile.link='downlink'; 
 
%subchannel definition 
tone_st=(Nbs-128*5)/2; 
% for j=1:Nsub, 
%     sc_tone_ind{j}=j:Nsub:Ncarr; 
% end; 
 
tic; 
for sn=1:length(snr) 
    disp(['snr=',num2str(snr(sn))]); 
    bercount=0; 
    percount=0;   
    count=0; 
         
    soubit=zeros(1,trial*(Ncol-Nrow)*Ncode); 
    decbit=zeros(1,trial*(Ncol-Nrow)*Ncode); 
    for tr=1:trial 
        %Source information bits and LDPC encoding 
        scode=zeros(1,(Ncol-Nrow)*Ncode); 
        ccode=zeros(1,Ncol*Ncode); 
        for i=1:Ncode 
            tmp=randint(1,Ncol-Nrow); 
            scode((i-1)*(Ncol-Nrow)+1:i*(Ncol-Nrow))=tmp; 
            if interflag==0 
                ccode((i-1)*Ncol+1:i*Ncol)=ldpc_encode_80216e(tmp',H1,z); 
            else 
                ccode((i-1)*Ncol+1:i*Ncol)=block_interleaver(ldpc_encode_80216e(tmp',H1,z),32); 
            end 
        end 
        soubit((trial-1)*(Ncol-Nrow)*Ncode+1:trial*(Ncol-Nrow)*Ncode)=scode; 
         
        % build time slot 
        demod=zeros(1,length(ccode)); 
        ssym=reshape(ccode,log2(mod_order),length(ccode)/log2(mod_order))'; 
        ssym=bi2de(ssym,'left-msb');                  
%         ssym=reshape(ssym,profile.num*8,size(ssym,1)*size(ssym,2)/profile.num/8); 
        for j=1:Nslot 
%             x=zeros(Ncarr,Nsym+2); 
%             xp=zeros(Ncarr,Nsym+2);         
            sp=exp(sqrt(-1)*2*pi*rand(1,profile.num*48*Nsym));   % pilot, power is equal to traffic power 
            tmp=qammod4(ssym); 
             
            x=mapping(tmp,sp(1:Nsym*profile.num*42),profile); 
            yp=mapping(sp,sp(1:Nsym*profile.num*42),profile); 
%             x=arrange(tmp,[sp(:,2),sp(:,7)]); 
%             xp(1:Ncarr,:)=sp; 
 
%             y=zeros(Nbs,Nsym+2); 
%             yp=zeros(Nbs,Nsym+2); 
%             for k=1:length(subindex) 
%                 y(tone_st+(subindex(k)*8+1:(subindex(k)+1)*8),:)=x((k-1)*8+1:k*8,:); 
%                 yp(tone_st+(subindex(k)*8+1:(subindex(k)+1)*8),:)=sp((k-1)*8+1:k*8,:); 
%             end 
             
            for k=45:469 
                if x(k,:)==0 
                    x(k,:)=exp(sqrt(-1)*2*pi*rand(1,Nsym)); 
                end 
            end 
            y=x; 
 
            %ifft, add prefix and postfix 
            yt=ifft(ifftshift(y,1))*sqrt(Nbs)*sqrt(Nup); 
            yt=[yt(end-Npref*Nup+1:end,:); yt; yt(1:Npostf*Nup,:)]; 
            yt=yt(:).'; 
            ypt=ifft(ifftshift(yp,1))*sqrt(Nbs)*sqrt(Nup); 
            ypt=[ypt(end-Npref*Nup+1:end,:); ypt; ypt(1:Npostf*Nup,:)]; 
            ypt=ypt(:).'; 
 
            %fading channel 
%             rx=fading_doppler_channel_80216e(yt, 'itu', '3A', [num2str(fdm),'Hz'], Nup, Ndown, (tr-1)*Nslot+j); 
%             rxp=fading_doppler_channel_80216e(ypt, 'itu', '3A', [num2str(fdm),'Hz'], Nup, Ndown, (tr-1)*Nslot+j); 
 
            %awgn channel 
            rx=awgn(yt, snr(sn), 10*log10(Ndown)); 
            rxp=ypt; 
 
            %receiver 
            %delete prefix and postfix 
            zt=reshape(rx,Nbs*Ndown/Nup+(Npref+Npostf)*Ndown,Nsym); 
            zt(1:Npref*Ndown,:)=[]; zt(end-Npostf*Ndown+1:end,:)=[]; 
            zpt=reshape(rxp,Nbs*Ndown/Nup+(Npref+Npostf)*Ndown,Nsym); 
            zpt(1:Npref*Ndown,:)=[]; zpt(end-Npostf*Ndown+1:end,:)=[]; 
 
            %fft 
            zf=fftshift(fft(zt)/sqrt(Nbs*Ndown/Nup)/sqrt(Ndown),1); 
            zpf=fftshift(fft(zpt)/sqrt(Nbs*Ndown/Nup)/sqrt(Ndown),1); 
 
            %channel estimation             
            [zef,zpef1]=demapping(zf,profile); 
            [zpef,zpef1]=demapping(zpf,profile); 
            zpef=zpef./sp(:); 
            test=zef./zpef; 
             
            % demodulation 
            sd=qamdemod4soft_h(zef,zpef,10^(-snr(sn)/10)); 
            demod=sd; 
        end 
         
        %LDPC decoding 
        dec=zeros(1,(Ncol-Nrow)*Ncode); 
        for i=1:Ncode 
            if interflag==0 
                tmp=demod((i-1)*Ncol+1:i*Ncol); 
            else 
                tmp=block_deinterleaver(demod((i-1)*Ncol+1:i*Ncol),32); 
            end 
            [zz,succ,kk]=ldpc_decode(tmp,H,2);%kk 
            dec((i-1)*(Ncol-Nrow)+1:i*(Ncol-Nrow))=zz(1:(Ncol-Nrow)); 
            if succ~=1 
                count=count+1; 
            end 
        end 
        clear tmp 
        decbit((trial-1)*(Ncol-Nrow)*Ncode+1:trial*(Ncol-Nrow)*Ncode)=dec; 
 
        %Error calculate 
        bererr=dec-scode; 
        bercount=bercount+length(find(bererr)); 
         
        bererr=reshape(bererr,Ncol-Nrow,Ncode); 
        for i=1:Ncode 
            if length(find(bererr(:,i))) 
                percount=percount+1; 
            end 
        end 
    end 
    ber(sn)=bercount/(trial*Ncode*(Ncol-Nrow)) 
    bler(sn)=percount/(trial*Ncode) 
     
%     eval(['save f:\liuyu\simdata\ldpc\fdm',num2str(fdm),'snr',num2str(snr(sn)),'mod',num2str(mod_order),'Nc',num2str(Nc),'.mat ber bler soubit decbit']); 
     
    clear soubit;clear decbit; 
end 
toc