%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % spwm3ph.m - Determines switching angles for SPWM % ( bi-state, natural sampling ) for % use in 3-phase inverters. % Triangular carrier symmetric about zero. % Plots Fourier spectrum. % Uses alf.m % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear; global cglob cglob = zeros(1,5); angle = zeros(1,1); time = zeros(1,1); N=15; T=1/60; Tc=T/(2*N-1); % T - period of fundamental N - chops/half cycle % MI - modulation index Ac - amplitude of carrier MI=1.0; Ac=10; A=MI*Ac; if MI>1 | MI<0; disp( 'CAUTION: MI>1 or MI<0'); end m=8*Ac*N/T; w=2*pi/T; for i=1:511; x(i)=Ac; end for k=1:N td = (k-1)*Tc; x0 = Tc/2; cglob = [ m w A 2*Ac td ]; alfa = fzero( 'alf', x0 ); alfa = alfa + td; time = [ time; alfa ]; angle = [ angle; alfa*360/T ]; x0 = 0.75*Tc; cglob = [-m w A -4*Ac td ]; alfa = fzero( 'alf', x0 ); alfa = alfa + td; time = [ time; alfa ]; angle = [ angle; alfa*360/T ]; end angle = [ angle; 180 ]; time = [ time; T/2 ]; x = zeros(1,1024); y = zeros(1,1024); t = linspace(0,T/2,512); k = length( time ); y = A*sin( w*t ); n=2; for i=1:512 if n > k-2, break, end if t(i) < time(n); x(i)=Ac; elseif t(i) >= time(n) & t(i) <= time(n+1); x(i)=-Ac; else; x(i)=Ac; n=n+2; end end for i=1:512; x(i+512)=-x(i); y(i+512)=-y(i); end clc; alphas = angle' % Display alphas to screen disp('Hit any key to continue'); clf; pause t=linspace(0,T,1024); % Generate the a-b-c switching patterns wrt dc link midpoint. xa=x/2; xb=zeros(1,1024); xc=xb; xphi=xb; for i=1:341; xb(i)=xa(i+683); end for i=1:683; xb(i+341)=xa(i); end for i=1:341; xc(i)=xb(i+683); end for i=1:683; xc(i+341)=xb(i); end V=[ 0 T -Ac/2-1 Ac/2+1 ]; axis(V); figure(1); plot(t,xa); grid; title('PHASE a SWITCHING PATTERN'); xlabel('TIME - s'); ylabel('NODE a POTENTIAL wrt SOURCE MID-POINT'); pause; % Generate phase a voltage for i=1:1024; xphi(i)=(2*xa(i)-xb(i)-xc(i))/3; end % Pulse mitigation to remove short state durations. ND = 2; % min allowable switch time in degrees( 1 deg min ) k = length(xphi); kp = fix( ND/360*1024 ); if kp<1; kp=1; end for i=1:k-kp if xphi(i+1)>xphi(i) & xphi(i+kp)~=xphi(i+1); xphi(i+1)=xphi(i); end if xphi(i+1)