clc, clear all, close all
fs = 1E5;
t2 = 1/fs;
time = 0:t2:0.02;
f = 50;
last = length(time);
%Graph for Triangle and Three-phase Sinusoidal Waves
triangle = sawtooth(2*pi*500*(time+5E-4),0.5);
sinusoidal = 0.8*sin(2*pi*f*time);
sinusoidal2 = 0.8*sin((2*pi*f*time)+(120*pi/180));
sinusoidal3 = 0.8*sin((2*pi*f*time)+(240*pi/180));
figure(1)
plot(time, triangle)
hold on
plot(time, sinusoidal)
hold on
plot(time, sinusoidal2)
hold on
plot(time, sinusoidal3)
grid on
title(‘Triangle and Three-phase Sinusoidal Waves’)
%PWM for 0-Degree Phase Shifted
for var = 1:last
diff = sinusoidal(var)-triangle(var);
if diff > 0
pwm(var) = 1;
elseif diff == 0
pwm(var) = 0;
else
pwm(var) = -1;
end
var = var + t2;
end
figure(2)
plot(time, pwm)
grid on
title(‘PWM for 0-Degree Phase Shifted Sinusoidal Wave’)
%PWM for 120-Degree Phase Shifted
for var = 1:last
diff = sinusoidal2(var)-triangle(var);
if diff > 0
pwm2(var) = 1;
elseif diff == 0
pwm2(var) = 0;
else
pwm2(var) = -1;
end
var = var + t2;
end
figure(3)
plot(time, pwm2)
grid on
title(‘PWM for 120-Degree Phase Shifted Sinusoidal Wave’)
%PWM for 240-Degree Phase Shifted
for var = 1:last
diff = sinusoidal3(var)-triangle(var);
if diff > 0
pwm3(var) = 1;
elseif diff == 0
pwm3(var) = 0;
else
pwm3(var) = -1;
end
var = var + t2;
end
figure(4)
plot(time, pwm3)
grid on
title(‘PWM for 240-Degree Phase Shifted Sinusoidal Wave’)
% PWM for all Phases
figure(5)
plot(time, pwm)
hold on
plot(time, pwm2)
hold on
plot(time, pwm3)
grid on
title(‘PWM for all Phases’)
axis([0 0.02 -1 1.1])