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


%function mcwill_turbo_ideal() 
clear 
close all 
 
%***** system configuration *****  
System.Bw=5e6; 
System.Fs=8e6; 
System.Nfft=1024; 
System.Nused=640; 
System.NcarGroup=5; 
System.Ncar=128; 
System.Nsubchan=16; 
 
%***** vector channel model ***** 
VectChan.M=8; 
VectChan.BtsAngleSpread=50; 
VectChan.ArrayGeometry='linear'; 
VectChan.AntSpace=0.5; 
 
%***** subchannel to subcarrier mapping ***** 
SubChanFormat.Nf=8; 
SubChanFormat.Nt=8; 
SubChanFormat.Pilot=[1:SubChanFormat.Nt 1:SubChanFormat.Nt; ones(1,SubChanFormat.Nf)*2 ones(1,SubChanFormat.Nf)*7]; 
for i=0:System.NcarGroup-1, 
    for j=0:System.Nsubchan-1, 
        SubChanToCar{i+1,j+1}=i*System.Ncar+j:System.Nsubchan:(i+1)*System.Ncar-1; 
    end; 
end; 
 
%***** subchannel allocation ***** 
Allocation.CarGroupSch=[1 2 2 3 4 5 ; ...   %subcarrier group index 
                        1 2 3 4 2 6];       %subchannel index  
 
%SymIn=1:288;                     
%x=SubChanMap(SymIn,Allocation,System,SubChanFormat,SubChanToCar); 
 
loops=10000; 
m=2; %modulation order, QAM4,m=2 
fdHz=[20 300 200 100]; 
%load_factor=[6]; 
%load W; 
SNRindB=[10:2:120]; 
%SNRindB=10; 
prefix_length=4; 
postfix_length=1.5; 
up_length=2; 
down_length=2; 
Nc=1024;%No. of  subcarrier 
Ns=2;%Over sampling rate 
Ns_r=2;%receiver over sampling rate 
packet_length=288; 
pilot_bits=randint(1,2*packet_length,2,211); 
pilot_sym=modulator(pilot_bits,2); 
dec_alg=0; 
niter=8; 
rate = 1/2; 
[P0,P1,P2,P3,M,J]=CTC_profile(packet_length/8); 
alpha=CTC_interleaver(packet_length/2,P0,P1,P2,P3); 
profile.sys='mcwill'; 
profile.link='downlink'; 
profile.n=1; 
profile.num=6; 
data_in_sym=zeros(1024,8); 
pilot_in_sym=zeros(1024,8); 
for fd=1:length(fdHz), 
    disp(['fd:' num2str(fdHz(fd))]); 
    for s=1:length(SNRindB); 
        disp(['SNR:' num2str(SNRindB(s))]); 
        % sigma = sqrt(10^(-SNRindB(s)/10)/(2*rate*2)); 	% standard deviation of AWGN noise 
        sigma2=10^(-SNRindB(s)/10)/(2*rate*2); 
        errcount=0; 
        packet_err_count=0; 
        packet_err_count_rs=0; 
        packet_count=0; 
        buffer_count=0; 
        for l=1:loops 
 
            msg_bits = round(rand(1, packet_length));    % info. bits 
            [bits_coded,final_state1,final_state2] = CTC_encoder( msg_bits,alpha,M,J); 
            load_bits= block_interleaver(bits_coded,1); 
            %load_bits=bits_coded; 
            load_sym=modulator(load_bits,2); 
             
            %load symbols according to mapping rule 
            %data_in_sym=mapping(load_sym,zeros(1,16*6),profile); 
            %pilot_in_sym=mapping(pilot_sym,zeros(1,16*6),profile); 
            %****** 
            [data_in_sym,SchAlloc]=SubChanMap(load_sym,Allocation,System,SubChanFormat,SubChanToCar); 
            pilot_in_sym=SubChanMap(pilot_sym,Allocation,System,SubChanFormat,SubChanToCar); 
             
            for n=1:8 
                [data_ofdm(n,:)]=build_ofdm_sym(data_in_sym(:,n).',Nc,Ns,prefix_length,postfix_length,up_length,down_length); 
                [pilot_ofdm(n,:)]=build_ofdm_sym(pilot_in_sym(:,n).',Nc,Ns,prefix_length,postfix_length,up_length,down_length); 
            end 
 
            %To form frame 
            data_ofdm_t=[data_ofdm(1,:),data_ofdm(2,:),data_ofdm(3,:),data_ofdm(4,:),data_ofdm(5,:),data_ofdm(6,:),data_ofdm(7,:),data_ofdm(8,:)]; 
            pilot_ofdm_t=[pilot_ofdm(1,:),pilot_ofdm(2,:),pilot_ofdm(3,:),pilot_ofdm(4,:),pilot_ofdm(5,:),pilot_ofdm(6,:),pilot_ofdm(7,:),pilot_ofdm(8,:)]; 
 
            % ***** Pass vector fading doppler channel ***** 
            [vect_data_fading]=vector_fading_doppler_channel(data_ofdm_t,'itu','3A',VectChan,[num2str(fdHz(fd)),'Hz'],Ns,Ns_r,l); 
            [vect_pilot_fading]=vector_fading_doppler_channel(pilot_ofdm_t,'itu','3A',VectChan,[num2str(fdHz(fd)),'Hz'],Ns,Ns_r,l); 
 
            %Pass awgn channel per antenna 
            for m=1:VectChan.M, 
                vect_data_awgn{m}=awgn(vect_data_fading{m},SNRindB(s),10*log10(Ns_r),l)/(Ns_r*sqrt(Nc)); 
                vect_pilot_fading{m}=vect_pilot_fading{m}/(Ns_r*sqrt(Nc)); 
            end; 
            %sigma2=var(data_fading-data_awgn); 
 
            %Weight Estimation 
            for m=1:VectChan.M, 
                for n=1:8, 
                    [pilot_ofdm_r]=extract_ofdm_sym_index(vect_pilot_fading{m},n,8,Ns_r,up_length,prefix_length,Nc,postfix_length,down_length); 
                    pilot_sym_tmp=fft(pilot_ofdm_r); 
                    vect_pilot_sym_r{m}(:,n)=pilot_sym_tmp(1:Nc).'; 
                end; 
            end;             
            bfw=UplinkWeight(vect_pilot_sym_r,pilot_in_sym,System,Allocation,VectChan,SubChanFormat,SubChanToCar); 
 
            %%% uplink beamforming 
            for m=1:VectChan.M, 
                for n=1:1:8, 
                    [data_ofdm_r]=extract_ofdm_sym_index(vect_data_awgn{m},n,8, Ns_r,up_length,prefix_length,Nc,postfix_length,down_length); 
                    data_sym_tmp=fft(data_ofdm_r); 
                    vect_data_sym_r{m}(:,n)=data_sym_tmp(1:Nc).'; 
                end; 
            end; 
            BfDataSym=UplinkBeamform(vect_data_sym_r,bfw,System,Allocation,VectChan,SubChanFormat,SubChanToCar); 
            BfPilotSym=UplinkBeamform(vect_pilot_sym_r,bfw,System,Allocation,VectChan,SubChanFormat,SubChanToCar); 
             
            %%**** Coded Symbol stream can be recovered using SchAlloc AND SubChanFormat **** 
            CodeSym=DeSubChanMap(BfDataSym,SchAlloc,SubChanFormat,SubChanToCar); 
             
            keyboard 
             
             
             
             
 
            %Channel Estimation 
            for n=1:8 
                [pilot_ofdm_r]=extract_ofdm_sym_index(pilot_fading,n,8,Ns_r,up_length,prefix_length,Nc,postfix_length,down_length); 
                pilot_sym_tmp=fft(pilot_ofdm_r); 
                pilot_sym_r(:,n)=pilot_sym_tmp(1:Nc).'; 
            end 
            [H,pilot]=demapping(pilot_sym_r,profile); 
            HH=H.'./pilot_sym; 
            % Receiver algorithm 
            load_bits_tmp=[]; 
            %Detect sym1,sym3 
            for n=1:1:8 
                [data_ofdm_r]=extract_ofdm_sym_index(data_awgn,n,8, Ns_r,up_length,prefix_length,Nc,postfix_length,down_length); 
                data_sym_tmp=fft(data_ofdm_r); 
                data_sym_r(:,n)=data_sym_tmp(1:Nc).'; 
            end 
            [subchannel_sym,pilot]=demapping(data_sym_r,profile); 
 
 
 
            [load_bits_r,hard_out_bin]=DeQAM4_soft(subchannel_sym, HH,sigma2); 
            % BER statistic 
            load_bits_r= block_deinterleaver(load_bits_r,1); 
            %[msg_dec_bits]=turbo_decoder(load_bits_r,g,alpha,puncture,dec_alg,niter); 
            [msg_dec_bits]=CTC_decoder(load_bits_r,alpha,dec_alg,niter,M,J,final_state1,final_state2); 
            biterr_cout=biterr(msg_bits,msg_dec_bits); 
            errcount=errcount+biterr_cout; 
            packet_count=packet_count+1; 
            [perr]=packet_err(msg_bits,msg_dec_bits); 
            if (perr==1) 
                packet_err_count=packet_err_count+1; 
            end 
            % toc 
        end%l 
        biterr_rate(fd,s)=errcount/(loops*length(msg_bits)); 
        perr_rate(fd,s)=packet_err_count/packet_count; 
        %perr_rate_rs(fd,s)=packet_err_count_rs/packet_count; 
        %disp(['BER:' num2str(biterr_rate(i))]); 
        save mcwill_turbo_logmap_p288_ideal_ber_per; 
    end%snr 
end%fd