% EXPERIMENT 2
% PULSE AMPLITUDE MODULATION AND DEMODULATION
clc;
clear all;
close all;
fm = 1000; % Message frequency
fs = 16000; % Sampling frequency
Fs = 200000; % Sampling rate
t = 0:1/Fs:0.01;
Ts = 1/fs;
% Message signal (2 Vpp)
m = sin(2*pi*fm*t);
% PAM Generation
N = round(Ts*Fs);
pulse_width = round(0.4*N);
pam = zeros(size(t));
for k = 0:floor(length(t)/N)-1
index = k*N + 1;
finish = min(index+pulse_width-1,length(t));
amplitude = m(index);
pam(index:finish) = amplitude;
end
% PAM Demodulation using FFT
L = length(t);
Y = fftshift(fft(pam));
f = ((0:L-1)-floor(L/2))*(Fs/L);
cutoff = 2000;
Y(abs(f)>cutoff) = 0;
demodulated = real(ifft(ifftshift(Y)));
% Plotting
figure(1);
subplot(3,1,1);
plot(t,m,'b','LineWidth',1.5);
title('Original Message Signal');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;
subplot(3,1,2);
plot(t,pam,'r','LineWidth',1);
title('PAM Modulated Signal');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;
subplot(3,1,3);
plot(t,demodulated,'g','LineWidth',1.5);
title('PAM Demodulated Signal');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;
disp('Experiment 2 Completed Successfully');
To embed this project on your website, copy the following code and paste it into your website's HTML: