Skip to main content

MATLAB Code for Pulse Amplitude Modulation (PAM) and 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; % (=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');

web('https://www.salimwireless.com/search?q=pulse%20amplitude%20modulation', '-browser');

 Output

 

Copy the code from here

 


Another Code for Pulse Amplitude Modulation and Demodulation of an Analog Message Signal 

MATLAB Script

 clc;
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');
web('https://www.salimwireless.com/search?q=pulse%20amplitude%20modulation', '-browser');

Copy the Code from here

 

Pulse Amplitude Modulation (PAM) & Demodulation for Digital Data

% The code is written by SalimWireless.Com
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);
web('https://www.salimwireless.com/search?q=pulse%20amplitude%20modulation', '-browser');

Output






Copy the MATLAB Code from here



Simulation Results for comparison of PAM, PWM, PPM, DM, and PCM

 
 
 

  
 

 
 
 
 

 
 
 

Explore Signal Processing Simulations

Further Reading

  1. Pulse Amplitude Modulation and Demodulation theory
  2. Is PAM a Digital Modulation Technique ?
  3. Pulse Width Modulation (PWM) and Demodulation
  4. Pulse Position Modulation (PPM) and Demodulation
  5. Delta Modulation and demodulation
  6. Pulse Code Modulation (PCM)
  7. Quantization Signal to Noise Ration (Q-SNR)
  8. MATLAB Code for Pulse Width Modulation and Demodulation
  9. MATLAB Code for Pulse Position Modulation (PPM) and Demodulation
  10. MATLAB Code for Pulse Code Modulation (PCM) and demodulation

People are good at skipping over material they already know!

View Related Topics to







Admin & Author: Salim

s

  Website: www.salimwireless.com
  Interests: Signal Processing, Telecommunication, 5G Technology, Present & Future Wireless Technologies, Digital Signal Processing, Computer Networks, Millimeter Wave Band Channel, Web Development
  Seeking an opportunity in the Teaching or Electronics & Telecommunication domains.
  Possess M.Tech in Electronic Communication Systems.


Contact Us

Name

Email *

Message *

Popular Posts

RMS Delay Spread, Excess Delay Spread and Multi-path ...

๐Ÿ“˜ Overview of Delay Spread and Multi-path ๐Ÿงฎ Excess Delay spread ๐Ÿงฎ Power delay Profile ๐Ÿงฎ RMS Delay Spread ๐Ÿ“š Further Reading ๐Ÿ“‚ Other Topics on RMS Delay Spread, Excess Delay ... ๐Ÿงฎ Multipath Components or MPCs ๐Ÿงฎ Online Simulator for Calculating RMS Delay Spread ๐Ÿงฎ Why is there significant multipath in the case of very high frequencies? ๐Ÿงฎ Why RMS Delay Spread is essential for wireless communication? ๐Ÿงฎ Why the Power Delay Profile is essential? ๐Ÿงฎ MATLAB Codes for Calculating Different Types of delay Spreads Delay Spread, Excess Delay Spread, and Multipath (MPCs) The fundamental distinction between wireless and wired connections is that in wireless connections signal reaches at receiver thru multipath signal propagation rather than directed transmission like co-axial cable. Wireless Communication has no set communication path between the transmitter and the receiver. The line...

BER vs SNR for M-ary QAM, M-ary PSK, QPSK, BPSK, ...

๐Ÿ“˜ Overview of BER and SNR ๐Ÿงฎ Online Simulator for BER calculation of m-ary QAM and m-ary PSK ๐Ÿงฎ MATLAB Code for BER calculation of M-ary QAM, M-ary PSK, QPSK, BPSK, ... ๐Ÿ“š Further Reading ๐Ÿ“‚ View Other Topics on M-ary QAM, M-ary PSK, QPSK ... ๐Ÿงฎ Online Simulator for Constellation Diagram of m-ary QAM ๐Ÿงฎ Online Simulator for Constellation Diagram of m-ary PSK ๐Ÿงฎ MATLAB Code for BER calculation of ASK, FSK, and PSK ๐Ÿงฎ MATLAB Code for BER calculation of Alamouti Scheme ๐Ÿงฎ Different approaches to calculate BER vs SNR What is Bit Error Rate (BER)? The abbreviation BER stands for bit error rate, which indicates how many corrupted bits are received (after the demodulation process) compared to the total number of bits sent in a communication process. It is defined as,  In mathematics, BER = (number of bits received in error / total number of transmitted bits)  On the other hand, SNR ...

Constellation Diagrams of ASK, PSK, and FSK

๐Ÿ“˜ Overview of Energy per Bit (Eb / N0) ๐Ÿงฎ Online Simulator for constellation diagrams of ASK, FSK, and PSK ๐Ÿงฎ Theory behind Constellation Diagrams of ASK, FSK, and PSK ๐Ÿงฎ MATLAB Codes for Constellation Diagrams of ASK, FSK, and PSK ๐Ÿ“š Further Reading ๐Ÿ“‚ Other Topics on Constellation Diagrams of ASK, PSK, and FSK ... ๐Ÿงฎ Simulator for constellation diagrams of m-ary PSK ๐Ÿงฎ Simulator for constellation diagrams of m-ary QAM BASK (Binary ASK) Modulation: Transmits one of two signals: 0 or -√Eb, where Eb​ is the energy per bit. These signals represent binary 0 and 1.    BFSK (Binary FSK) Modulation: Transmits one of two signals: +√Eb​ ( On the y-axis, the phase shift of 90 degrees with respect to the x-axis, which is also termed phase offset ) or √Eb (on x-axis), where Eb​ is the energy per bit. These signals represent binary 0 and 1.  BPSK (Binary PSK) Modulation: Transmits one of two signals...

Comparisons among ASK, PSK, and FSK | And the definitions of each

๐Ÿ“˜ Comparisons among ASK, FSK, and PSK ๐Ÿงฎ Online Simulator for calculating Bandwidth of ASK, FSK, and PSK ๐Ÿงฎ MATLAB Code for BER vs. SNR Analysis of ASK, FSK, and PSK ๐Ÿ“š Further Reading ๐Ÿ“‚ View Other Topics on Comparisons among ASK, PSK, and FSK ... ๐Ÿงฎ Comparisons of Noise Sensitivity, Bandwidth, Complexity, etc. ๐Ÿงฎ MATLAB Code for Constellation Diagrams of ASK, FSK, and PSK ๐Ÿงฎ Online Simulator for ASK, FSK, and PSK Generation ๐Ÿงฎ Online Simulator for ASK, FSK, and PSK Constellation ๐Ÿงฎ Some Questions and Answers Modulation ASK, FSK & PSK Constellation MATLAB Simulink MATLAB Code Comparisons among ASK, PSK, and FSK    Comparisons among ASK, PSK, and FSK   Simulator for Calculating Bandwidth of ASK, FSK, and PSK The baud rate represents the number of symbols transmitted per second. Both baud rate and bit rate a...

Difference between AWGN and Rayleigh Fading

๐Ÿ“˜ Introduction, AWGN, and Rayleigh Fading ๐Ÿงฎ Simulator for the effect of AWGN and Rayleigh Fading on a BPSK Signal ๐Ÿงฎ MATLAB Codes ๐Ÿ“š Further Reading Wireless Signal Processing Gaussian and Rayleigh Distribution Difference between AWGN and Rayleigh Fading 1. Introduction Rayleigh fading coefficients and AWGN, or additive white gaussian noise [↗] , are two distinct factors that affect a wireless communication channel. In mathematics, we can express it in that way.  Fig: Rayleigh Fading due to multi-paths Let's explore wireless communication under two common noise scenarios: AWGN (Additive White Gaussian Noise) and Rayleigh fading. y = h*x + n ... (i) Symbol '*' represents convolution. The transmitted signal  x  is multiplied by the channel coefficient or channel impulse response (h)  in the equation above, and the symbol  "n"  stands for the white Gaussian noise that is added to the si...

MATLAB Codes for Various types of beamforming | Beam Steering, Digital...

Beamforming Techniques MATLAB Codes for Beamforming... The mathematical [↗] and theoretical aspects of beamforming [↗] have already been covered. We'll talk about coding in MATLAB in this tutorial so that you may generate results for different beamforming approaches. Let's go right to the content of the article. In analog beamforming, certain codebooks are employed on the TX and RX sides to select the best beam pairs. Because of their beamforming gains, communication created through the strongest beams from both the TX and RX side enhances spectrum efficiency. Additionally, beamforming gain directly impacts SNR improvement. Wireless communication system capacity = bandwidth*log2(1+SNR) bits/s. Thus, the capacity or overall throughput of the system increases. MATLAB Script %Written by Salim Wireless %Visit www.salimwireless.com for study materials on wireless communication %or, if you want to learn how to code in MATLAB clear all;...

Mathematical Aspects of Beamforming in MIMO

๐Ÿ“˜ Overview ๐Ÿงฎ The Mathematics Behind Analog, Digital, and Hybrid Beamforming ๐Ÿ“š Further Reading ๐Ÿ“‚ Other Topics on Beamforming in MIMO ... MIMO / Massive MIMO Beamforming Techniques Beam steering, which permits strong directed beams towards the receiver to combat excessive pathloss, especially for higher frequency bands, immediately comes to mind when discussing mathematical aspects of Beamforming in MIMO antennas. On the other side, it also lessens signal interference and improves the effectiveness of spatial multiplexing in Massive MIMO communication. Let's go right to the mathematical parts of Beamforming, which will make it easier for you to code in Python and MATLAB. 1. Beam Steering (Analog Beamforming) In the first stage, the BS applies beam steering at the side of the mobile station (MS) while the MS enables omnidirectional transmission. In the following step, the MS uses beam steering while the BS is an...