Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
matlab code for pwm inverter m file
#1

matlab code for pwm inverter m file

PWM (Pulse Width Modulation) can be easily generated in MATLAB using simple MATLAB functions. We have already discussed about PWM generator circuit using 741 Op-amp in previous posts. In PWM, width of the pulses are varied according to the amplitude of AF message signal. PWM is basically an analog pulse modulation technique. It does modulation of the duty cycle of the pulse.
In addition to its use in communication systems, PWM is also used in voltage regulators such as Switched Mode Power Supplies (SMPS) to control the power delivered to the load. PWM can be generated using a comparator to which the modulating signal and a reference ramp (sawtooth) waveform are fed.The code for PWM simulation in MATLAB is shown below. The use of particular line of MATLAB code is also given as comments (%Comment field). The given MATLAB program accepts two input frequencies from the user.

clc;
clear all;
close all;
F2=input( Message frequency= );
F1=input( Carrier Sawtooth frequency= );
A=5;
t=0:0.001:1;
c=A.*sawtooth(2*pi*F1*t);%Carrier sawtooth
subplot(3,1,1);
plot(t,c);
xlabel( time );
ylabel( Amplitude );
title( Carrier sawtooth wave );
grid on;
m=0.75*A.*sin(2*pi*F2*t);%Message amplitude must be less than Sawtooth
subplot(3,1,2);
plot(t,m);
xlabel( Time );
ylabel( Amplitude );
title( Message Signal );
grid on;
n=length©;%Length of carrier sawtooth is stored to n
for i=1:n%Comparing Message and Sawtooth amplitudes
if (m(i)>=c(i))
pwm(i)=1;
else
pwm(i)=0;
end
end
subplot(3,1,3);
plot(t,pwm);
xlabel( Time );
ylabel( Amplitude );
title( plot of PWM );
axis([0 1 0 2]);%X-Axis varies from 0 to 1 & Y-Axis from 0 to 2
grid on;

% Author: Rashmil Dahanayake
% 3 Phase Inverter, Sinusoidal PWM
% Simulated with LC filter + RL load
% 31/12/2013
% Ref Chapter 8-4-1 Power electronics: converters, applications, and design. N. Mohan and T. M. Undeland,

clc;
clear all;

% Simulation settings
st=0.1; % simulation period in seconds
Ts=1e-6; % sampling peiod in seconds
t=0:TsConfusedt; % define time range

% Triangular carrier wave
f= 3e3; % switching frequency in Hz
ref= 2/pi*asin(sin(2*pi*t*f)); % carrier signal

Vdc=400; %input DC voltage
m=1; % modulation index

% control signal
fo=50; %output voltage frequncy in Hz -- 120^ phase shifted sinusoids
Cont=m*sin([2*pi*fo*t; 2*pi*fo*t+2*pi/3 ; 2*pi*fo*t+4*pi/3 ]);

% Inverter Circuit derive pole voltages
V_A0=(Cont(1,Smile>=ref)*Vdc/2 + (Cont(1,Smile<ref)*-Vdc/2 ;
V_B0=(Cont(2,Smile>=ref)*Vdc/2 + (Cont(2,Smile<ref)*-Vdc/2 ;
V_C0=(Cont(3,Smile>=ref)*Vdc/2 + (Cont(3,Smile<ref)*-Vdc/2 ;

% Line to Line voltages
V_AB=V_A0 - V_B0;
V_BC=V_B0 - V_C0;
V_CA=V_C0 - V_A0;

% Load Neutral voltage
V_Nn=(V_A0+V_B0+V_C0)/3;

% Phase Voltages
V_An=(V_AB-V_CA)/3; % same as V_An=2/3 *V_A0 - 1/3 *(V_B0+V_C0)
V_Bn=2/3*V_B0 + 1/3*(V_A0+V_C0);
V_Cn=(V_CA-V_BC)/3;

%Load Parameters
Lload = 2e-3; %Load inductance
Rload= 5; % Load resistance

%Filter Parameters
Lf= 10e-3; % Inductance for output filter
Cf= 20e-6; % Capacitance for output filter

% state space equations for LC filter
A=[zeros(3,3) eye(3)/(3*Cf) -eye(3)/(3*Cf); -eye(3)/Lf zeros(3,3) zeros(3,3);
eye(3,3)/Lload zeros(3,3) -eye(3)*Rload/Lload]; % systemmatrix
B=[zeros(3,3); eye(3)/Lf; zeros(3,3)]; % coefficient for thecontrol variable u
C=eye(9); % coefficient for the output y
D=zeros(9,3); % coefficient for the output y
Ks = 1/3*[-1 0 1; 1 -1 0; 0 1 -1]; % Conversion matrix to transform [iiAB iiBC iiCA] to [iiA iiB iiC]

%Transfer function for inverter output stage
sys= ss(A,B,C,D); % state space model of a LC filter + RL load
U=[V_AB;V_BC;V_CA]; % input for the system (sys)

% calculating filtered output
% Y=H(1,1) * V_AB; tf method

[y1,t1]=lsim(sys,U,t); % solving state space equations
% <--Columns 1 to 9 of Y1 represent
% VAB,VBC,VCA,ILf_AB,ILf_BC,ILf_CA,ILload_AB,ILload_BC,ILload_CA-->

% Plots
figure('Position',[175+100 70 760 555],'name','Switching'); % raw output from inverter
subplot(3,1,1); % reference signals
plot(t,ref,'g',t,Cont);title('Switching ref & carrier signal');
axis([st/5 st/5+.01 -1.1 1.1]);grid on;

subplot(3,1,2); %line-to-line
plot(t,V_AB,'b');title('Line to Line inverter output Voltages');
axis([st/5 st/5+.01 -Vdc Vdc]);grid on;

subplot(3,1,3); % Phase voltages
plot(t,V_Bn,'r');title('Phase Voltages');
axis([st/5 st/5+.01 -2/3*Vdc 2/3*Vdc]); grid on;

figure('Position',[175+3*100 70 760 555],'name','Filtered output'); % inverter output connected to LC filter and RL load
plot(t1,y1(:,1));grid on; title('Line to line load voltage');
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Powered By MyBB, © 2002-2024 iAndrew & Melroy van den Berg.