www.gusucode.com > 实现不同收发天线数,不同调制方式下的误比特率测量matlab源码程序 > MIMO程序/stbc14.m
function [FER,FER_uncoded,SER,SER_uncoded, BER, BER_uncoded]=stbc14(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 s P]=tx_modulate(tx_bits,modulation); %ready to transmit symbols of length 'K' X=temp.'; fr_length=length(X); % MRC x0=X; % form the channel matrix if channel_model=='AWGN ' Hr=ones(fr_length,M); else Hr=(randn(fr_length,M)+j*randn(fr_length,M))/sqrt(2); end %transmission matrix H=reshape(Hr,fr_length,M); Habs=sum(abs(H).^2,2); %received signal per receiver antenna r1=sum(H(:,1).*x0,2)/sqrt(N)+sqrt(sigma)*(randn(fr_length,1)+j*randn(fr_length,1)); r2=sum(H(:,2).*x0,2)/sqrt(N)+sqrt(sigma)*(randn(fr_length,1)+j*randn(fr_length,1)); r3=sum(H(:,3).*x0,2)/sqrt(N)+sqrt(sigma)*(randn(fr_length,1)+j*randn(fr_length,1)); r4=sum(H(:,4).*x0,2)/sqrt(N)+sqrt(sigma)*(randn(fr_length,1)+j*randn(fr_length,1)); % demodulate the received signals z1=r1.*conj(H(:,1))+r2.*conj(H(:,2))+r3.*conj(H(:,3))+r4.*conj(H(:,4)); %uncoded(1,1) 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(:,1)*s(m)).^2; %uncoded signal %coded signal d1(:,m)=abs(sum(z1,2)-s(m)).^2+(-1+sum(Habs,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 % form received symbols Xd=[s1d]; %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);