Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

ADVANCED COMMUNICATION LAB

A Lab Report
Submitted to fulfil partial requirement
For the degree of
MASTERS OF ENGINEERING
In
ELECTRONICS & COMMUNICATION

DEPARTMENT OF ELECTRONICS AND COMMUNICATION


ENGINEERING

THAPAR INSTITUTE OF ENGINEERING AND TECHNOLOGY


PATIALA-147003

Submitted to: Submitted by:


Mrs. Divya Sharma Meghna
801861003
INDEX

Sr No Name of Experiment Date Page Remarks


no

1 To study the basic signals and plot them in July 31,18 1-3
MATLAB.
2 To study the Amplitude Modulation in Aug 7,18 4-5
MATLAB.
3 To study the Amplitude Shift Keying(ASK) Aug 14,18 6-7
Modulation in MATLAB.
4 To study the Binary Frequency Shift Aug 21,18 8-9
Keying(BFSK) Modulation in MATLAB.
5 To study the Binary Phase Shift Keying(BPSK) Aug 28,18 10-11
Modulation in MATLAB.
6 To plot the constellation diagram of Binary Phase Sept 4,18 12-13
Shift Keying(BPSK) Modulation in MATLAB.
7 To plot the constellation diagram of Amplitude Sept 4,18 14-15
Shift Keying(ASK) Modulation in MATLAB.
8 To plot the constellation diagram of Binary Sept 11,18 16-17
Frequency Shift Keying(BFSK) Modulation in
MATLAB.
9 To plot the constellation diagram of Quadrature Sept 11,18 18-19
Phase Shift Keying(QPSK) Modulation in
MATLAB.
10 To plot the BER vs SNR graph for Binary Phase Oct 10,18 20-21
Shift Keying(BPSK) over an AWGN channel in
MATLAB.
11 To plot the BER vs SNR graph for Quadrature Oct 16,18 22-23
Phase Shift Keying(QPSK) over an AWGN
channel in MATLAB.
12 To plot the BER vs SNR graph for Binary Phase Oct 23,18 24-25
Shift Keying(QPSK) over an Rayleigh fading
channel in MATLAB.
Experiment-1
Aim: To study the basic signals and plot them in MATLAB.
Theory: During communication we send various type of signals . In order to process these signals we
need to check how to generate these signals in MATLAB and various properties of these signals. We
studied following signals:
a) Impulse function

b) Unit step function

c) Unit ramp function

d) Sine and cosine waves

e) Unit step response

1
Matlab code:
clc
clear all;

%% impulse response
d=[];
t=-10:10;
d=[zeros(1,10),ones(1,1),zeros(1,10)];
subplot(6,1,1);
stem(t,d);
title('impulse response');
xlabel('time');
ylabel('amplitude');
%% unit step
u1=[zeros(1,10),ones(1,11)];
subplot(6,1,2);
stem(t,u1);
title('unit step');
xlabel('time');
ylabel('amplitude');
%% unit ramp
for ii=1:21
r(ii)=t(ii);
end
subplot(6,1,3);
stem(t,r);
title('unit ramp');
xlabel('time');
ylabel('amplitude');
%% sine wave and cosine wave
x=-pi:0.01:pi;
subplot(6,1,4);
stem(x,sin(x));
title('sine wave');
xlabel('time');
ylabel('amplitude');
subplot(6,1,5)
stem(x,cos(x));
title('cosine wave');
xlabel('time');
ylabel('amplitude');

%% unit step response


u2=[zeros(1,16),ones(1,5)];
u=u1-u2;
subplot(6,1,6)
stem(t,u);
title('unit step response')

2
Output:

3
Experiment-2
Aim: To study the Amplitude Modulation in MATLAB.
Theory: In communication, the most common technique to modulate our signal is amplitude
modulation. In amplitude modulation, the carrier amplitude is modulated according to our message signal.
The AM equation can be expressed as:

Where first term expresses carrier wave and second term expresses two sidebands.
Algorithm:
1. Generate a message signal.
2. Plot the signal.
3. Generate a carrier signal whose frequency is more than that of message signal.
4. Plot this signal.
5. Use the AM equation to modulate the carrier with message signal.
6. Use different modulation index to study the concept of percentage of modulation.

Matlab Code:
%% carrier & modulating waves

t=0:0.01:10*pi;
m= cos(t);
subplot(3,2,1)
plot(t,m);
title('message signal');
xlabel('Time');
ylabel('Amplitude');
c=cos(10*t);
subplot(3,2,2);
plot(t,c);
title('carrier signal');
xlabel('Time');
ylabel('Amplitude');
%%

am=c+(0.1*cos(t+10*t))+(0.1*cos(t-10*t));
subplot(3,2,3)
plot(t,am)
title('AM wave with modulation index=0.2');
xlabel('Time');
ylabel('Amplitude');
am1=c+(0.25*cos(t+10*t))+(0.25*cos(t-10*t));
subplot(3,2,4)
plot(t,am1)
title('AM wave with modulation index=0.5');
xlabel('Time');
ylabel('Amplitude');

4
am2=c+(0.4*cos(t+10*t))+(0.4*cos(t-10*t));
subplot(3,2,5)
plot(t,am2)
title('AM wave with modulation index=0.8');
xlabel('Time');
ylabel('Amplitude');
am3=c+(0.5*cos(t+10*t))+(0.5*cos(t-10*t));
subplot(3,2,6)
plot(t,am3)
title('AM wave with modulation index=1');
xlabel('Time');
ylabel('Amplitude');

Output:

5
Experiment-3
Aim: To study the Amplitude Shift Keying(ASK) Modulation in MATLAB.

Theory: ASK is a type of Amplitude Modulation which represents the binary data in the form of
variations in the amplitude of a signal. The binary signal when ASK modulated, gives a zero
value for Low input while it gives the carrier output for High input.

where
vask(t) = amplitude-shift keying wave
vm(t) = digital information (modulating) signal (volts)
A/2 = unmodulated carrier amplitude (volts)
ωc = analog carrier radian frequency (radians per second, 2πf ct)

vm(t)=+1 for logic 1 and -1 for logic 0.

Matlab Code:
%This program is used for ASK modulation
clc;
clear;
%Input data
n=input('enter the no of bits--->');
b=randi([0,1],1,n)
subplot(3,1,1)
stairs(b) %This is used to create a staircase signal
axis([1 10 -2 +2]) %For better representation of signal axis command is used
%1to 10 is range of x axis while -2 to +2 is range of y axis
%% carrier signal
t=linspace(1,n,100);
c=10*sin(2*pi*t);
subplot(3,1,2)
plot(t,c)
%% ASK Modulation
my2=[];a1=0.5; a2=0;
t1=1/99:1/99:1;
for jj=1:length(b)
if b(jj)==1
m2=a1*sin(4*pi*t1);
else b(jj)==0
m2=a2*sin(2*pi*t1);
end
my2=[my2 m2]
m2=0;
end
t2=1/99:1/99:length(b)
subplot(3,1,3)
plot(t2,my2)

6
Output:
Command window

Waveforms

7
Experiment-4
Aim: To study the Binary Frequency Shift Keying(BFSK) Modulation in MATLAB.
Theory: BFSK uses a pair of discrete frequencies to transmit binary (0s and 1s) information. With this
scheme, the “1” is called the mark frequency and the “0” is called the space frequency.

Matlab Code:
clc;
clear;
n=input('enter the no of bits--->');
b=randi([0,1],1,n)
bp=1
m=[]
for i=1:length(b)
if b(i)==1
m1=ones(1,100);
else b(i)==0
m1=zeros(1,100);
end

m=[m m1];

end
t1=bp/100:bp/100:length(b)*(bp);
subplot(2,1,1)
plot(t1,m)
t2=bp/99:bp/99:bp;
y=[]; A=5; f1=8; f2=2; m2=[];
for (i=1:1:length(b))
if (b(i)==1)
y=A*cos(2*pi*f1*t2);
else
y=A*cos(2*pi*f2*t2);
end
m2=[m2 y];
end
t3=bp/99:bp/99:bp*length(b);
subplot(2,1,2);
plot(t3,m2);
xlabel('time(sec)');
ylabel('amplitude(volt)');
title('waveform for binary FSK modulation');

8
Output:
Command Window

Waveforms

9
Experiment-5
Aim: To study the Binary Phase Shift Keying(BPSK) Modulation in MATLAB.
Theory: In this scheme, phase of carrier signal is varied to represent binary 1 or 0 while peak amplitude
and frequency remain constant during each bit interval.

Matlab Code:
clc;
clear;
n=input('enter the no of bits--->');
b=randi([0,1],1,n)
bp=1
m=[]
for i=1:length(b)
if b(i)==1
m1=ones(1,100);
else b(i)==0
m1=zeros(1,100);
end

m=[m m1];

end
t1=bp/100:bp/100:length(b)*(bp);
subplot(2,1,1)
plot(t1,m)
xlabel('time(sec)');
ylabel('amplitude(volt)');
title('message signal');

t2=bp/99:bp/99:bp;
y=[]; A=5; f=2; m2=[];
for (i=1:1:length(b))
if (b(i)==1)
y=A*sin(2*pi*f*t2);
else
y=-A*sin(2*pi*f*t2);
end
m2=[m2 y];
end
t3=bp/99:bp/99:bp*length(b);
subplot(2,1,2);
plot(t3,m2);
xlabel('time(sec)');
ylabel('amplitude(volt)');
title('waveform for binary PSK modulation');

10
Output:
Command window

Waveforms

11
Experiment-6
Aim: To plot the constellation diagram of Binary Phase Shift Keying(BPSK) Modulation in MATLAB.
Theory: Constellation diagrams are graphical representation of the complex envelope of signal. The x
axis represents the in-phase component and y axis represents the quadrature component of the complex
envelope. The distance between signals on a constellation diagram relates to how different the waveforms
are. Constellation diagrams are used to evaluate the energy of the signal in modulation side.
The signal space can be represented as basis function

Symbol 0 is represented by and


symbol 1 is represented by

Algorithm:
1. Generate a binary bit string.
2. Replace symbols 0 and 1with their corresponding energies.
3. Plot the signals.

Matlab Code:
clc;
clear all;

n=input('enter the no of bits--->');


bit_stream=randi([0,1],1,n)
% modulated_bit_stream=(2*bit_stream)-1
k=1;
m=1;
E=1;
for ii=1:n
r=mod(ii,2);
if(r==0)
even(k)=sqrt(E);
k= k+1;
else
odd(m)=-sqrt(E);
m=m+1;

end
end
y1=zeros(1,length(even));
y2=zeros(1,length(odd));
stem(even,y1,'r')
hold on;

12
stem(odd,y2,'r')
xlim([-2 2]);
ylim([-2 2]);
line(xlim,[0 0])
line([0 0],ylim)
grid on;

Output:

13
Experiment-7
Aim: To plot the constellation diagram of Amplitude Shift Keying(ASK) Modulation in MATLAB.
Theory: In amplitude shift keying as only symbol 1 is transmitted and symbol 0 has zero energy
theorectically. So, the constellation diagram consists of signal in single side only.

Matlab Code:
clc;
clear all;
%% ASK modulation
n=input('enter the no of bits--->');
b=randi([0,1],1,n)
my2=[];a1=0.5; a2=0;
t1=1/99:1/99:length(b)
for jj=1:length(b)
if b(jj)==1
m2=a1*sin(4*pi*t1);
else b(jj)==0
m2=a2*sin(2*pi*t1);
end
my2=[my2 m2]
m2=0;
end

%% constellation diagram\
k=1;
m=1;
E=1;
for ii=1:n
r=mod(ii,2);
if(r==0)
even(k)=sqrt(E);
k= k+1;
else
odd(m)=0;
m=m+1;

end
end
y1=zeros(1,length(even));

14
y2=zeros(1,length(odd));
stem(even,y1,'r')
hold on;
stem(odd,y2,'r')
xlim([-2 2]);
ylim([-2 2]);
line(xlim,[0 0])
line([0 0],ylim)
grid on;

Output:

15
Experiment-8
Aim: To plot the constellation diagram of Binary Frequency Shift Keying(BFSK) Modulation in
MATLAB.

Theory: In BFSK as the two signals are orthogonal to each other and are represented by √𝐸𝑏 on signal
space. The distance between two points is evaluated by
2 2
𝑑2 = (√𝐸𝑏 ) + (√𝐸𝑏 )

𝑑 = √2𝐸𝑏

Matlab Code:
clc;
close all;
clear all;

n=input('enter the no of bits--->');


bit_stream=randi([0,1],1,n)
% modulated_bit_stream=(2*bit_stream)-1
k=1;
m=1;
E=1;
for i=1:n
if(bit_stream(i)==0)
x(i)=0;
y(i)=sqrt(E/2);
elseif(bit_stream(i)==1)
x(i)=sqrt(E/2);
y(i)=0;
end
end

plot(x,y,'xk')
xlim([-2 2]);
ylim([-2 2]);
line(xlim,[0 0])
line([0 0],ylim)
grid on;

16
Output:

17
Experiment-9
Aim: To plot the constellation diagram of Quadrature Phase Shift Keying(QPSK) Modulation in
MATLAB.

Theory: In QPSK every signal is equidistant from origin( √𝐸𝑠 ) an to determine the signal without any
error the distance between points is given as d=2 √𝐸𝑏 where 𝐸𝑏 is the energy contained in a bit
transmitted for the time 𝑇𝑏 . The distance ‘d’ for QPSK is same as of BPSK hence they both have same
noise immunity.

Matlab Code:
clc;
close all;
clear all;

n=input('enter the no of bits--->');


b=randi([0,1],1,n)

A=1/sqrt(2);e=[]
for ii=1:n-1
if b(ii)==0 && b(ii+1)==0
energy=-A-i*A;
elseif b(ii)==0 && b(ii+1)==1
energy=-A+i*A;
elseif b(ii)==1 && b(ii+1)==0
energy=A-i*A;
else b(ii)==1 && b(ii+1)==1
energy=A+i*A;
end
e=[e energy];
end
plot(real(e),imag(e),'xk');
xlim([-2 2]);
ylim([-2 2]);
line(xlim,[0 0])
line([0 0],ylim)
grid on;

Output:

18
19
Experiment-10
Aim: To plot the BER vs SNR graph for Binary Phase Shift Keying(BPSK) over an AWGN channel in
MATLAB.
Theory: Bit error rate depicts the error bits in transmitted signal. When the signal to noise ratio is more
better is the BER.
The bit error probability for BPSK oven an AWGN channel is expressed as:
𝑑
𝑃𝑏 = 𝑄( )
√𝑁𝑜

For realizing bit error rate (BER) over an additive white Gaussian noise (AWGN) channel the effect of
noise is represented in the baseband with Gaussian random samples added to each signal sample. The
signal to noise ratio (SNR) is varied to show the effect of SNR on BER
Matlab Code:
clear all
clc
r=randint(1,10000);
for i=1:10000
if r(i)==0
s(i)=-1;
else
s(i)=1;
end
end
k=1;
for snrdb=1:1:10;
v=1/(10^(snrdb/10));
x=awgn(s,snrdb,'measured');
%n1=sqrt(v/2)*randn(1,10000);
%n2=sqrt(1/2)*randn(1,10000);
%n=sqrt(n1.*n1+n2.*n2);
y=x;
for j=1:10000
if y(j)>0
z(j)=1;
else
z(j)=0;
end
end
error=length(find(z~=r));
ber(k)=error/10000;
k=k+1;
end
snrdb=1:1:10;
snrlin=10.^(snrdb./10);
tber=0.5.*erfc(sqrt(snrlin));
semilogy(snrdb,ber,'-bo',snrdb,tber,'-mh')
grid on
title('BPSK with AWGN');
xlabel('Signal to noise ratio');
ylabel('Bit error rate');

20
Output:

21
Experiment-11
Aim: To plot the BER vs SNR graph for Quadrature Phase Shift Keying(QPSK) over an AWGN channel
in MATLAB.
Theory: The probability of error for QPSK is approximately equal to

𝐸𝑠
𝑃𝑒 = 𝑒𝑟𝑓𝑐(√ )
2𝑁𝑜

𝐸𝑠
White Gaussian noise is added to the QPSK modulated signal and the graph is plotted for different
𝑁𝑜
values. Theoretical and simulates graphs are compared and plotted in MATLAB.
Matlab Code:
clear all;
close all;

l=10000;
snrdb=1:1:10;
snrlin=10.^(snrdb/10);

for snrdb=1:1:10
si=2*(round(rand(1,l))-0.5);
sq=2*(round(rand(1,l))-0.5);
s=si+j*sq;
w=awgn(s,snrdb,'measured');
r=w;
si_=sign(real(r));
sq_=sign(imag(r));
ber1=(l-sum(si==si_))/l;
ber2=(l-sum(sq==sq_))/l;
ber(snrdb)=mean([ber1 ber2]);
end

%semilogy(snrdb, ber,'o-')
snrdb=1:1:10;
snrlin=10.^(snrdb./10);
tber=erfc(sqrt(snrlin));
semilogy(snrdb,ber,'-bo',snrdb,tber,'-mh')
title('QPSK with awgn');
xlabel('Signal to noise ratio');
ylabel('Bit error rate');
grid on;

22
Output:

23
Experiment-12
Aim: To plot the BER vs SNR graph for Binary Phase Shift Keying(BPSK) over an Rayleigh fading
channel in MATLAB.
Theory: Rayleigh fading channel is more realistic way of representing a wireless channel. It has a
constant flat frequency response. The BER for a Rayleigh fading channel is much higher than the BER for
an AWGN channel. In fact, for Rayleigh fading, the BER curve is almost a straight line.
Matlab Code:
% Rayleigh fading channel

clear
close all
clear all

N = 10^6 % number of bits or symbols

% Transmitter
Input = rand(1,N)>0.5; % generating 0,1 with equal probability
s = 2*Input-1; % BPSK modulation 0 -> -1; 1 -> 0

Eb_N0_dB = [-3:40]; % multiple Eb/N0 values

for ii = 1:length(Eb_N0_dB)

n = 1/sqrt(2)*[randn(1,N) + j*randn(1,N)]; % white gaussian noise, 0dB variance


h = 1/sqrt(2)*[randn(1,N) + j*randn(1,N)]; % Rayleigh channel

% Channel and noise Noise addition


y = h.*s + 10^(-Eb_N0_dB(ii)/20)*n;

% equalization
yHat = y./h;

% receiver - hard decision decoding


InputHat = real(yHat)>0;

% counting the errors


nErr(ii) = size(find([Input- InputHat]),2);

end

simBer = nErr/N; % simulated ber


theoryBerAWGN = 0.5*erfc(sqrt(10.^(Eb_N0_dB/10))); % theoretical ber
EbN0Lin = 10.^(Eb_N0_dB/10);
theoryBer = 0.5.*(1-sqrt(EbN0Lin./(EbN0Lin+1)));

% plot
close all
figure

24
semilogy(Eb_N0_dB,theoryBerAWGN,'r','LineWidth',2);
hold on
semilogy(Eb_N0_dB,theoryBer,'gs','LineWidth',2);
hold on
semilogy(Eb_N0_dB,simBer,'b','LineWidth',2);
axis([-3 40 10^-5 0.5])
grid on
legend('AWGN-Theory','Rayleigh-Theory', 'Rayleigh-Simulation');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('BER for BPSK modulation in Rayleigh channel');

Output:

25

You might also like