0% found this document useful (0 votes)
64 views

Workshop Matlab/Simulink in Drives and Power Electronics: Lecture 1: Introduction To Matlab

Here are the steps to define the speed reference profile v_ref: 1. Define the time vector: time = 0:0.1:10; 2. Define the speed reference vector: v_ref = zeros(size(time)); v_ref(time>=3 & time<8) = 1.4; This defines v_ref as a vector of zeros the same size as time, with values of 1.4 between 3 and 8 seconds. 18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 16 / 24 Palestine Polytechnic University Ex 2: Plotting a Function

Uploaded by

ram
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Workshop Matlab/Simulink in Drives and Power Electronics: Lecture 1: Introduction To Matlab

Here are the steps to define the speed reference profile v_ref: 1. Define the time vector: time = 0:0.1:10; 2. Define the speed reference vector: v_ref = zeros(size(time)); v_ref(time>=3 & time<8) = 1.4; This defines v_ref as a vector of zeros the same size as time, with values of 1.4 between 3 and 8 seconds. 18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 16 / 24 Palestine Polytechnic University Ex 2: Plotting a Function

Uploaded by

ram
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Palestine Polytechnic University

Workshop
Matlab/Simulink in Drives
and Power Electronics
Lecture 1 : Introduction to Matlab

Ghislain REMY Jean DEPREZ


18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 1 / 24
Palestine Polytechnic University

Workshop Program
• 8 lectures will be presented based on Matlab/Simulink :
– 1 Introduction to Matlab
– 2 Introduction to Simulink
– 3 DC-Motor Control design
– 4 DC-Motor Chopper design SimPowerSystems
– 5 Introduction to Stateflow/Statechart
– 6 Induction Motor Inverter Control
– 7 Synchronous Motor Modeling
– 8 Synchronous Motor Control
• Two system applications (four quadrants electric drives of
mechanical systems) will be used as "conducting lines" during
the workshop.

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 2 / 24
Palestine Polytechnic University

Drives and Power Systems


• Presentation of the Structure of Industrial Drives and Power
Systems
– DC-Motor, Synchronous and Induction Motors
– Large applications domain
– Power Electronics (IGBT, MOSFET…)
– Classical Control Algorithm (Cascaded
Control Loop, Scalar and Vector Control…)

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 3 / 24
Palestine Polytechnic University

System applications:
Four quadrants electric drives of mechanical systems

1- ELEVATOR

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 4 / 24
Palestine Polytechnic University

0 .3 F _ R O T 1 .T O R Q U

0 .2

0 .1

-0 .1

-0 .2

-0 .3
-1 5 -1 0 -5 0 5 10 1 5M A S S _ R O T 1 .O

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 5 / 24
Palestine Polytechnic University

2- ARM of ROBOT

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 / 24
Palestine Polytechnic University

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 / 24
Palestine Polytechnic University

Design of Mechatronics System


• Model-based design  Simulation of the system is essential
• Multi-domain modeling (Mechanical, ElectroChemical, Thermal ,
Controls, Hydraulic, Electrical, Magnetic, Pneumatic…)

 Matlab/
Simulink
is a very
good tool
for this kind
of approach.

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 8 / 24
Palestine Polytechnic University

Matlab: General Presentation


• MATLAB environment integrates numerical calculation, advanced plot
function, visualization and an advanced programming language.
• MATLAB Product Family is composed of Toolboxes:
– Data-mining and Visualization ;
– Numerical and Symbolical Calculation;
– Modeling and Simulation ;
– Programming, Software and Graphical User Interface Design;
– Automatic conversion of MATLAB programs in C, C++ code.
The Toolboxes are advanced library of MATLAB functions
designed to bring solutions in applications.
They are written in MATLAB language with accessible source,
useful for develop your own algorithm.

Last version is
R2009a

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 9 / 24
Palestine Polytechnic University

Presentation of the Matlab Software


• Interface Presentation
Editor
Calculation
principles
Matrices

Workspace Figures

Variables
Editor

Command Window
18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 10 / 24
Palestine Polytechnic University

Select a Current Directory for MATLAB


• In the Command Window, type :
cd d:\Workshop\Ex01
So the Current Directory is changed in:
D:\Workshop\Ex01 Current Directory
Avoid in folder and file names:
• Blank space;
• Long name;
• Special symbol.

Verify the current directory using:


cd or pwd
-> MATLAB shows the folder name

Command Window
18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 11 / 24
Palestine Polytechnic University

Variables and Workspace


• MATLAB works using variables defined as :
scalar or vector or array or structure.
• The Variable names must respect the following rules:
– Maximum of 31 characters;
– The 1st character must be a letter;
– MATLAB differentiate majuscule from minuscule.
• Variables are saved in the Workspace
• It is not necessary to type or define variables.
– Amp = 1; adds automatically an Amp variable
• Variables are kept until explicit erase order, like:
– clear deletes all variables
– clear A B deletes A and B variables only
• Control whos et who show a list of current variables

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 12 / 24
Palestine Polytechnic University

Data Manipulation
• Data are managed using a vector representation, using an
Array type
• Some examples:
• A line vector is defined using: A = [1 2] or A = [1,2] A=
a space or , are used to change of column 1 2

• A row vector is defined using: B = [3;4] B=


3
; is used to change of line
4
• Transpose symbol: B = [3 4]’ B=
‘ is used to transpose a vector 3
4

• To include B inside C: C = [B [-1;5]] C=


3 -1
4 5
18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 13 / 24
Palestine Polytechnic University

Matrix Manipulation
• To multiply matrix A by a matrix B of the same size: A.*B
Examples : with A = [1 2]; B = [3 4]; A= 1 2 B=3 4
A.*B  3 8 (= 1*3 2*4) term to term product
• To multiply matrix A by a constant
A.*5  5 10 (= 1*5 2*5)
• To do a scalar product of matrix A by a matrix B :
A*B’ 11 (= 1*3 + 4*2)
• To do a concatenation
[A B]  1 2 3 4

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 14 / 24
Palestine Polytechnic University

Data retrieval of a Matrix


• To access to all columns of the x row: Matrix(x,:)
• To access to all rows of the y column: Matrix (:,y)
• To access to the x row of the y column: Matrix (x,y)
Examples :
>> C=[ 1 2 ; 3 4]
C=
1 2
3 4

>>C(:,1) >> C(2,:) >> C(2,1)


ans = ans = ans =
1 3 4 3
3

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 15 / 24
Palestine Polytechnic University

Ex 1: Speed Reference Definition


• Obj: Add a v_ref variable with the following profile:
|v|
• Time is a discrete signal 1.4 m.s-1
with a fixed step size:
t

• time = t_init : t_step_size : t_final T1=3s T2=5 s

Examples: t = 0:1:10
time =
Columns 1 through 11
0 1 2 3 4 5 6 7 8 9 10

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 16 / 24
Palestine Polytechnic University

The Plot function:


• plot(x1,y1,’s1’,x2,y2,’s2’, …)
– x : table of the x-axis values
– y : table of the y-axis values
– s : character string:
• The colors
• The line types
• The plot symbols
• The syntax is the same
using the semilogx,
semilogy, loglog command
plot(x,y,'m*:'); %plots a magenta dotted line with a star at
each data point
plot(x,y,'rs'); % plots a red square at each data point, but
does not draw any line because no line was selected
plot(x,y,'rs−'); % connects the data points with a solid line

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 17 / 24
Palestine Polytechnic University

Examples of Plot functions and options


Three−phases waveforms
PLOT(X,Y) plots vector Y versus vector X.
If X or Y is a matrix, then the vector is
plotted versus the rows or columns of the
matrix, whichever line up. If X is a scalar
and Y is a vector, disconnected line objects
are created and plotted as discrete points
vertically at X.

x=linspace(0, 2*pi, 60);


PLOT(Y) plots the columns of Y versus
% pi is a built−in function in MATLAB; their index.
% we could have used x=0:0.02*pi:2*pi
or x = (0: 0.02: 2)*pi instead; If Y is complex, PLOT(Y) is equivalent to
y=sin(x); u=sin(x+2*pi/3); v=sin(x+4*pi/3); PLOT(real(Y),imag(Y)).
% The x−axis must be specified for each function
plot(x,y,x,u,x,v);
% Turn grid and axes box on In all other uses of PLOT, the imaginary
grid on; box on; part is ignored.
text(0.75, 0.65, 'sin(x)');
text(2.85, 0.65, 'sin(x+2*pi/3)');
text(4.95, 0.65, 'sin(x+4*pi/3)')
18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 18 / 24
Palestine Polytechnic University

To Plot a function: a detailled procedure


t = 0 :200e-6 :50e-3 ; % definition of a time vector
w = 314 ;
plot(t,sin(w*t)) ; % show the plot of sin(wt)
hold on ; % avoid to erase previous plot
plot(t,0.8*sin(w*t-pi/3),’--’)

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 19 / 24
Palestine Polytechnic University

Modification of a figure
• The figure properties can be modified using the button:
Edit Plot
Then, selection can be
made using left clicking
on the figure:
Line, Axis, Background…
And can be modified
by selecting:
Show Property Editor

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 20 / 24
Palestine Polytechnic University

Some other Matlab commands


• Previous command can be recall by using :
– the up and down arrows of the keyboard
– Type one or more characters and then use the up or down arrow to
recall only the command starting with the typed characters
• Example: if a plot function have been already used
you can recall it by typing ‘pl’ then pushing the up arrow.
path List the known directory in MATLAB
help plot Help on the ‘plot’ function
type fichier Show the content of an ASCII File
whos, who List all the variables of the Workspace
clear Clear all the variables of the Workspace
!, dos Give an access to the Operating System (OS)
cd, dir, mkdir Command of the OS available in MATLAB
exit, quit End of the MATLAB session

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 21 / 24
Palestine Polytechnic University

The m-file
• Previous commands used in the Command Window can be re-
used in a text file : the “m-file” (due to the .m extension)

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 22 / 24
Palestine Polytechnic University

To create a function
• To create a function toto returning a variable z calculated from
two parameters x and y:
z = toto(x,y);
• Create m-file with the name toto.m:
function f=toto(u,v)
f=u+3*v^2
• Call this function
z=toto(2,3)
ans=
29

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 23 / 24
Palestine Polytechnic University

18-21 May 2009 Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 / 24

You might also like