You are on page 1of 1

clear all

close all
clf
set(0,'DefaultLineLineWidth',2);
subplot(4,1,1);
t=linspace(0,20,10000);
T=0.5;
tmp=mod(t,T);
w0=0.5;
y=8*tmp.*(tmp<w0)-2;
plot(t,y);
axis([0 20 -4 4]);
xlabel('Time(t)');
ylabel('Amplitude(Y)');
title('\bf SAW TOOTH WAVE FORM');
grid on;
subplot(4,1,2);
fs=0.1;
X=1.8;
x=X*sin(2*pi*fs*t);
plot(t,x);
xlabel('Time(t)');
ylabel('Amplitude(x)');
title('\bf SINE WAVE FORM');
axis([0 20 -4 4]);
grid on;
subplot(4,1,3);
plot(t,x,'r',t,y);
title('\bf COMPARING SIN AND SAWTOOTH');
xlabel('Time(t)');
ylabel('Amplitude');
grid on;
subplot(4,1,4);
for i=1:10000;
if (x(i)>=y(i))
z(i)=1;
else
z(i)=0;
end
end
plot(t,z);
xlabel('Time(t)');
ylabel('Amplitude');
title('\bf PWM WAVE');
axis([0 20 -1.5 1.5]);
grid on;

You might also like