Pulse Amplitude Modulation (PAM) & Demodulation
Pulse Amplitude Modulation (PAM) & Demodulation of an Analog Message Signal
MATLAB Script
clc;
clear all;
close all;
fm = 10; % frequency of the message signal
fc = 100; % frequency of the carrier signal
fs = 1000 * fm; % sampling frequency (100 kHz)
t = 0:1/fs:1;
m = 1 * cos(2 * pi * fm * t);
c = 0.5 * square(2 * pi * fc * t) + 0.5;
s = m .* c;
subplot(4,1,1);
plot(t,m);
title('Message signal');
xlabel('Time');
ylabel('Amplitude');
subplot(4,1,2);
plot(t,c);
title('Carrier signal');
xlabel('Time');
ylabel('Amplitude');
subplot(4,1,3);
plot(t,s);
title('Modulated signal');
xlabel('Time');
ylabel('Amplitude');
% Demodulation
d = s .* c;
filter = fir1(200,fm/fs,'low');
original_t_signal = conv(filter,d);
t1 = 0:1/(length(original_t_signal)-1):1;
subplot(4,1,4);
plot(t1,original_t_signal);
title('Demodulated signal');
xlabel('Time');
ylabel('Amplitude');
web('https://www.salimwireless.com/search?q=pulse%20amplitude%20modulation', '-browser');
Output
Another Code for Pulse Amplitude Modulation and Demodulation of an Analog Message Signal
MATLAB Script
clc;
clear;
close all;
% Parameters
messageFrequency = 2;
carrierFrequency = 20;
samplingFrequency = 1000;
duration = 1;
A = 1;
% Time vector
t = 0:1/samplingFrequency:duration;
% Message signal
messageSignal = A * sin(2 * pi * messageFrequency * t);
% Carrier signal
carrierSignal = A * square(2 * pi * carrierFrequency * t);
% PAM signal
pamSignal = messageSignal .* (carrierSignal > 0);
% Plotting
figure;
subplot(3,1,1); plot(t, messageSignal); title('Message Signal');
subplot(3,1,2); plot(t, carrierSignal); title('Carrier Signal');
subplot(3,1,3); plot(t, pamSignal); title('PAM Signal');
web('https://www.salimwireless.com/search?q=pulse%20amplitude%20modulation', '-browser');
Pulse Amplitude Modulation (PAM) & Demodulation for Digital Data
% The code is written by SalimWireless.Com
clc;
clear;
close all;
% Parameters
M = 8;
numSymbols = 100;
Fs = 1000;
T = 1;
% Generate random data
data = randi([0 M-1], 1, numSymbols);
% PAM Modulation
pamLevels = linspace(-M + 1, M - 1, M);
modulatedSignal = pamLevels(data + 1);
% Create time vector
t = 0:1/Fs:T*numSymbols-1/Fs;
% Upsample and create PAM signal
upsampledSignal = zeros(1, length(t));
for i = 1:numSymbols
upsampledSignal((i-1)*Fs+1:i*Fs) = modulatedSignal(i);
end
% Add noise
snr = 20;
noisySignal = awgn(upsampledSignal, snr, 'measured');
% PAM Demodulation
receivedSymbols = noisySignal(1:Fs:end);
demodulatedData = zeros(1, numSymbols);
for i = 1:numSymbols
[~, demodulatedData(i)] = min(abs(receivedSymbols(i) - pamLevels));
end
% Plotting
figure;
subplot(4,1,1); stem(data); title('Original Data');
subplot(4,1,2); plot(t, upsampledSignal); title('Transmitted PAM Signal');
subplot(4,1,3); plot(t, noisySignal); title('Received Noisy PAM Signal');
subplot(4,1,4); stem(demodulatedData); title('Demodulated Data');
grid on;
disp('Original Data:'); disp(data);
disp('Demodulated Data:'); disp(demodulatedData);
web('https://www.salimwireless.com/search?q=pulse%20amplitude%20modulation', '-browser');
Output
Simulation Results for Comparison of PAM, PWM, PPM, DM, and PCM
Further Reading
- Pulse Amplitude Modulation and Demodulation theory
- Is PAM a Digital Modulation Technique ?
- Pulse Width Modulation (PWM) and Demodulation
- Pulse Position Modulation (PPM) and Demodulation
- Delta Modulation and demodulation
- Pulse Code Modulation (PCM)
- Quantization Signal to Noise Ration (Q-SNR)
- MATLAB Code for Pulse Width Modulation and Demodulation
- MATLAB Code for Pulse Position Modulation (PPM) and Demodulation
- MATLAB Code for Pulse Code Modulation (PCM) and demodulation