clc;
clear all;
close all;
d=50;
fs=1000;
t=0:1/fs:d;
r=1 :2: d;
x=pulstran(t,r,'rectpuls');
subplot(4,1,1);
plot(t,x);
xlabel("Time");
ylabel("Amplitude");
title("Pulse Train");
%Sine Function
s=5.sin(((2pi).5t)/d);
subplot(4,1,2);
plot(t,s);
xlabel("Time");
ylabel("Amplitude");
title("Sine Function");
%PAM Modulation
sig=x.s;
subplot(4,1,3);
plot(t,sig);
xlabel("Time");
ylabel("Amplitude");
title("Pulse Amplitude Modulation");
%PAM Demodulation
N_fft=10001;
hl = fir1(N_fft,(0.1/(fs/2)),'low');
sig1 = 4.conv(sig,hl);
t_n=(0:(length(sig1)-1))*(1/fs);
subplot(4,1,4);
plot(t_n,sig1);
axis([0 50 -6 6])
xlabel("Time");
ylabel("Amplitude");
title("PAM Demodulation");