dt=1e-6; %time step
period=100e-6; %PWM period, must be an integer multiple of dt
time=[0:dt:period-dt]; %create time array ranging from 0 to period-dt
duty=0.5; %duty cycle of each waveform
Von=20; %value during on time
Voff=0; %value during off time
G1phase=0; %phase of G1 as percentage of one period
G2phase=1/3; %phase of G2
G3phase=2/3; %phase of G3
G0=zeros(1,round(period/dt));
G0(:)=Voff;
G0(1:round(period*duty/dt))=Von; %Go is now a prototype gate waveform with 0 phase
G1=circshift(G0,[0,round(period/dt*G1phase)]); %create all three gate waveforms over one period
G2=circshift(G0,[0,round(period/dt*G2phase)]);
G3=circshift(G0,[0,round(period/dt*G3phase)]);
figure(1); plot(time,G1,time,G2,time,G3) %plot them
axis([0 period Voff-1 Von+1])