You are on page 1of 16

EEE-351 Principles of Communication Systems

Lab Report-03:
Title: Amplitude Modulation/Demodulation in MATLAB

Student Name ABDUL WAHAB


FAIQ JHANZAIB

FA20-BEE-010
Registration Number FA20-BEE-048

BEE-5B
Class/Section

Instructor’s Name SIR KHAN AFSAR

Lab Assessment Marks

Pre Lab /1
/1
Ability to use software /5
Follow procedures /5 /10
In Lab
Troubleshoot software /5 /5
Q&A /5
Presentation /4
Post-Lab Analysis /4 /4
Writing /4

COMSATS University Islamabad (CUI), Islamabad Campus Page 1


Objectives
In this lab, you will understand the basic concepts of amplitude modulation/demodulation.
You will learn twoimportant techniques of amplitude modulation:
- Double-sideband suppressed carrier (DSB-SC)
- Double-sideband through carrier (DSB-TC)
By implementing these two schemes in MATLAB, you will be able to visualize them in
time as well as infrequency domain.

Note: Understanding this lab is important to implement amplitude modulation in USRP

In Lab Tasks
Task 3.1
Generate the following message signal. Plot the time-domain waveform of the message
signal and analyzeits spectrum. Set 𝑡𝑡0 = 0.15.

Lab 03 2
MATLAB Code and Results:
clc;
clear all
close all;
t0=0.15;
step=0.0005;
tx1=0:step:0.05;
tx2=0.05:step:0.1;
t=[tx1 tx2];
m1=ones(size(tx1)).*1;
m2=ones(size(tx2)).*(-2);
m=[m1 m2];
subplot(2,1,1)
plot(t,m,'linewidth',2)
title('Message signal in time domain')
xlabel('t')
ylabel('m')
grid on;

L=length(m);
m3=abs(fft(m,L));
U = fftshift(fft(m));
w=1000*linspace(-1,1,L);
subplot(2,1,2)
plot(w,m3,'linewidth',2)
title('Message signal in Frequency Domain')
xlabel('w')
ylabel('m3')
grid on;

Lab 03 3
RESULT:

Figure 1:shows the message signal in time domain as well as frequency domain.

Task 3.2
Perform DSB-SC AM on the message signal generated in the Task 3.1. Plot the time-domain
waveform of the modulated signal and analyse its spectrum. For the carrier signal assume that 𝐴𝐴
= 1 volts and 𝑓𝑓𝑐𝑐 = 250 Hz.

Lab 03 4
MATLAB Code:
clc;
clear all
close all;
t0=0.15;
step=0.0005;
tx1=0:step:0.05;
tx2=0.05:step:0.1;
t=[tx1 tx2];
m1=ones(size(tx1)).*1;
m2=ones(size(tx2)).*(-2);
m=[m1 m2];
subplot(2,1,1)
plot(t,m,'linewidth',2)
title('Message signal')
xlabel('t')
ylabel('m')
grid on;

L=length(m);
m3=abs(fft(m,L));
w=1000*linspace(-1,1,L);
subplot(2,1,2)
plot(w,m3,'linewidth',2)
title('Message signal in Frequency Domain')
xlabel('w')
ylabel('m3')
grid on;

figure(2)
f=250;
AC=1;
y=cos(2*pi*f*t);
plot(t,y,'linewidth',2)
title('carrier')

figure(3)

g= AC*m.*y;
subplot(2,1,1)
plot(t,g,'linewidth',2)
title('Modulated Signal in Time Domain')
xlabel('t')

Lab 03 5
ylabel('g')
grid on;

L=length(g);
g=abs(fft(g,L));
U = fftshift(fft(g));
w=1000*linspace(-1,1,L);
subplot(2,1,2)
plot(w,g,'linewidth',2)
title('Modulated signal in Frequency Domain')
xlabel('w')
ylabel('u')

RESULTS:

Lab 03 6
Lab 03 7
Task 3.3
Perform the coherent demodulation on the modulated signal of the Task 3.2. Determine
appropriate cut-off frequency of the low-pass filter to recover message signal. Plot the time-
domain waveform of the recovered signaland its spectrum.

MATLAB Code and Results

clc;
clear all;
close all;
Ac = 1;
Fc= 250;
t0=0.15;
Fs=1000;
step=0.0005;
tx1=0:step:0.05;
tx2=0.05:step:0.1;
t=[tx1 tx2];
m1=ones(size(tx1)).*1;
m2=ones(size(tx2)).*(-2);
m=[m1 m2];
u = Ac.*m.*cos(2*pi*Fc*t)
subplot(3,1,1)
plot(t,u,'linewidth',2)
title('Modulated Signal')
c = (Ac.*m.*cos(2*pi*Fc*t)).*(Ac.*cos(2*pi*Fc*t));
subplot(3,1,2)
plot(t,c,'linewidth',2)
title('U(t)*Carrier Signal')
y= Fc./Fs;
lpf=fir1(15,y);
demod=filter(lpf,1,c)
subplot(3,1,3)
plot(t,demod,'linewidth',2)
title('Demodulated Signal')

Lab 03 8
RESULT:

Figure 2:shows the modulated signal and if we take product of carrier with modulated signal it
will give back a demodulated signal which is a message signal.

Task 3.4
Perform the DSB-TC AM on the message signal generated in the Task 3.1. Using the modulation
index value of
𝜇𝜇 = 0.5, set the appropriate value of 𝐴𝐴. Plot the time-domain waveform of the modulated signal
and analyse its spectrum.

Lab 03 9
MATLAB Code:
clc;
clear all;
close all;

t0 = 0.15;
step = 0.0005;
tx1 = 0:step:0.05;
tx2 = 0.05:step:0.1;
t = [tx1 tx2];
m1 = ones(size(tx1)) * 1;
m2 = ones(size(tx2)) * (-2);
m = [m1 m2];

% Calculate the carrier frequency and amplitude


fc = 250; % Carrier frequency (Hz)
A = 2; % Carrier amplitude

% Modulate the message signal


g = A * m .* cos(2 * pi * fc * t);

% Plot the message signal


subplot(3,1,1)
plot(t, m, 'linewidth', 2)
title('Message signal')
xlabel('t')
ylabel('m')
grid on;

% Plot the carrier signal


subplot(3,1,2)
y = A * cos(2 * pi * fc * t);
plot(t, y, 'linewidth', 2)
title('Carrier signal')
xlabel('t')
ylabel('y')
grid on;

% Plot the modulated signal in time domain


subplot(3,1,3)
plot(t, g, 'linewidth', 2)
title('Modulated Signal in Time Domain')
xlabel('t')
ylabel('g')

Lab 03 10
grid on;

% Analyze the spectrum of the modulated signal


L = length(g);
G = fft(g, L);
U = fftshift(G);
w = 1000 * linspace(-1, 1, L);

figure;
subplot(2,1,1)
plot(w, abs(U), 'linewidth', 2)
title('Modulated Signal in Frequency Domain (Magnitude)')
xlabel('w')
ylabel('|U(w)|')
grid on;

subplot(2,1,2)
plot(w, angle(U), 'linewidth', 2)
title('Modulated Signal in Frequency Domain (Phase)')
xlabel('w')
ylabel('Phase(U(w))')
grid on;

RESULT:

Lab 03 11
Figure 3: This graph shows the effect of changing modulation constant and also changing the
amplitude of carrier signal.

Post-Lab Task
Import an audio signal ‘afile.wav’ in MATLAB. Plot the time-domain waveform of the
message signal andanalyze its spectrum.

Setting 𝐴𝐴 = 1 volts and 𝑓𝑓𝑐𝑐 = 15000 Hz, perform the DSB-SC AM on the audio file. Plot
the time-domainwaveform of the modulated signal and analyse its spectrum.
Perform the coherent demodulation on the modulated audio signal. Determine appropriate
cut-off frequency of the low-pass filter to recover message signal. Plot the time-domain
waveform of the recoveredsignal and its spectrum.
Note: use the MATLAB function ‘soundsc’ to listen to the original and recovered audio signal.

Lab 03 12
MATLAB CODE:

clc; % Clears the Command Window


clear all; % Clears all variables from the
workspace
close all; % Closes all open figures

Ac = 1; % Amplitude of the carrier signal


Fc = 15000; % Carrier frequency (15 kHz)
t = 3500000; % Time variable (used for modulating the
signal)

[y, Fs] = audioread('afile.wav'); % Reads audio from


'afile.wav' and returns the signal 'y' and the sampling
rate 'Fs'
sound(y, Fs); % Plays the audio
signal
subplot(2,1,1); % Creates a subplot
plot(y); % Plots the message
title('Message signal'); % Sets the title for
the subplot

L = length(y); % Length of the signal 'y'


m3 = abs(fft(y, L)); % Computes the magnitude
of the FFT of 'y'
w = 1000 * linspace(-1, 1, L); % Creates a frequency
axis for the FFT
subplot(2,1,2); % Creates a subplot (2
rows, 1 column, 2nd plot)
plot(w, m3); % Plots the message
signal in the frequency domain
title('Message signal in Frequency Domain'); % Sets the
title for the subplot

figure(2); % Creates a new figure


(Figure 2)
u = Ac .* y .* cos(2*pi*Fc*t); % Modulates the message
signal 'y' with a carrier signal
subplot(3,1,1); % Creates a subplot (3
rows, 1 column, 1st plot)
plot(u); % Plots the modulated
signal in the time domain

Lab 03 13
title('Modulated Signal in Time Domain'); % Sets the title
for the subplot

c = (Ac .* y .* cos(2*pi*Fc*t)) .* (Ac .* cos(2*pi*Fc*t));


% Multiplies the modulated signal by the carrier signal
subplot(3,1,2); % Creates a subplot (3
rows, 1 column, 2nd plot)
plot(c); % Plots the product of
modulated signal and carrier signal
title('U(t)*Carrier Signal'); % Sets the title for
the subplot

y = Fc / Fs; % Calculates a value


related to the carrier frequency and sampling rate
lpf = fir1(15, y); % Designs a low-pass
FIR filter with 15 coefficients
demod = filter(lpf, 1, c); % Demodulates the
signal using the designed filter
subplot(3,1,3); % Creates a subplot (3
rows, 1 column, 3rd plot)
plot(demod); % Plots the
demodulated signal
sound(demod); % Plays the demodulated
signal
title('Demodulated Signal'); % Sets the title for
the subplot

Lab 03 14
RESULT:

Lab 03 15
Explanation:
It demonstrates the modulation and demodulation of an audio signal using amplitude modulation
(AM). It takes an audio signal from the file 'afile.wav', modulates it with a carrier signal, and
then demodulates it to recover the original message signal. The code also includes various
plotting and visualization steps to show the signals in the time and frequency domains.

Critical Analysis

1. Importing and Visualizing the Audio Signal:


The time-domain waveform of the original audio signal is plotted, giving students a visual representation
of the input audio.

2. Spectrum Analysis of the Original Signal:


A crucial aspect of signal analysis is examining its frequency content. In this step, the code computes
and visualizes the frequency spectrum of the original audio signal. By observing this spectrum, we can
gain insight into the dominant frequencies and harmonics present in the audio.

3. Carrier Signal Generation:


To perform amplitude modulation, a carrier signal is required. This step sets up the parameters for AM
modulation:
`A_c` determines the amplitude of the carrier.
`f_c` sets the carrier frequency.
`t_c` is a time vector synchronized with the original signal, representing the carrier signal.
A cosine waveform is generated to simulate the carrier signal.

4. AM Modulation:
The core of this lab exercise is the modulation process. The original audio signal is combined with the
carrier signal using multiplication (`modulated signal = audio .* carrier'`).The result is a modulated signal
that carries the information from the original audio within its amplitude variations. Plotting the modulated
signal in the time domain enables students to observe how the audio signal is embedded within the carrier.

5. Spectrum Analysis of the Modulated Signal:


Understanding the spectrum of the modulated signal is crucial in AM modulation. The code calculates
and visualizes the frequency spectrum of the modulated signal. We can see the sidebands around the
carrier frequency due to the modulation process.

6. Coherent Demodulation:
Coherent demodulation involves reversing the modulation process by multiplying the modulated signal
with the carrier signal. This step extracts the original audio signal from the modulated signal, a critical
concept in demodulation.

7. Low-Pass Filtering for Message Signal Recovery:


To obtain a clean audio message signal, filtering is employed. A low-pass Butterworth filter is designed
with a specified cutoff frequency (here, 2000 Hz) to recover the message signal.The filtered signal, termed
the "recovered signal," represents the original audio message.

Lab 03 16

You might also like