Pulse Width Modulation or PWM is a technique which is used for getting Analog Results with digital means. We can say that some Digital Control or some Electronics algorithm is used to generate square waves. Square wave is in fact a signal which is generated through switching between ON & OFF states. There are no of ways to generate PWM. For example in modern electronics projects PWM is generated through some type of micro controllers or 555 Timers. If you recall my previous project tutorials, in which I have generated PWM through 555 timer. Since in this tutorial we are working with-in MATLAB premises so we will only discuss CODE and no hardware design involved in this tutorial. Now without wasting any time, I think we should move towards the CODE of the project. Stay tuned and believe me you will learn something new from this project.
You should also read:
First of all open your MATLAB software and a command window will appear. Now first thing to do is to clear the command window and remove all the previous variables or functions from MATLAB.
This is done through MATLAB language and we have commands to do this. The commands are given below:
clc clear all disp('Sinusoidal Pulse Width Modulation of AC Signal') disp(' ')
Vrin=1; f=input('The frequency of the input supply voltage, f = '); Z=1; ma=input('the modulation index,ma, (0<ma<1), ma = '); phi=input('the phase angle of the load in degrees = '); Q=input('The number of pulses per half period = ');
phi=phi*pi/180; R=Z*cos(phi); L=(Z*sin(phi))/(2*pi*f);
N=2*Q;
for k=1:2*N for j=1:50 i=j+(k-1)*50; wt(i)=i*pi/(N*50); Vin(i)=sqrt(2)*Vrin*sin(wt(i)); ma1(i)=ma*abs(sin(wt(i))); if rem(k,2)==0 Vt(i)=0.02*j; if abs(Vt(i)-ma*abs(sin(wt(i))))<=0.011 m=j; beta(fix(k/2)+1)=3.6*((k-1)*50+m)/N; else j=j; end else Vt(i)=1-0.02*j; if abs(Vt(i)-ma*abs(sin(wt(i))))ma*abs(sin(wt(i))) Vout(i)=0; else Vout(i)=Vin(i); end end end beta(1)=[];
disp(' ') disp('......................................................................') disp('alpha beta width') [alpha' beta' (beta-alpha)']
a=0; subplot(3,1,1) plot(wt,Vin,wt,a) axis([0,2*pi,-2,2]) title('Generation Of The Output Voltage Pulses ') ylabel('Vin(pu)'); subplot(3,1,2) plot(wt,Vt,wt,ma1,wt,a) axis([0,2*pi,-2,2]) ylabel('Vt, m(pu)'); subplot(3,1,3) plot(wt,Vout,wt,a) axis([0,2*pi,-2,2]) ylabel('Vo(pu)'); xlabel('Radian');
Vo =sqrt(1/(length(Vout))*sum(Vout.^2)); disp('The rms Value of the Output Voltage ') Vo y=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) THDVo = sqrt(Vo^2 -x(1)^2)/x(1);
m=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
for 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 CORMS = sqrt(sum(CO.^2)/(length(CO))); disp(' The RMS value of the load current is') CORMS THDIo = sqrt(CORMS^2-COX(1)^2)/COX(1);
for j2=1900*N+1:2000*N if Vout(j2)~=0 CS(j2)=C(j2); else CS(j2)=0; end end for j3=1:100*N CS1(j3)=CS(j3+1900*N); end CSRMS= sqrt(sum(CS1.^2)/(length(CS1))); disp('The RMS value of the supply current is') CSRMS CS2= fft(CS1); CS2(1)=[]; CSX=abs(CS2); CSX=(sqrt(2)/(100*N))*CSX; THDIS = sqrt(CSRMS^2-CSX(1)^2)/CSX(1); phi1 = atan(real(CS2(1))/imag(CS2(1)))-pi/2; PF=cos(phi1)*CSX(1)/CSRMS;
disp(' Performance parameters are') THDVo THDIo THDIS PF a=0; 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]); 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)) title(''); axis([0,100,0,0.8]); ylabel('Isn(pu)'); xlabel('Harmonic Order');
clc clear all disp('Sinusoidal Pulse Width Modulation of AC Signal') disp(' ') Vrin=1; f=input('The frequency of the input supply voltage, f = '); Z=1; ma=input('the modulation index,ma, (0<ma<1), ma = '); phi=input('the phase angle of the load in degrees = '); Q=input('The number of pulses per half period = '); phi=phi*pi/180; R=Z*cos(phi); L=(Z*sin(phi))/(2*pi*f); N=2*Q; for k=1:2*N for j=1:50 i=j+(k-1)*50; wt(i)=i*pi/(N*50); Vin(i)=sqrt(2)*Vrin*sin(wt(i)); ma1(i)=ma*abs(sin(wt(i))); if rem(k,2)==0 Vt(i)=0.02*j; if abs(Vt(i)-ma*abs(sin(wt(i))))<=0.011 m=j; beta(fix(k/2)+1)=3.6*((k-1)*50+m)/N; else j=j; end else Vt(i)=1-0.02*j; if abs(Vt(i)-ma*abs(sin(wt(i))))<0.011 l=j; alpha(fix(k/2)+1)=3.6*((k-1)*50+l)/N; else j=j; end end if Vt(i)>ma*abs(sin(wt(i))) Vout(i)=0; else Vout(i)=Vin(i); end end end beta(1)=[]; disp(' ') disp('..........................................') disp('alpha beta width') [alpha' beta' (beta-alpha)'] a=0; subplot(3,1,1) plot(wt,Vin,wt,a) axis([0,2*pi,-2,2]) title('Generation Of The Output Voltage Pulses ') ylabel('Vin(pu)'); subplot(3,1,2) plot(wt,Vt,wt,ma1,wt,a) axis([0,2*pi,-2,2]) ylabel('Vt, m(pu)'); subplot(3,1,3) plot(wt,Vout,wt,a) axis([0,2*pi,-2,2]) ylabel('Vo(pu)'); xlabel('Radian'); Vo =sqrt(1/(length(Vout))*sum(Vout.^2)); disp('The rms Value of the Output Voltage ') Vo y=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) THDVo = sqrt(Vo^2 -x(1)^2)/x(1); m=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 for 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 CORMS = sqrt(sum(CO.^2)/(length(CO))); disp(' The RMS value of the load current is') CORMS THDIo = sqrt(CORMS^2-COX(1)^2)/COX(1); for j2=1900*N+1:2000*N if Vout(j2)~=0 CS(j2)=C(j2); else CS(j2)=0; end end for j3=1:100*N CS1(j3)=CS(j3+1900*N); end CSRMS= sqrt(sum(CS1.^2)/(length(CS1))); disp('The RMS value of the supply current is') CSRMS CS2= fft(CS1); CS2(1)=[]; CSX=abs(CS2); CSX=(sqrt(2)/(100*N))*CSX; THDIS = sqrt(CSRMS^2-CSX(1)^2)/CSX(1); phi1 = atan(real(CS2(1))/imag(CS2(1)))-pi/2; PF=cos(phi1)*CSX(1)/CSRMS; disp(' Performance parameters are') THDVo THDIo THDIS PF a=0; 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]); 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)) title(''); axis([0,100,0,0.8]); ylabel('Isn(pu)'); xlabel('Harmonic Order');That's all for today. I have tried my best to explain it in detail but still if you get into some trouble then ask in comments.
JLCPCB – Prototype 10 PCBs for $2 (For Any Color)
China’s Largest PCB Prototype Enterprise, 600,000+ Customers & 10,000+ Online Orders Daily
How to Get PCB Cash Coupon from JLCPCB: https://bit.ly/2GMCH9w