%BER of QPSK Modulation in AWGN Channel
clear all;
close all;
clc;
N = 1000000; % number of symbols
x0 = randn(1,N)>0.5;% generates 0,1 with equal probability
x = (2*x0-1)+ 1i*(2*x0-1);%generating qpsk signals
s0 = (1/sqrt(2))*x;%normalizing
EbN0indB = [0:12];%Eb/N0 value
Ebnolin=10.^(EbN0indB/10);
for i = 1:length(EbN0indB)
No=1/Ebnolin(i);
n= sqrt(No)*[1/sqrt(2)]*[ randn(1,N) + 1i*randn(1,N)];%AWGN noise
y0= s0 + n;%addition of noise at receiver
y_re= real(y0);%real part
y_im= imag(y0);%imaginary part
%assigning values after comparing
x1(find(y_re <0 & y_im <0)) = (-1) + (-1)*1i;
x1(find(y_re >=0 & y_im >=0)) = 1 + 1*1i;
x1(find(y_re <0 & y_im >=0)) = -1 + 1*1i;
x1(find(y_re >=0 & y_im <0)) = 1 + -1*1i;
error(1,i)= size(find(x-x1),2);%no of errors
end
BER = error/N;%simulated error
theoryBer = erfc(sqrt(0.5*(10.^(EbN0indB/10))))...
- (1/4)*(erfc(sqrt(0.5*(10.^(EbN0indB/10))))).^2;%theoritical error
semilogy(EbN0indB, theoryBer, 'b.-');
hold on
semilogy(EbN0indB,BER,'-r','LineWidth',2);
axis([0 10 10^-5 0.5]);
grid on;
legend('theory', 'simulation');
xlabel( 'Eb/N0, dB');
ylabel('BER');
title('Bit error probability curve for QPSK modulation');