You are on page 1of 2

MATLAB CODE:

clc;
clear all;
close all;

fc = 3000; % carrier frequency 3kHz


fm = 200; % modulating frequency 200Hz
fs = 1e6; % sampling frequency
t = linspace(0, 0.02, 5000); % a row matrix for plotting
Am = 1; % amplitude of modulating signal
Ac = 2; % amplitude of carrier signal

% generating modulating signal or message signal


ms = Am * sin(2*pi*fm*t);

% generating carrier signal


cs = Ac * sin(2*pi*fc*t);

% amplitude modulated signals


m1 = Am/Ac; % m = 0.5 i.e. under modulated
y1 = Ac * (1 + m1*sin(2*pi*fm*t)) .* sin(2*pi*fc*t);
m2 = 1; % perfectly modulated
Ac = Am/m2;
y2 = Ac * (1 + m2*sin(2*pi*fm*t)) .* sin(2*pi*fc*t);
m3 = 2; % over modulated
Ac = Am/m3;
y3 = Ac * (1 + m3*sin(2*pi*fm*t)) .* sin(2*pi*fc*t);

% amplitude demodulated signals


% for y1
r1 = y1 .* cs; % rectified signal
[num, den] = butter(2, fc*2/fs); % lowpass filter
z1 = filter(num, den, r1);

% for y2
r2 = y2 .* cs; % rectified signal
[num, den] = butter(2, fc*2/fs); % lowpass filter
z2 = filter(num, den, r2);

% for y3
r3 = y3 .* cs; % rectified signal
[num, den] = butter(2, fc*2/fs); % lowpass filter
z3 = filter(num, den, r3);

% we can also use inbuilt ammod and amdemmod functions for generating
% amplitude modulated and demodulated signals

figure;
subplot(4, 3, 1:3);
plot(t, ms);
xlabel("Time(s)");
ylabel("Amplitude");
title("Modulating Signal (fm = 200 Hz)");

subplot(4, 3, 4:6);
plot(t, cs);
xlabel("Time(s)");
ylabel("Amplitude");
title("Carrier Signal (fc = 3 kHz)");

subplot(4, 3, 7);
plot(t, y1);
xlabel("Time(s)");
ylabel("Amplitude");
title("Under Modulated Signal (m = 0.5)");

subplot(4, 3, 8);
plot(t, y2);
xlabel("Time(s)");
ylabel("Amplitude");
title("Perfectly Modulated Signal (m = 1)");

subplot(4, 3, 9);
plot(t, y3);
xlabel("Time(s)");
ylabel("Amplitude");
title("Over Modulated Signal (m = 2)");

subplot(4, 3, 10);
plot(t, z1);
xlabel("Time(s)");
ylabel("Amplitude");
title("De Modulated Signal (m = 0.5)");

subplot(4, 3, 11);
plot(t, z2);
xlabel("Time(s)");
ylabel("Amplitude");
title("De Modulated Signal (m = 1)");

subplot(4, 3, 12);
plot(t, z3);
xlabel("Time(s)");
ylabel("Amplitude");
title("De Modulated Signal (m = 2)");

You might also like