2k19ec209 CSF3 All

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

Communication System Lab

Name - Vikas Gupta


Roll no - 2K19/EC/209
Teacher - Vinay kumar Sangwan

(Experiment no - 5)
Aim : To generate matlab code for Frequency Modulation.

Platform : Matlab software.

Theory :
Frequency Modulation

In amplitude modulation, the amplitude of the carrier signal varies.


Whereas, in Frequency Modulation (FM), the frequency of the
carrier signal varies in accordance with the instantaneous
amplitude of the modulating signal.
Hence, in frequency modulation, the amplitude and the phase of
the carrier signal remains constant. This can be better understood
by observing the following figures.
The frequency of the modulated wave increases, when the
amplitude of the modulating or message signal increases.
Similarly, the frequency of the modulated wave decreases, when
the amplitude of the modulating signal decreases. Note that, the
frequency of the modulated wave remains constant and it is equal
to the frequency of the carrier signal, when the amplitude of the
modulating signal is zero.

Mathematical Representation

The equation for instantaneous frequency fifi in FM modulation is

fi=fc+kfm(t)fi=fc+kfm(t)

Where,
fcfc is the carrier frequency
ktkt is the frequency sensitivity

m(t)m(t) is the message signal

We know the relationship between angular frequency ωiωi and


angle θi(t)θi(t) as

ωi=dθi(t)dtωi=dθi(t)dt

⇒2πfi=dθi(t)dt⇒2πfi=dθi(t)dt

⇒θi(t)=2π∫fidt⇒θi(t)=2π∫fidt

Substitute, fifi value in the above equation.

θi(t)=2π∫(fc+kfm(t))dtθi(t)=2π∫(fc+kfm(t))dt

⇒θi(t)=2πfct+2πkf∫m(t)dt⇒θi(t)=2πfct+2πkf∫m(t)dt

Substitute, θi(t)θi(t) value in the standard equation of angle


modulated wave.

s(t)=Accos(2πfct+2πkf∫m(t)dt)s(t)=Accos⁡(2πfct+2πkf∫m
(t)dt)
This is the equation of FM wave.
If the modulating signal
is m(t)=Amcos(2πfmt)m(t)=Amcos⁡(2πfmt), then the equation
of FM wave will be

s(t)=Accos(2πfct+βsin(2πfmt))s(t)=Accos⁡(2πfct+βsin⁡(
2πfmt))
Where,
ββ = modulation index =Δffm=kfAmfm=Δffm=kfAmfm
The difference between FM modulated frequency (instantaneous
frequency) and normal carrier frequency is termed as Frequency
Deviation. It is denoted by ΔfΔf, which is equal to the product
of kfkf and AmAm.
FM can be divided into Narrowband FM and Wideband
FM based on the values of modulation index ββ.

Narrowband FM

Following are the features of Narrowband FM.


 This frequency modulation has a small bandwidth when
compared to wideband FM.
 The modulation index ββ is small, i.e., less than 1.
 Its spectrum consists of the carrier, the upper sideband and the
lower sideband.
 This is used in mobile communications such as police wireless,
ambulances, taxicabs, etc.

Wideband FM

Following are the features of Wideband FM.


 This frequency modulation has infinite bandwidth.
 The modulation index ββ is large, i.e., higher than 1.
 Its spectrum consists of a carrier and infinite number of
sidebands, which are located around it.
 This is used in entertainment, broadcasting applications such
as FM radio, TV, etc.
Code -
clc;
clear all;
close all;
%% Time Domain FM
fm=4;
fc=80;
wm=2*pi*fm;
wc=2*pi*fc;
Am=5;
Ac=5;
fs=1000;
ts=1/fs;
n=1000;
t=0:ts:(n-1)*ts;
mssg=Am*cos(2*pi*fm*t);
carr=Ac*cos(2*pi*fc*t);
subplot(4,2,1);
plot(t,mssg);
xlabel('Time'); ylabel('Amplitude');
title('Message signal');
subplot(4,2,3)
plot(t,carr);
xlabel('Time'); ylabel('Amplitude');
title('Carrier signal');
%wide band
B=15;
fm1=Ac*cos(wc*t+B.*sin(wm*t));
subplot(4,2,5)
plot(t,fm1);
xlabel('Time'); ylabel('Amplitude');
title('fM wideband signal (B=15)');
%Narrow band
B=0.6;
fm2=Ac*cos(wc*t+B.*sin(wm.*t));
subplot(4,2,7)
plot(t,fm2);
xlabel('Time'); ylabel('Amplitude');
title('FM Narrow band signal (B=0.6)');
%% FM Spectrum
l1=length(mssg);
f=fs*(-l1/2:l1/2-1)/l1;
ff1=fft(mssg,l1);
subplot(4,2,2)
plot(f,2/fs*abs(fftshift(ff1)));
xlabel('Frequency'); ylabel('Amplitude');
title('Message signal in frequency domain');
l2=length(carr);
f=fs*(-l2/2:l2/2-1)/l2;
ff2=fft(carr,l2);
subplot(4,2,4)
plot(f,2/fs*abs(fftshift(ff2)));
xlabel('Frequency'); ylabel('Amplitude');
title('Carrier signal in frequency domain');
l3=length(fm1);
f=fs*(-l2/2:l2/2-1)/l2;
ff2=fft(fm1,l2);
subplot(4,2,6);
plot(f,2/fs*abs(fftshift(ff2)));
xlabel('Frequency'); ylabel('Amplitude');
title('FM wide band signal in frequency domain');
l3=length(fm2);
f=fs*(-l2/2:l2/2-1)/l2;
ff2=fft(fm2,l2);
subplot(4,2,8);
plot(f,2/fs*abs(fftshift(ff2)));
xlabel('Frequency'); ylabel('Amplitude');
title('FM narrow band signal in frequency domain');

Output Result :
(Experiment no - 6)
Aim : To generate matlab code for Phase Modulation.

Platform : Matlab software.

Theory :

Phase Modulation
In frequency modulation, the frequency of the carrier varies.
Whereas, in Phase Modulation (PM), the phase of the carrier
signal varies in accordance with the instantaneous amplitude of
the modulating signal.
So, in phase modulation, the amplitude and the frequency of the
carrier signal remains constant. This can be better understood by
observing the following figures.
The phase of the modulated wave has got infinite points, where
the phase shift in a wave can take place. The instantaneous
amplitude of the modulating signal changes the phase of the
carrier signal. When the amplitude is positive, the phase changes
in one direction and if the amplitude is negative, the phase
changes in the opposite direction.

Mathematical Representation

The equation for instantaneous phase ϕiϕi in phase modulation is

ϕi=kpm(t)ϕi=kpm(t)

Where,


kpkp is the phase sensitivity


m(t)m(t) is the message signal

The standard equation of angle modulated wave is

s(t)=Accos(2πfct+ϕi)s(t)=Accos⁡(2πfct+ϕi)

Substitute, ϕiϕi value in the above equation.

s(t)=Accos(2πfct+kpm(t))s(t)=Accos⁡(2πfct+kpm(t))

This is the equation of PM wave.


If the modulating
signal, m(t)=Amcos(2πfmt)m(t)=Amcos⁡(2πfmt), then the
equation of PM wave will be

s(t)=Accos(2πfct+βcos(2πfmt))s(t)=Accos⁡(2πfct+βcos⁡(
2πfmt))
Where,

β= modulation index = Δϕ=kpAmΔϕ=kpAm


ΔϕΔϕ is phase deviation

Phase modulation is used in mobile communication systems,


while frequency modulation is used mainly for FM broadcasting.
Code :
clc;
clear all;
close all;
fm=4;
fc=50;
wm=2*pi*fm;
wc=2*pi*fc;
Am=5;
Ac=5;
kp=pi/2;
t=linspace(0,1,1000);
fs=1000;
mssg=Am*cos(wm*t);
carr=Ac*cos(wc*t);
figure;
subplot(3,2,1);
plot(t,mssg);
xlabel('Time-->');
ylabel('Amplitude-->');
title('Message signal');
l1=length(mssg);
f=fs*[-l1/2:l1/2-1]/l1;
ff1=fft(mssg,l1);
subplot(3,2,2);
plot(f,2/fs*abs(fftshift(ff1)));
xlabel('Frequency');
ylabel('Amplitude');
title('Message signal in frequency domain');
subplot(3,2,3)
plot(t,carr);
xlabel('Time-->');
ylabel('Amplitude-->');
title('Carrier signal');
l2=length(carr);
f=fs*[-l2/2:l2/2-1]/l2;
ff2=fft(carr,l2);
subplot(3,2,4);
plot(f,2/fs*abs(fftshift(ff2)));
xlabel('Frequency');
ylabel('Amplitude');
title('Carrier signal in frequency domain');
pm=Ac*cos(wc*t+Am*kp.*cos(wm*t));
subplot(3,2,5)
plot(t,pm);
xlabel('Time-->');
ylabel('Amplitude-->');
title('PM signal');
l3=length(pm);
f=fs*[-l3/2:l3/2-1]/l3;
ff3=fft(pm,l3);
subplot(3,2,6)
plot(f,2/fs*abs(fftshift(ff3)));
xlabel('Frequency');
ylabel('Amplitude');
title('Modulation in frequency domain');

Output :
(Experiment no - 7)
Aim : To generate matlab code for Dsbsc demod using
synchronous detector .

Platform : Matlab software.

Theory :
The process of extracting an original message signal from DSBSC
wave is known as detection or demodulation of DSBSC. The
following demodulators (detectors) are used for demodulating
DSBSC wave.

 Synchronous Detector
 Costas Loop

Synchronous Detector

Here, the same carrier signal (which is used for generating


DSBSC signal) is used to detect the message signal. Hence, this
process of detection is called as coherent or synchronous
detection. Following is the block diagram of the coherent detector.

In this process, the message signal can be extracted from DSBSC


wave by multiplying it with a carrier, having the same frequency
and the phase of the carrier used in DSBSC modulation. The
resulting signal is then passed through a Low Pass Filter. Output
of this filter is the desired message signal.
Let the DSBSC wave be

s(t)=Accos(2πfct)m(t)s(t)=Accos⁡(2πfct)m(t)

The output of the local oscillator is

c(t)=Accos(2πfct+ϕ)c(t)=Accos⁡(2πfct+ϕ)

Where, ϕϕ is the phase difference between the local oscillator


signal and the carrier signal, which is used for DSBSC modulation.
From the figure, we can write the output of product modulator as

v(t)=s(t)c(t)v(t)=s(t)c(t)

Substitute, s(t)s(t) and c(t)c(t) values in the above equation.

⇒v(t)=Accos(2πfct)m(t)Accos(2πfct+ϕ)⇒v(t)=Accos⁡(2πfc
t)m(t)Accos⁡(2πfct+ϕ)

=Ac2cos(2πfct)cos(2πfct+ϕ)m(t)=Ac2cos⁡(2πfct)cos⁡(2πfct
+ϕ)m(t)
=Ac22[cos(4πfct+ϕ)+cosϕ]m(t)=Ac22[cos⁡(4πfct+ϕ)+cos⁡ϕ]
m(t)

v(t)=Ac22cosϕm(t)+Ac22cos(4πfct+ϕ)m(t)v(t)=Ac22cos⁡ϕm
(t)+Ac22cos⁡(4πfct+ϕ)m(t)
In the above equation, the first term is the scaled version of the
message signal. It can be extracted by passing the above signal
through a low pass filter.
Therefore, the output of low pass filter is

v0t=Ac22cosϕm(t)v0t=Ac22cos⁡ϕm(t)

The demodulated signal amplitude will be maximum,


when ϕ=00ϕ=00. That’s why the local oscillator signal and the
carrier signal should be in phase, i.e., there should not be any
phase difference between these two signals.
The demodulated signal amplitude will be zero,
when ϕ=±900ϕ=±900. This effect is called as quadrature null
effect.

Code :
clc;
clear all;
close all;
t = 0.1:0.001:1;
fs = 1000;
fm=5;
fc=20;
wm = 2*pi*5;
wc = 2*pi*20;
Am = 1;
Ac = 2;
m = Am*sin(wm.*t);
c = Ac*cos(wc*t);
N_t = length(t);
modulated = Ac*c.*m;
N = length(modulated);
N_scale = fs*(-N/2:N/2-1)/N;
c_fft = fftshift(fft(c))/N;
m_fft = fftshift(fft(m))/N;
modulated_fft = fftshift(fft(modulated)/N);
figure(1);
subplot(2, 2, 1);
plot(t, m);
title('message Vikas 2K19/EC/209(t)');
subplot(2, 2, 2);
plot(t, c);
title('carrier(t)');
subplot(2, 2, 3);
plot(N_scale, abs(m_fft));
title('M(w)');
subplot(2, 2, 4);
plot(N_scale, abs(c_fft));
title('C(w)');
figure(2);
subplot(2, 1, 1);
plot(t, modulated);
title('s(t)');
subplot(2, 1, 2);
plot(N_scale, abs(modulated_fft));
title('S(w)');
figure(3);
Fco = 30;
n = 1;
[b,a] = butter(n, 2*Fco/fs, 'low');
freqz(b, a);
[Yh, w] = freqz(b, a, fs/2);
h = ifft(Yh);
mulOut = Ac*c.*modulated;
lpfOut = filter(b, a, mulOut);
YlpfOut = fftshift(fft(lpfOut)/length(lpfOut));
N1 = length(lpfOut);
Nd_scale = fs*(-N1/2:N1/2-1)/N1;
figure(4);
subplot(2,1,1);
plot(t, lpfOut);
title('demod at 0 2K19/EC/209');
hold on;
plot(t, m);
hold off;
subplot(2,1,2);
plot(Nd_scale, abs(YlpfOut));
title('des_fft');
phi = pi/4;
c45 = cos(wc*t + phi);
phi = pi/2;
c90 = cos(wc*t + phi);
mulOut = Ac*c45.*modulated;
lpfOut = filter(b, a, mulOut);
YlpfOut = fftshift(fft(lpfOut)/length(lpfOut));
N1 = length(lpfOut);
Nd_scale = fs*(-N1/2:N1/2-1)/N1;
figure(5);
subplot(2,1,1);
plot(t, lpfOut);
title ('demodulated at 45');
hold on;
plot(t, m);
hold off;
subplot(2,1,2);
plot(Nd_scale, abs(YlpfOut));
title ('des_fft');
mulOut = Ac*c90.*modulated;
lpfOut = filter(b, a, mulOut);
YlpfOut = fftshift(fft(lpfOut)/length(lpfOut));
N1 = length(lpfOut);
Nd_scale = fs*(-N1/2:N1/2-1)/N1;
figure(6);
subplot(2,1,1);
plot(t, lpfOut);
title ('demodulated at 90');
hold on;
plot(t, m);
hold off;
subplot(2,1,2);
plot(Nd_scale, abs(YlpfOut));
title ('des_fft');

Output :
(Experiment no - 8)
Aim : To generate matlab code for Ssbsc demod using
synchronous detector .

Platform : Matlab software.

Theory :
The process of extracting an original message signal from SSBSC wave is
known as detection or demodulation of SSBSC. Coherent detector is used for
demodulating SSBSC wave.

Synchronous Detector

Here, the same carrier signal (which is used for generating SSBSC wave) is
used to detect the message signal. Hence, this process of detection is called
as coherent or synchronous detection. Following is the block diagram of
coherent detector.
In this process, the message signal can be extracted from SSBSC wave by
multiplying it with a carrier, having the same frequency and the phase of the
carrier used in SSBSC modulation. The resulting signal is then passed
through a Low Pass Filter. The output of this filter is the desired message
signal.
Consider the following SSBSC wave having a lower sideband.

s(t)=AmAc2cos[2π(fc−fm)t]s(t)=AmAc2cos⁡[2π(fc−fm)t]

The output of the local oscillator is

c(t)=Accos(2πfct)c(t)=Accos⁡(2πfct)

From the figure, we can write the output of product modulator as

v(t)=s(t)c(t)v(t)=s(t)c(t)

Substitute s(t)s(t) and c(t)c(t) values in the above equation.

v(t)=AmAc2cos[2π(fc−fm)t]Accos(2πfct)v(t)=AmAc2cos⁡[2π(fc−fm)t]Accos
⁡(2πfct)

=AmAc22cos[2π(fc−fm)t]cos(2πfct)=AmAc22cos⁡[2π(fc−fm)t]cos⁡(2πfct)

=AmAc24{cos[2π(2fc−fm)]+cos(2πfm)t}=AmAc24{cos⁡[2π(2fc−fm)]+cos⁡(2
πfm)t}

v(t)=AmAc24cos(2πfmt)+AmAc24cos[2π(2fc−fm)t]v(t)=AmAc24cos⁡(2πf
mt)+AmAc24cos⁡[2π(2fc−fm)t]
In the above equation, the first term is the scaled version of the message
signal. It can be extracted by passing the above signal through a low pass
filter.
Therefore, the output of low pass filter is

v0(t)=AmAc24cos(2πfmt)v0(t)=AmAc24cos⁡(2πfmt)

Here, the scaling factor is Ac24Ac24.


We can use the same block diagram for demodulating SSBSC wave having
an upper sideband. Consider the following SSBSC wave having an upper
sideband.

s(t)=AmAc2cos[2π(fc+fm)t]s(t)=AmAc2cos⁡[2π(fc+fm)t]

The output of the local oscillator is

c(t)=Accos(2πfct)c(t)=Accos⁡(2πfct)

We can write the output of the product modulator as

v(t)=s(t)c(t)v(t)=s(t)c(t)

Substitute s(t)s(t) and c(t)c(t) values in the above equation.

⇒v(t)=AmAc2cos[2π(fc+fm)t]Accos(2πfct)⇒v(t)=AmAc2cos⁡[2π(fc+f
m)t]Accos⁡(2πfct)

=AmAc22cos[2π(fc+fm)t]cos(2πfct)=AmAc22cos⁡[2π(fc+fm)t]cos⁡(2
πfct)

=AmAc24{cos[2π(2fc+fm)t]+cos(2πfmt)}=AmAc24{cos⁡[2π(2fc+fm)t]
+cos⁡(2πfmt)}

v(t)=AmAc24cos(2πfmt)+AmAc24cos[2π(2fc+fm)t]v(t)=AmAc24cos
⁡(2πfmt)+AmAc24cos⁡[2π(2fc+fm)t]
In the above equation, the first term is the scaled version of the message
signal. It can be extracted by passing the above signal through a low pass
filter.
Therefore, the output of the low pass filter is

v0(t)=AmAc24cos(2πfmt)v0(t)=AmAc24cos⁡(2πfmt)

Here too the scaling factor is Ac24Ac24.


Therefore, we get the same demodulated output in both the cases by using
coherent detector.
Code :

clc;
clear ;
close all;
Am=1; %amplitude of message signal
Ac=2; %amplitude of carrier signal
ka=0.25 %amplitude sensitivity of a modulator
Fm=5; %frequency of message signal
Fc=20; %frequency of carrier signal
F=500; %sampling frequency
T=1/F; %time period
t=0:T:1; % x-axis;
n=length(t); %length of t

figure(1);
%message signal
Mt=Am*cos(2*pi*Fm*t); %sinusoidal signal
subplot(3,1,1);
plot(t,Mt); %define signal
xlabel('Time(s)');
ylabel('Amplitude');
title('Message VIKAS 2K19/EC/209 signal');

%carrier signal
Ct=Ac*cos(2*pi*Fc*t); %sinusoidal signal
subplot(3,1,2);
plot(t,Ct,'r'); %define signal
xlabel('Time(s)');
ylabel('Amplitude');
title('Carrier signal');

% Hilbert transform of baseband (message signal)


Mh = imag(hilbert(Mt));

%Hilbert transform of baseband (carrier signal)


Ch= imag(hilbert(Ct));

%SSBSC modulation
Xt1=Mt.*Ct - Mh.*Ch; %Single Side Band with Upper Side
Band
Xt2=Mt.*Ct + Mh.*Ch; %Single Side Band with lower Side
Band
subplot (3,1,3);
plot(t,Xt1,'m'); %defining ssb modulation
xlabel('Time(s)');
ylabel('Amplitude');
title('SSB modulated 2K19/EC/209 signal');
figure(2);
%FREQUENCY SPECTRUM OF MESSAGE SIGNAL
fs=F*[-n/2:n/2-1]/n; %frequency axis
Mf=fftshift(fft(Mt,n)); %defining frequency spectrum
subplot(4,1,1);
plot(fs,abs(Mf));
xlabel('Frequency (Hz)');
ylabel('Amplitude');
title('Frequency spectrum of message signal');

%FREQUENCY SPECTRUM OF CARRIER SIGNAL


Cf=fftshift(fft(Ct,n));
subplot(4,1,2);
plot(fs,abs(Cf),'r');
xlabel('Frequency (Hz)');
ylabel('Amplitude');
title('Frequency spectrum of carrier signal');

%frequency spectrum of ssb with upper side band


Xf1=fftshift(fft(Xt1,n));
subplot(4,1,3);
plot(fs,abs(Xf1),'m'); %since signal is complex,we used
abs(in order to get absolute value)
xlabel('Frequency (Hz)');
ylabel('Amplitude');
title('Frequency spectrum of upper side band');

%frequency spectrum of ssb with lower side band


Xf2=fftshift(fft(Xt2,n));
subplot(4,1,4);
plot(fs,abs(Xf2),'m');
xlabel('Frequency (Hz)');
ylabel('Amplitude');
title('Frequency spectrum of lower side band');

figure(3);
%designing of low pass filter
fco=30; % LPF 3db cutoff frequency in Hz
N=2; % order of butterworth filter
[b,a]=butter(N,2*fco/F,'low');
freqz(b,a); % bode plot (mag and phase)

% local oscillator
ct= cos(2*pi*Fc*t); %with zero phase
ct2=cos(2*pi*Fc*t + pi/2); %with 90 degree phase

figure(4);
%multiplier output with (zero degree phase shift)
mulout=Xt1.*ct; %in time domain
subplot(2,2,1);
plot(t,mulout);
xlabel('Time(s)');
ylabel('Amplitude');
title('Multiplier output (0 degree phase shift)');

%spectrum of multiplier
muloutf=fftshift(fft(mulout,n));
subplot(2,2,2);
plot(fs,abs(muloutf));
xlabel('Frequency (Hz)');
ylabel('Amplitude');
title('Spectrum of multiplier (0 degree phase shift)');

%output of low pass filter of order 2(with zero degree


phase shift)
lpfout = filter(b,a,mulout);
subplot(2,2,3);
plot(t,lpfout,'r',t,Mt,'b');
xlabel('Time(s)');
ylabel('Amplitude');
title('Demodulated and message signal in time domain
(0)');

%spectrum of output of low pass filter


Ylpfout =fftshift(fft(lpfout,n));
subplot(2,2,4);
plot(fs,abs(Ylpfout),'r',fs,abs(Mf));
xlabel('Frequency (Hz)');
ylabel('Amplitude');
title('Spectrum of demodulated and message signal (0)');

figure(5)
%multiplier output with (90 degree phase shift)
mulout2=Xt1.*ct2; %in time domain
subplot(4,1,1);
plot(t,mulout2);
xlabel('Time(s)');
ylabel('Amplitude');
title('Multiplier output (90 degree phase shift)');

%spectrum of multiplier
muloutf2=fftshift(fft(mulout2,n));
subplot(4,1,2);
plot(fs,abs(muloutf2));
xlabel('Frequency (Hz)');
ylabel('Amplitude');
title('Spectrum of multiplier (with 90 degree phase
shift)');
%output of low pass filter of order 2(with 90 degree
phase shift)
lpfout2 = filter(b,a,mulout2);
subplot(4,1,3);
plot(t,lpfout2,'r',t,Mt,'b');
xlabel('Time(s)');
ylabel('Amplitude');
title('Demodulated and message signal signal (90)');

Ylpfout2 =fftshift(fft(lpfout2,n));
subplot(4,1,4);
plot(fs,abs(Ylpfout2),'r',fs,abs(Mf));
xlabel('Frequency (Hz)');
ylabel('Amplitude');
title('Spectrum of demodulated and message signal (90)');

Output Result :

You might also like