% EXPERIMENT 3
% PULSE POSITION MODULATION AND DEMODULATION
clc;
clear all;
close all;
fm = 1000; % Message frequency
fs = 10000; % Pulse repetition frequency
Fs = 200000; % Sampling rate
t = 0:1/Fs:0.01;
Ts = 1/fs;
% Message signal (1 Vpp)
m = 0.5*sin(2*pi*fm*t);
N = round(Ts*Fs);
pulse_width = round(0.1*N);
ppm = zeros(size(t));
decoded = zeros(size(t));
% PPM Generation and Decoding
for k = 0:floor(length(t)/N)-1
index = k*N + 1;
% Position shift according to message
shift = round(((m(index)+0.5)/1)*0.6*(N-pulse_width));
start_pos = index + shift;
end_pos = min(start_pos+pulse_width-1,length(t));
ppm(start_pos:end_pos) = 1;
% Decode pulse position
decoded(index:min(index+N-1,length(t))) = ...
2*shift/(0.6*(N-pulse_width))-1;
end
% FFT based Low Pass Filter
L = length(t);
Y = fftshift(fft(decoded));
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,ppm,'r');
title('PPM Modulated Signal');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;
subplot(3,1,3);
plot(t,demodulated,'g','LineWidth',1.5);
title('PPM Demodulated Signal');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;
disp('Experiment 3 Completed Successfully');
To embed this project on your website, copy the following code and paste it into your website's HTML: