PWM inverter code

download PWM inverter code

of 5

Transcript of PWM inverter code

  • 7/29/2019 PWM inverter code

    1/5

    % A Program For Analysis of a Voltage-source inverter with Sinusoidal-Pulse-Width Modulated output.% By: Yasin A. Shiboul% Date 16/3/2004%% PART I (preparation)% In this part the screen is cleared, any other functions, figures and% variables are also cleared. The name of the programm is displayed.clcclear alldisp('Voltage-source inverter with Sinusoidal-Pulse Width Modulated output')disp(' By Yasin Shiboul ')disp('')%% PART II% In this part the already known variables are entered, the user is% asked to enter the other variables.% Vrin is the DC input voltage.Vrin=1;% f is the frequency of the output voltage waveform.f=input('The frequency of the output voltage, f = ');% Z is the load impedance in per unit.Z=1;% ma is the modulation index

    ma=input('the modulation index,ma, (0

  • 7/29/2019 PWM inverter code

    2/5

    % finding the time stepwt(i)=i*pi/(N*50);%finding the half period of the output voltage.if(sin(wt(i)))>0

    hpf=1;else

    hpf=-1;end% calculating the modulating signal.ma1(i)=ma*abs(sin(wt(i)));

    % calculating the sawtooth waveformif rem(k,2)==0

    Vt(i)=0.02*j;if abs(Vt(i)-ma*abs(sin(wt(i))))

  • 7/29/2019 PWM inverter code

    3/5

    subplot(2,1,2)plot(wt,Vout,wt,a)axis([0,2*pi,-2,2])ylabel('Vo(pu)');xlabel('Radian');

    % PART VIII% Analyzing the output voltage waveform

    % Finding the rms value of the output voltageVo =sqrt(1/(length(Vout))*sum(Vout.^2));disp('The rms Value of the output Voltage = ')Vo% finding the harmonic contents of the output voltage waveformy=fft(Vout);y(1)=[];x=abs(y);x=(sqrt(2)/(length(Vout)))*x;disp('The rms Value of the output voltage fundamental component = ')x(1)%% Findint the THD of the output voltageTHDVo = sqrt(Vo^2 -x(1)^2)/x(1);%

    % PART IX% calculating the output current waveformm=R/(2*pi*f*L);DT=pi/(N*50);C(1)=-10;%i=100*N+1:2000*N;Vout(i)=Vout(i-100*N*fix(i/(100*N))+1);%for i=2:2000*N;C(i)=C(i-1)*exp(-m*DT)+Vout(i-1)/R*(1-exp(-m*DT));end%

    %% PART X% Analyzing the output current waveform% finding the harmonic contents of the output current waveformfor j4=1:100*N

    CO(j4)=C(j4+1900*N);CO2= fft(CO);CO2(1)=[];COX=abs(CO2);COX=(sqrt(2)/(100*N))*COX;end% Finding the RMS value of the output current.

    CORMS = sqrt(sum(CO.^2)/(length(CO)));disp(' The RMS value of the load current =')CORMS%Finding the THD for the output currentTHDIo = sqrt(CORMS^2-COX(1)^2)/COX(1);% PART XI% Finding the supply current waveform%

  • 7/29/2019 PWM inverter code

    4/5

    for j2=1900*N+1:2000*Nif Vout(j2)~=0

    CS(j2)=abs(C(j2));elseCS(j2)=0;

    endend% PART XII% Analyzing the supply current waveform%% Supply current waveform and its average valuefor j3=1:100*N

    CS1(j3)=abs(CS(j3+1900*N));endCSRMS= sqrt(sum(CS1.^2)/(length(CS1)));disp('The RMS value of the supply current is')CSRMSCSAV= (sum(CS1)/(length(CS1)));disp('The Average value of the supply current is')CSAV

    % Finding the Fourier analysis of the supply current waveform%

    CS2= fft(CS1);CS2(1)=[];CSX=abs(CS2);CSX=(sqrt(2)/(100*N))*CSX;% PART XIII% Displaying the calculated parameters.disp(' Performance parameters are')THDVoTHDIoa=0;

    %%PART XIV

    % Openning a new figure window for plotting of% the output voltage,output current, supply current and the harmonic% contents of these values%figure(2)%subplot(3,2,1)plot(wt,Vout(1:100*N),wt,a);title('');axis([0,2*pi,-1.5,1.5]);ylabel('Vo(pu)');%%

    subplot(3,2,2)plot(x(1:100))title('');axis([0,100,0,0.8]);ylabel('Von(pu)');%subplot(3,2,3)plot(wt,C(1900*N+1:2000*N),wt,a);title('');axis([0,2*pi,-1.5,1.5]);

  • 7/29/2019 PWM inverter code

    5/5

    ylabel('Io(pu)');%subplot(3,2,4)plot(COX(1:100))title('');axis([0,100,0,0.8]);ylabel('Ion(pu)');%subplot(3,2,5)plot(wt,CS(1900*N+1:2000*N),wt,a);axis([0,2*pi,-1.5,1.5]);ylabel('Is(pu)');xlabel('Radian');%subplot(3,2,6)plot(CSX(1:100))holdplot(CSAV,'*')text(5,CSAV,'Average valu')title('');axis([0,100,0,0.8]);ylabel('Isn(pu)');xlabel('Harmonic Order');