% PWM Examples of three-phase Inverter--AC Output % This file demonstrates the AC output of a PWM inverter for different % modulation indeces. The modulation index is incremented every time clicking the left % mouse button on the figure. Click the right mouse button to stop. % The file contains two independent cells. The first cell dipicts the % control signals of the inverter and the phase voltages. % The second cell gives the output harmonics as the user changes the % modulation index. %% Control signals and Phase Voltage v. Modulation index %Enter the frequency modulation index below. close all;clear all;clc %Data mf=9;%frequency modulation index: Odd multiple of 3. %Calculations fr=1;%reference frequency fc=mf*fr;%carrier frequency t=0:(1/80/fc):1/fr;%normalized time tp=360*t;%Degrees ph=0*pi/180;%phase shift for visual effect tha=2*pi*fr*t+ph;thb=2*pi*fr*t-2*pi/3+ph;thc=2*pi*fr*t+2*pi/3+ph;%argument of phase a, b, and c reference sine trc=2*asin(sin(2*pi*fc*t+mf*ph))/pi;%carrier % % Plot Carrier and the three reference signals % figure b=1; m=0; while b==1 vra=m*sin(tha);vrb=m*sin(thb);vrc=m*sin(thc);%Reference waveforms ga=(vra>=trc);%Gate signal for phase a gb=(vrb>=trc);%Gate signal for phase b gc=(vrc>=trc);%Gate signal for phase c vab=ga-gb;vbc=gb-gc;vca=gc-ga;%line-to-line voltage subplot(4,2,1) plot(tp,trc,'k',tp,vra,'r',tp,vrb,'b',tp,vrc,'g') set(gca,'PlotBoxAspectRatio',[5,1,1]) axis([0 360 -1.5 1.5]) line([0 360],[0 0],'Color','k','LineStyle','--') title(['Freq. Mod. Indx, m_f=',num2str(mf),'; Ampl. Mod. Indx, m=',num2str(m)]) %legend('Carrier','phase a','phase b','phase c','Location','SouthOutside','Orientation','Horizontal') subplot(4,2,3) plot(tp,ga,'r') line([0 360],[0 0],'LineStyle','--','Color','k') axis([0 360 0 1.2]) title('Phase a Gate Signal') xlabel('Degs') subplot(4,2,5) plot(tp,gb,'b') line([0 360],[0 0],'LineStyle','--','Color','k') axis([0 360 0 1.2]) title('Phase b Gate Signal') xlabel('Degs') subplot(4,2,7) plot(tp,gc,'g') line([0 360],[0 0],'LineStyle','--','Color','k') axis([0 360 0 1.2]) title('Phase c gate Signal') xlabel('Degs') subplot(4,2,4) plot(tp,vab,'r') line([0 360],[0 0],'LineStyle','--','Color','k') axis([0 360 -1.2 1.2]) title('Vab') xlabel('Degs') subplot(4,2,6) plot(tp,vbc,'b') line([0 360],[0 0],'LineStyle','--','Color','k') axis([0 360 -1.2 1.2]) title('Vbc') xlabel('Degs') subplot(4,2,8) plot(tp,vca,'g') line([0 360],[0 0],'LineStyle','--','Color','k') axis([0 360 -1.2 1.2]) title('Vca') xlabel('Degs') if m<1.5; m=m+0.1;else;m=m+0.5;end [x,y,b]=ginput(1); if m>30; b=0; end end %% Harmonic Output % clear all;close all;clc mf=21;%Frequency modulation index: Odd multiple of 3. %Calculations fr=1;%reference frequency fc=mf*fr;%carrier frequency harmn=0:3*mf+5;%Harmonic numbers to be plotted t=0:(1/60/fc):1/fr;%normalized time tp=360*t;%Degrees ph=-120*pi/180;%phase shift for visual effect tha=2*pi*fr*t+ph;thb=2*pi*fr*t-2*pi/3+ph;thc=2*pi*fr*t+2*pi/3+ph;%argument of phase a, b, and c reference sine trc=2*asin(sin(2*pi*fc*t+mf*ph))/pi;%carrier figure b=1; m=0; while b==1 vra=m*sin(tha);vrb=m*sin(thb);vrc=m*sin(thc);%Reference waveforms ga=(vra>=trc);%Gate signal for phase a gb=(vrb>=trc);%Gate signal for phase b gc=(vrc>=trc);%Gate signal for phase c vab=ga-gb;vbc=gb-gc;vca=gc-ga;%line-to-line voltage Vab=fft(vab)/length(t);Vab(2:end)=2*Vab(2:end);%Fourier Series vab1=abs(Vab(2))*cos(2*pi*fr*t+angle(Vab(2)));%Fundamental of the line voltage THD=100*sqrt(sum(abs(Vab(3:end/2-1)).^2))/abs(Vab(2)); subplot(3,1,1) plot(tp,trc,'k',tp,vra,'r',tp,vrb,'b',tp,vrc,'g') axis([0 360 -1.5 1.5]) line([0 360],[0 0],'Color','k','LineStyle','--') title(['Freq. Mod. Indx, m_f=',num2str(mf),'; Ampl. Mod. Indx, m=',num2str(m)]) subplot(3,1,2) plot(tp,vab,'r',tp,vab1,'k') line([0 360],[0 0],'LineStyle','--','Color','k') axis([0 360 -1.2 1.2]) title(['Voltage v_a_b and its Fundamental, v_a_b_1=',num2str(abs(Vab(2)))]) xlabel('Degs') subplot(3,1,3) bar(harmn,abs(Vab(harmn+1))) axis([0 harmn(end) 0 1.15]) title(['Harmonics of v_a_b, ','%THD=',num2str(THD)]) xlabel('Harmonic Order') if m<1.5; m=m+0.1;else;m=m+0.5;end [x,y,b]=ginput(1); if m>30; b=0; end end