Anda di halaman 1dari 3

BER V/S SNR PLOT FOR BPSK AND QPSK

Matlab code

%This program simulates BER of BPSK and QPSK in AWGN channel%

clear all; close all; clc;

num_bit=10000; %Signal length

max_run=10; %Maximum number of iterations for a single SNR

Eb=1; %signal power

SNRdB=0:1:20; %Signal to Noise Ratio (in dB)

SNR=10.^(SNRdB/10);

for count=1:length(SNR) %Beginning of loop for different SNR

totalError=0;

totalError1=0;

No=Eb/SNR(count); %Calculate noise power from SNR

for run_time=1:max_run %Beginning of loop for different runs

Error=0;
Error1=0;

data=randint(1,num_bit); %Generate binary data source

%------Baseband BPSK modulation------

s=2*data-1;

%------Baseband QPSK modulation-------

data1=reshape(data,num_bit/2,2);

data1=2*data1-1;

s1 = (data1(:,1) + j*data1(:,2))/sqrt(2);

N=sqrt(No/2)*[randn(1,num_bit)+j*randn(1,num_bit)]; %Generate WGN for BPSK

N1=sqrt(No/2)*[randn(num_bit/2,1)+j*randn(num_bit/2,1)]; %Generate WGN for QPSK

Y=s+N; %Received Signal

Y1=s1+N1;

Y=real(Y);

%Decision device taking hard decision and deciding error

for k=1:num_bit

if ((Y(k)>0 && data(k)==0)||(Y(k)<0 && data(k)==1))

Error=Error+1;

end

end

Error=Error/num_bit; %Calculate error/bit

totalError=totalError+Error; %Calculate total error/bit for different runs

%-----decision device for QPSk------

for k=1:num_bit/2

if((data1(k,1)==0 && real(Y1(k))>0)||(data1(k,2)==0 && imag(Y1(k))>0)||(data1(k,1)==1 &&


real(Y1(k))<0)||(data1(k,2)==1 && imag(Y1(k))<0))

Error1=Error1+1;

end
end

Error1=2*Error1/num_bit;

totalError1=totalError1+Error1;

end %Termination of loop for different runs

avgError1=totalError1/max_run;

BER_sim1(count)=avgError1;

avgError=totalError/max_run; %calculate average error over total no of runs

BER_sim(count)=avgError; %Calculate BER for a particular SNR

end %Termination of loop for different SNR

BER_th1=.5*erfc(sqrt(SNR/2));

BER_th=.5*erfc(sqrt(SNR)); %Calculate analytical BER

semilogy(SNRdB,BER_th1,'g',SNRdB,BER_sim1,'g*',SNRdB,BER_th,'k',SNRdB,BER_sim,'k*');

legend('Theoretical','Simulation',3);

axis([min(SNRdB) max(SNRdB) 10^(-5) 1]);

Anda mungkin juga menyukai