Name: Muhammad Shahab Reg#no: 16bnele0772 Assignment: 02 Submitted To: Engr Fawad Assignment Title: QPSK and QAM16 Implementation in Matlab

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Name : Muhammad Shahab

Reg#no : 16bnele0772
Assignment : 02
Submitted to : Engr Fawad
Assignment Title :
QPSK and QAM16 implementation in matlab
Fowlling Steps
 First generate Random bits and
Convert bits into QPSK symbols
 Then generate QPSK waveform by means of
modulation.
 Then add AWGN noise to QPSK waveform and transmit the resulted QPSK
signal to the other station
 And demodulate the received signal to recover
original bits then calculate the Bit Error
Rate(BER)
 At last Plot waterfall curve for BER vs
Eb/No.
Same procedure should apply for QAM-16 modulation.

1-Matlab code of QPSK for a given task.


clear all; %Clear all
close all; %Close all
l=1e6;
EbNodB=0:2:10;
EbNo=10.^(EbNodB/10);
for n=1:length(EbNodB)
si=2*(round(rand(1,l))-0.5);
sq=2*(round(rand(1,l))-0.5);
s=si+j*sq; %Adding both
w=(1/sqrt(2*EbNo(n)))*(randn(1,l)+j*randn(1,l));
r=s+w; %Received signal
si_=sign(real(r));
sq_=sign(imag(r));
ber1=(l-sum(si==si_))/l;
ber2=(l-sum(sq==sq_))/l;
ber(n)=mean([ber1 ber2]);
end
semilogy(EbNodB, ber,'o-') %Plot
xlabel('EbNo(dB)') %Label for x-axis
ylabel('BER') %Label for y-axis
grid on %Turning the grid on
Plot curve for BER vs Eb/No.

Curve explanation:

In this program calculate the Bit Error Rate (BER) of QPSK in an Additive
White Gaussian Noise (AWGN) channel.
This modulation and demodulation is done at baseband. The (BER) curve illustrates the
relationship between power in the transmitted signal in terms of signal to noise ratio (SNR) and
the resulting BER for the system.
2-Matlab code of 16-QAM for a given task.
clear all;
close all;
N = 2*10^5; % number of symbols
alpha16qam = [-3 -1 1 3]; % 16-QAM alphabets
Es_N0_dB = [0:20];
ipHat = zeros(1,N);
for ii = 1:length(Es_N0_dB)
ip = randsrc(1,N,alpha16qam) + j*randsrc(1,N,alpha16qam);
s = (1/sqrt(10))*ip;
n = 1/sqrt(2)*[randn(1,N) + j*randn(1,N)];
y = s + 10^(-Es_N0_dB(ii)/20)*n;
y_re = real(y);
y_im = imag(y);
ipHat_re(find(y_re< -2/sqrt(10))) = -3;
ipHat_re(find(y_re > 2/sqrt(10))) = 3;
ipHat_re(find(y_re>-2/sqrt(10) & y_re<=0)) = -1;
ipHat_re(find(y_re>0 & y_re<=2/sqrt(10))) = 1;
ipHat_im(find(y_im< -2/sqrt(10))) = -3;
ipHat_im(find(y_im > 2/sqrt(10))) = 3;
ipHat_im(find(y_im>-2/sqrt(10) & y_im<=0)) = -1;
ipHat_im(find(y_im>0 & y_im<=2/sqrt(10))) = 1;
ipHat = ipHat_re + j*ipHat_im;
nErr(ii) = size(find([ip- ipHat]),2); % couting the number of errors
end
simBer = nErr/N;
theoryBer = 3/2*erfc(sqrt(0.1*(10.^(Es_N0_dB/10))));
close all
figure
semilogy(Es_N0_dB,theoryBer,'b.-','LineWidth',2);
hold on
semilogy(Es_N0_dB,simBer,'mx-','Linewidth',2);
axis([0 20 10^-5 1])
grid on
legend('theory', 'simulation');
xlabel('Es/No, dB')
ylabel('Symbol Error Rate')
title('Symbol error probability curve for 16-QAM modulation')
Plot waterfall curve for BER vs Eb/No.

Curve Explanation:
To assess the performance of a higher order modulation system is to measure
the (SER) or (BER) over a range of background noise (loading) conditions.
Applying (AWGN), which has well defined mathematical properties, comparative analysis of
different types of higher order modulation systems can be reliably performed.

You might also like