clc;
clear all;
close all;
Fm= 20; % Message Signal frequency
Fc= 50; % Ramp signal frequency
A=5; % Amplitude of Ramp Signal
d=10; %Duration
fs=1000;
t=0:1/fs:d;
r=1 :2: (10d);
%Message Signal
m=A.sin(2*pi*F*m*t/(2*d));
subplot(6,1,1);
plot(t,m);
xlabel('Time');
ylabel('Amplitude');
title('Message Signal');
grid on;
%Sawtooth Wave
c=A.sawtooth(2*pi*F*c*t/(2*d));
subplot(6,1,2);
plot(t,c);
xlabel('Time');
ylabel('Amplitude');
title('Carrier Wave(Sawtooth)');
grid on;
%Pulse train x=pulstran(10*t,r,'rectpuls');
subplot(6,1,3);
plot(10*t,x);
xlabel("Time");
ylabel("Amplitude");
title("Pulse Train");
%PAM Modulation
sig=x.m;
subplot(6,1,4);
plot(t,sig);
xlabel("Time");
ylabel("Amplitude");
title("Pulse Amplitude Modulation(PAM)");
%PWM & PPM Modulation
n=length(c);
pwm(1)=0;
for i=1:n
if (m(i)>=c(i))
pwm(i)=1;
else
pwm(i)=0;
end
end
ppm(1)=0;
for i=1:n
if (pwm(i)==0 && pwm(i+1)==1)
ppm(i)=1;
else
ppm(i)=0;
end
end
subplot(6,1,5);
plot(t,pwm);
xlabel('Time');
ylabel('Amplitude');
title('Pulse Width Modulation(PWM)');
grid on;
subplot(6,1,6)
plot(t,pwm,t,ppm,'r');
xlabel('Time');
ylabel('Amplitude');
title('Pulse Position Modulation(PPM)');