Pulse Amplitude Modulation (PAM) & Demodulation
MATLAB Script
clc;
clear all;
close all;
fm= 10; % frequency of the message signal
fc= 100; % frequency of the carrier signal
fs=1000*fm; % (=100KHz) sampling frequency (where 1000 is the upsampling factor)
t=0:1/fs:1; % sampling rate of (1/fs = 100 kHz)
m=1*cos(2*pi*fm*t); % Message signal with period 2*pi*fm (sinusoidal wave signal)
c=0.5*square(2*pi*fc*t)+0.5; % square wave with period 2*pi*fc
s=m.*c; % modulated signal (multiplication of element by element)
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');
%demdulated
d=s.*c; % At receiver, received signal is multiplied by carrier signal
filter=fir1(200,fm/fs,'low'); % low-pass FIR filter which order is 200
% here fm is the cut-off frequency and the fs is the sampling frequency
original_t_signal=conv(filter,d); % convolution of demodulated signal with filter %coefficient
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');
Output
Copy the code from here
Another Code for Pulse Amplitude Modulation
MATLAB Script
clear;
close all;
% Parameters
messageFrequency = 2; % Message frequency in Hz
carrierFrequency = 20; % Carrier frequency in Hz
samplingFrequency = 1000; % Sampling frequency in Hz
duration = 1; % Signal duration in seconds
A = 1; % Amplitude of the signals
% Time vector
t = 0:1/samplingFrequency:duration;
% Message signal (sinusoidal)
messageSignal = A * sin(2 * pi * messageFrequency * t);
% Carrier signal (square wave)
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');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(3,1,2);
plot(t, carrierSignal);
title('Carrier Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(3,1,3);
plot(t, pamSignal);
title('PAM Signal');
xlabel('Time (s)');
ylabel('Amplitude');
Copy the Code from here
Pulse Amplitude Modulation (PAM) & Demodulation for Digital Data
clc;
clear;
close all;
% PAM Modulation and Demodulation Example
% Parameters
M = 8; % PAM order (8-PAM)
numSymbols = 100; % Number of symbols to transmit
Fs = 1000; % Sampling frequency
T = 1; % Symbol duration
% Generate random data
data = randi([0 M-1], 1, numSymbols); % Random data symbols
% PAM Modulation
% Map the data symbols to PAM levels
pamLevels = linspace(-M + 1, M - 1, M); % PAM levels
modulatedSignal = pamLevels(data + 1); % Map data to PAM levels
% Create a 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 some noise
snr = 20; % Signal-to-noise ratio
noisySignal = awgn(upsampledSignal, snr, 'measured');
% PAM Demodulation
% Sample the noisy signal at symbol rate
receivedSymbols = noisySignal(1:Fs:end);
% Map received symbols to nearest PAM level
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');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(4,1,2);
plot(t, upsampledSignal);
title('Transmitted PAM Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(4,1,3);
plot(t, noisySignal);
title('Received Noisy PAM Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(4,1,4);
stem(demodulatedData);
title('Demodulated Data');
xlabel('Symbol Index');
ylabel('PAM Level');
grid on;
% Display results
disp('Original Data:');
disp(data);
disp('Demodulated Data:');
disp(demodulatedData);