Vous êtes sur la page 1sur 16

CHAPTER ONE: INTRODUCTION TO MATLAB

What is MATLAB?

MATLAB is numeric computation software for engineering and scientific calculation.


The name MATLAB stands for MATRIX LABORATORY.

MATLAB is basically a high level language which has many specialized toolboxes for
making things easier for us

MATLAB has a rich set of plotting capabilities. The graphics are integrated in
MATLAB. Since MATLAB is also a programming environment, a user can extend the
functional capability of MATLAB by writing new module.

MATLAB Desktop

On Windows systems MATLAB is started by double-clicking the MATLAB icon on the desktop
or by selecting MATLAB from the start menu.

MATLAB has an extensive graphical interface. When MATLAB starts, the MATLAB window
will appear, with several sub windows and menu bars.

If you cannot see all windows in default go to the menu desktop->desktop layout->
default.

The menu bar at the top of the MATLAB window contains a set of buttons and pull-down menus
for working with M-files, windows, preferences and other settings, web resources for MATLAB,
and online MATLAB help. If a window is docked and selected, its menu bar appears at the top of
the MATLAB window.

The starting procedure takes the user to the Command window where the Command line is
indicatedwith >>. Used in the calculator mode all MATLAB commands are entered to the
command line from the keyboard.

MATLAB is started by clicking the mouse on the appropriate icon and is ended by typing exit or
by using the menu option. After each MATLAB command, the "return" or "enter" key must be
depressed.

Collected by D.M1
MATLAB as a Calculator

The basic arithmetic operators are + - * / ^ and these are used in conjunction with brackets: ( ).
The symbol^ is used to get exponents (powers): 2^4=16.

You should type in commands shown following the prompt: >>.

>> 2 + 3/4*5

ans =

5.7500

Is this calculation 2 + 3/ (4*5) or 2 + (3/4)*5? MATLAB works according to the


priorities:

1. Quantities in brackets,

2. Powers 2 + 3^2 2 + 9 = 11,

3. * /, working left to right (3*4/5=12/5),

4. + -, working left to right (3+4-5=7-5),

Collected by D.M2
Thus, the earlier calculation was for 2 + (3/4)*5 bypriority 3.

Variables

Variables are assigned numerical values by typing the expression directly, for example, typing

a = 1+2

yields: a =

The answer will not be displayed when a semicolon is put at the end of an expression, for
example type

a = 1+2;.

b = 2*a;

To determine the value of a previously defined quantity, type the quantity by itself:b

yields: b =

Example

>> 3-2^4

ans =

-13

>>ans*5

ans =

-65

The result of the rst calculation is labeled ans by MATLAB and is used in the second
calculation where its value is changed

We can use our own names to store numbers:

>> x = 3-2^4

Collected by D.M3
x=

-13

>> y =

x*5

y=

-65

So that x has the value 13 and y = 65. These canbe used in subsequent calculations. These are
examplesof assignment statements: values are assigned tovariables. Each variable must be
assigned a value beforeit may be used on the right of an assignment statement

CHAPTER TWO: CONTROL SYSTEM USING MATLAB

The Laplace Transform

MATLAB has a command to obtain the partial-fraction expansion of B(s)/A(s). It also has a
command to obtain the zeros and poles of B(s)/A(s).

Commands covered: tf2zp, zp2tf, cloop, feedback, parallel, series

Transfer functions are defined in MATLAB by storing the coefficients of the numerator and the
B( s)
denominator in vectors. Given a continuous-time transfer function H ( s)=
A (s)

Collected by D.M4
For example,

Command tf by defining the

Collected by D.M5
Command zpk

To find the zeros, poles and gain of a transfer function from the vectors num and den which
contain the coefficients of the numerator and denominator polynomials, type

[z,p,k] = tf2zp(num,den)

Example

[z,p,k]=tf2zp([1 1],[1 2 1])

z=-1, p=-1;-1, k=1

The zeros are stored in z, the poles are stored in p, and the gain is stored in k. To find the
numerator and denominator polynomials from z, p, and k, type [num,den] = zp2tf(z,p,k)

tf2zp: converts the numerator, denominator from coefficient to roots.

[Z,P,K] = TF2ZP(NUM,DEN)

zp2tf: converts the numerator, denominator from roots to coefficient.

[NUM,DEN] = ZP2TF(Z,P,K)

Class Work (Mark 12%; 2point Each)

1. Consider the following transfer function; find the zeros, poles and gain.

a.

b.

Collected by D.M6
c.
2. Given the zero(s), pole(s), and gain K of B(s)/A(s), obtain the function B(s)/A(s) using
MATLAB. Consider the three cases below.
a. There is no zero. Poles are at -1 + 2j and -1 - 2j. K = 10.
b. A zero is at 0. Poles are at -1 + 2j and -1 - 2j. K = 10.
c. A zero is at -1. Poles are at -2, -4 and -8. K = 12

Frequency Response Plots

To compute the frequency response H (w) of a transfer function, store the numerator and
denominator of the transfer function in the vectors num and den. Define a vector w that contains
the frequencies for which H (w) is to be computed, for example w = a: b: c wherea is the lowest
frequency, c is the highest frequency and b is the increment in frequency. The command

H = freqs (num,den,w)

returns a complex vector H that contains the value of H( w) for each frequency in w.

To draw a Bode plot of a transfer function which has been stored in the vectors num and den,
typeBode(num,den)

To customize the plot, first define the vector w which contains the frequencies at which the Bode
plot will be calculated. Since w should be defined on a log scale, the command logspaceis used.
For example, to make a Bode plot ranging in frequencies from 10-1to 102, define w by

w = logspace(-1,2);

The magnitude and phase information for the Bode plot can then be found be executing:

[mag,phase] = bode (num,den,w);

To plot the magnitude in decibels, convert mag using the following command:

magdb = 20*log10(mag);

To plot the results on a semilog scale where the y-axis is linear and the x-axis is logarithmic,
typesemilogx(w,magdb)

for the log-magnitude plot and typesemilogx(w,phase)

Collected by D.M7
for the phase plot. The phase plot may contain jumps of 2 p which may not be desired. To
remove these jumps, use the command unwrapsprior to plotting the phase.

semilogx(w,unwrap(phase))

CHAPTER THREE: MODELING USING MATLAB

DC MOTOR MODELING

1. Physical System

Consider a DC motor, whose electric circuit of the armature and the free body diagram of the
rotor are shown in figure blow

Figure 1: Schematic representation of the considered DC motor

The rotor and the shaft are assumed to be rigid. Consider the following values for the physical
parameters:

Moment of inertia of the rotor J = 0.01 kg m2


Damping (friction) of the mechanical system b = 0.1 Nms
(back-) electromotive force constant K = 0.01 Nm/A
Electric resistance R= 1
Electric inductance L = 0.5 H

The input is the armature voltage V in Volts (driven by a voltage source). Measured variables are
the angularvelocity of the shaft in radians per second, and the shaft angle in radians.

2. System Equations

Collected by D.M8
The motor torque, T, is related to the armature current, i, by a constant factor K:

T = Ki. (1)

The back electromotive force (emf),Vb, is related to the angular velocity by:

Vb = K = K (d/ dt) (2)

From Figure 1 we can write the following equations based on the Newtons law combined with
the Kirchhoffslaw:

3. Transfer Function

Using the Laplace transform, equations (3) and (4) can be written as:

where s denotes the Laplace operator. From (6) we can express I(s):

and substitute it in (5) to obtain:

This equation for the DC motor is shown in the block diagram in blow.

Collected by D.M9
Figure 2: A block diagram of the DC motor.

From equation (8), the transfer function from the input voltage, V (s), to the output angle, ,
directly follows:

From the block diagram in Figure 2, it is easy to see that the transfer function from the input
voltage, V (s), tothe angular velocity, , is:

MATLAB Representations

The above transfer function can be entered into MATLAB by dening the numerator and
denominator polynomials, using the conventions of the MATLABs Control Toolbox. The
coefcients of a polynomial in s areentered in a descending order of the powers of s.

Example: The polynomial A = 3s3 + 2s + 10 is in MATLAB entered as: A = [3 0 2 10].

Open the M-le motor.m. It already contains the denition of the motor constants:
J=0.01;
b=0.1;
K=0.01;
R=1;
L=0.5;

The transfer function (9) can be entered in MATLAB in a number of different ways.

Collected by D.M10
1. As Ga (s) can be expressed as Gv (s) 1/s, we can enter these two transfer functions
separately andcombine them in series:

aux = tf(K,conv([L R],[J b]))


Gv = feedback(aux,K);
Ga = tf(1,[1 0])*Gv;

Here, we made use of the function feedback to create a feedback connection of two transfer
functionsand the multiplication operator *, which is overloaded by the LTI class of the Control
System Toolboxsuch that is computes the product of two transfer functions.

2. Instead of using convolution, the rst of the above three commands can be replaced by
the product oftwo transfer functions:

aux = tf(K,[L R])*tf(1,[J b]);

3. Another possibility (perhaps the most convenient one) is to dene the transfer function in
a symbolicway. First introduce a system representing the Laplace operator s
(differentiator) and then enter thetransfer function as an algebraic expression:

s = tf([1 0],1);
Gv = K/((L*s + R)*(J*s + b) + K2);
Ga = Gv/s;
It is convenient to label the inputs and outputs by the names of the physical variables they
represent:
Gv.InputName=Voltage;
Gv.OutputName=Velocity;
Ga.InputName=Voltage;
Ga.OutputName=Angle;

Now by calling motor from the workspace, we have both the velocity (Gv) and the position
(Ga) transferfunctions dened in the workspace.

Exercises (10 Mark)

1. Convert Gv and Ga into their respective state-space (function ss) and zero-pole-
gain (function zpk) representations.

2. What are the poles and zeros of the system? Is the system stable? Why?

Collected by D.M11
CHAPTER FOUR: CONTROL DESIGN

Let us design a PID feedback controller to control the velocity of the DC motor. Recall that the
transferfunction of a PID controller is:

whereu is the controller output (in our case the voltage V ), e = uc y is the controller input
(the controlerror), and Kp , Kd , Ki are the proportional, derivative and integral gains,
respectively. A block diagram ofthe closed-loop system is given in figure blow.

Figure 5: Closed-loop system with a PID controller.

Proportional Control

First, try a simple proportional controller with some estimated gain, say, 100. To compute the
closed-looptransfer function, use the feedback command. Add the following lines to your m-le:

Kp = 100;
Gc = feedback(Gv*Kp,1);

Collected by D.M12
Gc.InputName = Desired velocity;

Here Gc is the closed-loop transfer function. To see the step response of the closed-loop system,
enter: figure(4); step(Gc,0:0.01:2);

You should get the plot given in Figure blow:

Figure 6: Closed-loop step response with a P controller.

Note: -To eliminate the steady-state error, an integral action must be used.
-To reduce the overshoot, a derivativeaction can be employed.

PID Control

Let us try a PID controller. Edit your M-le so that it contains the following commands:

Kp = 1;
Ki = 0.8;
Kd = 0.3;
C = tf([KdKp Ki],[1 0]);
rlocus(Ga*C);
Kp = rlocfind(Ga*C);
Gc = feedback(Ga*C*Kp,1);
figure(c); step(Gc,0:0.01:5)

The rlocus and rlocnd functions are used to select the overall gain of the PID controller, such
that the controller is stable and has the desired location of the poles (within the dened ratio
among the Kp , Ki and Kdconstants). If the design is not satisfactory, this ratio can be changed, of
course. We should obtain a plotsimilar to the one in figure blow:

Collected by D.M13
Figure 7: Closed-loop step response with a PID controller.

Exercise (10 marks)

1. Use the root locus and the Nyquist criterion to nd out for what value of the gain
Kp the proportionalcontroller for the angle Ga (s) becomes unstable.

Collected by D.M14
Collected by D.M15
Collected by D.M16

Vous aimerez peut-être aussi