## 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

**Also read about**