www.gusucode.com > 实现不同收发天线数,不同调制方式下的误比特率测量matlab源码程序 > MIMO程序/stbc22_est.m
function [FER,FER_uncoded,SER,SER_uncoded, BER, BER_uncoded]=stbc22_est(channel_model,K,Num,no_tx_antennas,no_rx_antennas,modulation) %SNR upto 20 dBs EbNo=[0:2:20]; %N, M: number of transmit and receive antennas N=no_tx_antennas; M=no_rx_antennas; %initialize count idx = 1; h=waitbar(0,'Percentage Completed'); set(h,'Position',[230 60 275.25 56.25]); set(h,'name','Please wait...'); wb=9.09; for SNR=EbNo sigma=0.5/(10^(SNR/10)); % Num -> number of packets for packet_count=1:Num % we are interested in transmitting 'K' SYMBOLS not bits. Hence, K*2 for QPSK % etc. switch (modulation) case 'BPSK ' data=randint(K,N); BIT=1; case 'QPSK ' data=randint(K*2,N); BIT=2; case '8PSK ' data=randint(K*3,N); BIT=3; case '16QAM' data=randint(K*4,N); BIT=4; otherwise disp('No Modulation') end tx_bits=data.'; temp=[]; temp1=[]; for i=1:N [temp1 s P]=tx_modulate(tx_bits(i,:),modulation); temp=[temp; temp1]; temp1=0; end %ready to transmit symbols of length 'K' X=temp.'; fr_length=length(X); % block coding-Alamouti x0=X(:,1);% required to verify a 1x1 system x1=X; x2(:,1)=-conj(X(:,2)); x2(:,2)=conj(X(:,1)); for n=1:M R1=[]; R2=[]; R3=[]; y1=[]; %configure pilot 1 for one antenna pilot1=[0 0 0 0 0 0 0 0 0 0 1 -1 -1 1 -1 -1 1 -1 1 1]; %extend the pilot symbols for full frame length pilots1=(repmat(pilot1,fr_length,1)); %append the pilot1 symbols to the first antenna symbol X1=[pilots1 x1(:,1)]; %configure pilot 2 for the second antenna. Pilot 2 is orthogonal to pilot 1 pilot2=[1 -1 -1 -1 1 -1 -1 1 -1 1 0 0 0 0 0 0 0 0 0 0]; %extend the pilot symbols for full frame length pilots2=(repmat(pilot2,fr_length,1)); %append the pilot2 symbols to the second antenna symbol X2=[pilots2 x1(:,2)]; %assign the symbols to be transmitted to variable y1 instead of x1. y1 is %the signal transmitted in the first interval period from BOTH the antennas y1=[X1 X2]; % transmit through channel for i=1:fr_length %channel coefficient for first antenna if channel_model=='AWGN ' H1(i)=ones(1,1); else H1(i)=sqrt(0.5)*(randn(1,1)+j*randn(1,1)); end %received signal per receiver antenna R1(i,:)=H1(i)*y1(i,1:21)/sqrt(N)+sqrt(sigma)*(randn(1,1)+j*randn(1,1));% upto 21st column constitutes the transmission in the %first symbol interval from the FIRST antenna %i R2(i,1)=H1(i)*x2(i,1)/sqrt(N)+sqrt(sigma)*(randn(1,1)+j*randn(1,1));%transmission in the second symbol interval from the FIRST %antenna.Note no pilot symbols are being transmitted as the assumption is that the channel does %not change through two symbol intervals end for i=1:fr_length %channel coefficient for second antenna if channel_model=='AWGN ' H2(i)=ones(1,1); else H2(i)=sqrt(0.5)*(randn(1,1)+j*randn(1,1)); end %received signal per receiver antenna R3(i,:)=H2(i)*y1(i,22:end)/sqrt(N)+sqrt(sigma)*(randn(1,1)+j*randn(1,1));% column 22 till 42nd constitutes the transmission % in the first symbol interval from the SECOND antenna R2(i,2)=H2(i)*x2(i,2)/sqrt(N)+sqrt(sigma)*(randn(1,1)+j*randn(1,1));%transmission in the second symbol interval from the SECOND %antenna.Note no pilot symbols are being transmitted as %the assumption is that the channel does %not change through two symbol intervals end %gather the R1 matrix for transmission during the first symbol interval R1=[R1 R3]; %extract the training symbols tr_symbols1=R1(:,1:20); tr_symbols2=R1(:,22:41); %reconfigure the received signal matrix for first symbol interval from BOTH %the antennas temp1=[R1(:,21) R1(:,42)]; %assign to r1 and r2. The 'sum' function denotes summing at the outputs of %BOTH antennas r1(:,n)=sum(temp1,2); r2(:,n)=sum(R2,2); %estimate channel using MMSE for i=1:fr_length H_est1(i,1)=mean(tr_symbols1(i,:).*conj(pilot1)); end for i=1:fr_length H_est2(i,1)=mean(tr_symbols2(i,:).*conj(pilot2)); end %final estimated channel coefficients to be used for reception H_est=[H_est1 H_est2]; %original (perfect) channel coefficients used to transmit the signals H=[H1.' H2.']; %absolute ESTIMATED channel coefficients to be used later in this program H_estabs(:,n)=sum(abs(H_est).^2,2); % demodulate the received signals z1(:,n)=r1(:,n).*conj(H_est(:,1))+conj(r2(:,n)).*H_est(:,2); z2(:,n)=r1(:,n).*conj(H_est(:,2))-conj(r2(:,n)).*H_est(:,1); end %uncoded(1,1)TRANSMITTED signal. Note we use original channel coefficients, since this is the transmitted signal r01=H(:,1).*x0+sqrt(sigma)*(randn(fr_length,1)+j*randn(fr_length,1)); %form estimates for m=1:P d01(:,m)=abs(r01-H_est(:,1)*s(m)).^2; % uncoded signal %coded signals d1(:,m)=abs(sum(z1,2)-s(m)).^2+(-1+sum(H_estabs,2))*abs(s(m))^2; d2(:,m)=abs(sum(z2,2)-s(m)).^2+(-1+sum(H_estabs,2))*abs(s(m))^2; end % determine the minimum of estimates %decision for detecting uncoded [y0,i0]=min((d01),[],2); s0d=s(i0).'; clear d01 %decision for detecting s1 [y1,i1]=min(d1,[],2); s1d=s(i1).'; clear d1 %decision for detecting s2 [y2,i2]=min(d2,[],2); s2d=s(i2).'; clear d2 % form received symbols Xd=[s1d s2d]; %determine symbol errors error_un(packet_count)=sum(X(:,1)~=s0d);% for uncoded temp1=X>0; temp2=Xd>0; error(packet_count)=sum(sum(temp1~=temp2));% for coded end % end of FOR loop for "packet_count" %calculate FER, SER and BER for current idx %for uncoded signal SER_uncoded(idx)=sum(error_un)/(Num*K); BER_uncoded(idx)=SER_uncoded(idx)/BIT; FER_uncoded(idx)=SER_uncoded(idx)*K; %for coded signal SER(idx)=sum(error)/(Num*K); BER(idx)=SER(idx)/BIT; FER(idx)=SER(idx)*K; %increment idx idx=idx + 1; str_bar=[num2str(wb) '% Completed']; waitbar(wb/100,h,str_bar); wb=wb+9.09; end % end of FOR loop for SNR close(h);