www.pudn.com > ldpc802.16.rar > transceiver_ldpc_comp_mcwill_spreading.m, change:2005-11-03,size:7490b


%tranceiver 
close all; 
clear all; 
 
seed=randint(1,1,10000); 
% seed=89438; 
rand('state',seed); 
randn('state',seed); 
 
Nbs=1024; 
Npref=6;    % ofdm prefix is 6e-6 (s) 
Npostf=3.5;     % ofdm postfix is 3.5e-6 (s) 
 
Ncarr=48;  % subcarrier number 
Nsub=16;   %number of subchannels in each carrier group 
 
N=8;    % full loading factor 
Nc=8;   % loading factor 
Nsym=6;     % symbol length in one time slot 
 
Nup=8;  % oversampling rate is 8e6 (Hz) 
Ndown=8;    % downsampling rate is 2e6 (Hz) 
 
%modulation 
mod_order=4;    % modulation is QAM4 
W1=hadamard(N)/sqrt(N);  % spreading matrix 
 
%LDPC parameter 
load ldpc_80216e_66r3_r12 
z=48; 
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 
ploc1=2;ploc2=7; 
subchannel=[0	2	4	6	8	10	12	14	16	17	18	19	20	21	22	23	24	25	26	27	28	29	30	31	32	33	34	35	36	... 
    37    38	39	40	41	42	43	44	45	46	47	48	49	50	51	52	53	54	55	56	57	58	59	60	61	62	63	64	65	66	... 
    67	68	69	70	71	72	73	74	75	76	77	78	79]; 
 
subindex=subchannel(1:72/12:end); 
 
interflag=0; 
snr=[11,10,9,8,7];  
fdm=300; 
trial=1e4;  
 
%subchannel definition 
tone_st=(Nbs-128*5)/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) 
    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,length(subindex)*8,size(ssym,1)*size(ssym,2)/length(subindex)/8); 
        for j=1:Nslot 
%             x=zeros(Ncarr,Nsym+2); 
%             xp=zeros(Ncarr,Nsym+2);         
            sp=exp(sqrt(-1)*2*pi*rand(length(subindex)*8,Nsym+2))*sqrt(Nc/N);   % pilot, power is equal to traffic power 
            tmp=qammod4(ssym(:,(j-1)*Nsym+1:j*Nsym)); 
             
            % spreading 
            tmp=reshape(tmp,Nc,size(tmp,1)*size(tmp,2)/Nc); 
            for i=1:size(tmp,2) 
                tmp(:,i)=W*tmp(:,i); 
            end 
            tmp=reshape(tmp,length(subindex)*8,size(tmp,1)*size(tmp,2)/length(subindex)/8); 
 
            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=tone_st+(1:128*5) 
                if y(k,:)==0 
                    y(k,:)=exp(sqrt(-1)*2*pi*rand(1,Nsym+2))*sqrt(Nc/N); 
                end 
            end 
 
            %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(yt, 'itu', '3A', [num2str(fdm),'Hz'], Nup, Ndown, (tr-1)*Nslot+j); 
            rxp=fading_doppler_channel(ypt, 'itu', '3A', [num2str(fdm),'Hz'], Nup, Ndown, (tr-1)*Nslot+j); 
 
            %awgn channel 
            rx=awgn(rx, snr(sn), 10*log10(Ndown)); 
            rxp=rxp; 
 
            %receiver 
            %delete prefix and postfix 
            zt=reshape(rx,Nbs*Ndown/Nup+(Npref+Npostf)*Ndown,Nsym+2); 
            zt(1:Npref*Ndown,:)=[]; zt(end-Npostf*Ndown+1:end,:)=[]; 
            zpt=reshape(rxp,Nbs*Ndown/Nup+(Npref+Npostf)*Ndown,Nsym+2); 
            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 
            for k=1:length(subindex) 
                zpef1((k-1)*8+1:k*8,:)=zpf(tone_st+(subindex(k)*8+1:(subindex(k)+1)*8),:); 
                zef1((k-1)*8+1:k*8,:)=zf(tone_st+(subindex(k)*8+1:(subindex(k)+1)*8),:); 
            end 
            zpef=dearrange(zpef1); 
            zpef=zpef./dearrange(sp);             
            zpef=zpef(:); 
            zef=dearrange(zef1);         
            zef=zef(:); 
             
            % mmse detection and demodulation 
            zpef=reshape(zpef,8,length(zpef)/8); 
            zef=reshape(zef,8,length(zef)/8); 
            zef2=zeros(size(zef)); 
            demod=zeros(size(ccode)); 
            for k=1:size(zef,2) 
                H2=diag(zpef(:,k))*W; 
                 
                % mmse detection 
                A=inv(H2'*H2+10^(-snr(sn)/10)*eye(Nc))*H2'; 
                zef2(:,k)=A*zef(:,k); 
                 
                % demodulation 
                B=A*H2; 
                for i=1:size(B,1) 
                    a=A(i,:); 
                    b=B(i,:);b(i)=0; 
                    sigma2=sum(abs(a).^2)*10^(-snr(sn)/10)+sum(abs(b).^2); 
                    demod((j-1)*size(zef2,2)*size(zef2,1)*log2(mod_order)+(k-1)*size(zef2,1)*log2(mod_order)+i*log2(mod_order)-1:(j-1)*size(zef2,2)*size(zef2,1)*log2(mod_order)+(k-1)*size(zef2,1)*log2(mod_order)+i*log2(mod_order))=qamdemod4soft_mmse(zef2(i,k),abs(B(i,i)),sigma2); 
                end 
            end 
        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