%Interactively generate the output of a multiple and sinusoidal PWM shceme %for bi-polar output %% Initialization and Parameter Cell clear all close all clc %Parameters mf=26;%Freq. Modulation index (Even) M=0.2;%Initial value of Modulation index dM=0.1;%increment value of M wt=[0:0.0001:2*pi];%Frequency range %% UNIFORM PWM %Carrier R=(1+(2/pi)*asin(sin(mf*wt+pi/2))).*((wt<=pi)-(wt>=pi))/2; b=1; figure while b==1 subplot(2,1,1) SQW=((wt<=pi)-(wt>=pi));%square wave reference plot(wt,R,'k',wt,M*SQW,'r','LineWidth',1.5) line([0 2*pi],[0 0],'Color','k','LineWidth',0.8); axis([0 2*pi -1.2 1.2]) title(['M=',num2str(M)]) subplot(2,1,2) v_MPWM=(abs(M*SQW)>=abs(R)).*((wt<=pi)-(wt>=pi));%Multiple PWM plot(wt,v_MPWM,'r','LineWidth',1.5) line([0 2*pi],[0 0],'Color','k','LineWidth',0.8); axis([0 2*pi -1.2 1.2]) M=M+dM; [x,y,b]=ginput(1); end %% Sinusoidal PWM--Unidirectional Carrier %Carrier R=(1+(2/pi)*asin(sin(mf*wt-pi/2))).*((wt<=pi)-(wt>=pi))/2; b=1; figure while b==1 subplot(2,1,1) SW=sin(wt);%sinusoidal reference plot(wt,R,'k',wt,M*SW,'r','LineWidth',1.5) line([0 2*pi],[0 0],'Color','k','LineWidth',0.8); axis([0 2*pi -1.5 1.5]) title(['M=',num2str(M)]) subplot(2,1,2) v_MPWM=(abs(M*SW)>=abs(R)).*((wt<=pi)-(wt>=pi));%Multiple PWM plot(wt,v_MPWM,'r','LineWidth',1.5) line([0 2*pi],[0 0],'Color','k','LineWidth',0.8); axis([0 2*pi -1.2 1.2]) M=M+dM; [x,y,b]=ginput(1); end %% Sinusoidal PWM Bi-Polar Carrier mf=15;%Freq. Modulation index (Even) M=0.0;%Initial value of Modulation index dM=0.1;%increment value of M wt=[0:0.0001:2*pi];%Frequency range %Carrier R=(2/pi)*asin(sin(mf*wt)); b=1; figure while b==1 subplot(4,1,1) SW=sin(wt);%sinusoidal reference plot(wt,R,'k',wt,M*SW,'r',wt,-M*SW,'b','LineWidth',1.5) line([0 2*pi],[0 0],'Color','k','LineWidth',0.8); axis([0 2*pi -1.5 1.5]) title(['M=',num2str(M)]) subplot(4,1,2) G1=M*SW>=R; plot(wt,G1,'r','LineWidth',0.8) line([0 2*pi],[0 0],'Color','k','LineWidth',0.8); axis([0 2*pi 0 1.2]) subplot(4,1,3) G2=-M*SW>=R; plot(wt,G2,'b','LineWidth',0.8) line([0 2*pi],[0 0],'Color','k','LineWidth',0.8); axis([0 2*pi 0 1.2]) subplot(4,1,4) v_MPWM=G1-G2;%Multiple PWM plot(wt,v_MPWM,'r','LineWidth',1.5) line([0 2*pi],[0 0],'Color','k','LineWidth',0.8); axis([0 2*pi -1.2 1.2]) M=M+dM; [x,y,b]=ginput(1); end