MATLAB MODULES FOR CONTROL SYSTEM PRINCIPLES AND …

228
MATLAB MODULES 1 | Page [email protected] [email protected] MATLAB MODULES FOR CONTROL SYSTEM PRINCIPLES AND DESIGN Welcome to the MATLAB Modules for Control Systems Principles and Design. They are designed to help you learn how to use MATLAB for the analysis and design of automatic control systems. The flow of the modules is given by the box below. Throughout the modules, you will find links to all of the modules. Links are also given to come back to this page (Home), and to the complete index. We are interested to hear how you use the modules and your suggestions for improvements ; feedback link has been included for this purpose. We focus on MATLAB Version 7. For the most part, the material applies to 6x version as well. MATLAB continues to evolve as a software tool, However, the basic operation of MATLAB and its basic capabilities have, more or less, stabilized around the optimum level. Dramatic changes are not expected in near future; the material, therefore ,will continue to apply to 7x version as well. We envision that you will follow along with these modules by running MATLAB/Simulink in one window and the modules in another. You should be able to run most of the MATLAB/Simulink programs by copying and pasting MATLAB scripts between windows, and by downloading Simulink files. If you find that the font is too hard to read, you can change the default font in your browser. Module 1 MATLAB Window Environment and the BASE Program Module 2 Control System Toolbox and Symbolic Math Toolbox Module 3 Simulink Module 4 Feedback System Simulation Module 5 Time Response Characteristics and LTI Viewer Module 6 Stability Analysis on Root Locus Plots Module 7 Root Locus Design and SISO Design Tool Module 8 Stability Analysis on Bode/Nyquist Plots Module 9 Frequency Response Characteristics Module 10 Frequency Response Design

Transcript of MATLAB MODULES FOR CONTROL SYSTEM PRINCIPLES AND …

MATLAB MODULES

1 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULES FOR

CONTROL SYSTEM PRINCIPLES AND DESIGN

Welcome to the MATLAB Modules for Control Systems Principles and Design. They are

designed to help you learn how to use MATLAB for the analysis and design of automatic control

systems. The flow of the modules is given by the box below. Throughout the modules, you will

find links to all of the modules. Links are also given to come back to this page (Home), and to

the complete index. We are interested to hear how you use the modules and your suggestions for

improvements ; feedback link has been included for this purpose. We focus on MATLAB

Version 7. For the most part, the material applies to 6x version as well. MATLAB continues to

evolve as a software tool, However, the basic operation of MATLAB and its basic capabilities

have, more or less, stabilized around the optimum level. Dramatic changes are not expected in

near future; the material, therefore ,will continue to apply to 7x version as well. We envision that

you will follow along with these modules by running MATLAB/Simulink in one window and the

modules in another. You should be able to run most of the MATLAB/Simulink programs by

copying and pasting MATLAB scripts between windows, and by downloading Simulink files. If

you find that the font is too hard to read, you can change the default font in your browser.

Module 1 MATLAB Window Environment and the BASE Program

Module 2 Control System Toolbox and Symbolic Math Toolbox

Module 3 Simulink

Module 4 Feedback System Simulation

Module 5 Time Response Characteristics and LTI Viewer

Module 6 Stability Analysis on Root Locus Plots

Module 7 Root Locus Design and SISO Design Tool

Module 8 Stability Analysis on Bode/Nyquist Plots

Module 9 Frequency Response Characteristics

Module 10 Frequency Response Design

MATLAB MODULES

2 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 1

MATLAB Window Environment and the Base Program

Starting MATLAB

On the Windows desktop, the installer usually creates a shortcut icon for starting MATLAB;

double-clicking on this icon opens MATLAB desktop.

The MATLAB desktop is an integrated development environment for working with MATLAB

suite of toolboxes, directories, and programs. We see in Fig. M1.1 that there are four panels,

which represent:

1. Command Window

2. Current Directory

3. Workspace

4. Command History

A particular window can be activated by clicking anywhere inside its borders.

MATLAB MODULES

3 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M1.1 MATLAB Desktop (version 7.0, release 14)

Desktop layout can be changed by following Desktop --> Desktop Layout from the main menu

as shown in Fig. M1.2 (Default option gives Fig. M1.1).

MATLAB MODULES

4 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M1.2 Changing Desktop Layout to History and Command Window option

Command Window

We type all our commands in this window at the prompt ( >> ) and press return to see the

results of our operations. Type the command ver on the command prompt to get information

about MATLAB version, license number, operating system on which MATLAB is running,

JAVA support version, and all installed toolboxes. If MATLAB don't regard to your speed of

reading and flush the entire output at once, just type more on before supplying command to see

one screen of output at a time. Clicking the What's New button located on the desktop shortcuts

toolbar, opens the release notes for release 14 of MATLAB in Help window. These general

release notes give you a quick overview of what products have been updated for Release 14.

Working with Command Window allows the user to use MATLAB as a versatile scientific

calculator for doing online quick computing. Input information to be processed by the MATLAB

commands can be entered in the form of numbers and arrays.

MATLAB MODULES

5 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

As an example of a simple interactive calculation, suppose that you want to calculate the torque (

T ) acting on 0.1 kg mass ( m ) at swing of the pendulum of length ( l ) 0.2 m. For small

values of swing, T is given by the formula . This can be done in the MATLAB command

window by typing:

>> torque = 0.1*9.8*0.2*pi/6

MATLAB responds to this command by:

torque =

0.1026

MATLAB calculates and stores the answer in a variable torque (in fact, a array) as soon as

the Enter key is pressed. The variable torque can be used in further calculations. is

predefined in MATLAB; so we can just use pi without declaring it to be 3.14….Command

window indicating these operations is shown in Fig. M1.3.

MATLAB MODULES

6 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M1.3 Command Window for quick scientific calculations ( text in colored boxes

corresponds to explanatory notes ).

If any statement is followed by a semicolon,

>> m = 0.1;

>> l = 0.2;

>> g = 9.8;

the display of the result is suppressed. The assignment of the variable has been carried out even

though the display is suppressed by the semicolon. To view the assignment of a variable, simply

type the variable name and hit Enter. For example:

>> torque=m*g*l*pi/6;

>> torque

torque =

MATLAB MODULES

7 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

0.1026

It is often the case that your MATLAB sessions will include intermediate calculations whose

display is of little interest. Output display management has the added benefit of increasing the

execution speed of the calculations, since displaying screen output takes time.

Variable names begin with a letter and are followed by any number of letters or numbers

(including underscore). Keep the name length to 31 characters, since MATLAB remembers only

the first 31 characters. Generally we do not use extremely long variable names even though they

may be legal MATLAB names. Since MATLAB is case sensitive, the variables A and a are

different.

When a statement being entered is too long for one line, use three periods, … , followed by

to indicate that the statement continues on the next line. For example, the following

statements are identical (see Fig. M1.4).

>> x=3-4*j+10/pi+5.678+7.890+2^2-1.89

>> x=3-4*j+10/pi+5.678...

+7.890+2^2-1.89

+ addition, subtraction, * multiplication, / division, and ^ power are usual arithmetic

operators.

The basic MATLAB trigonometric commands are sin, cos, tan, cot, sec and csc. The inverses

, etc., are calculated by asin, acos, etc. The same is true for hyperbolic

functions. Some of the trigonometric operations are shown in Fig M1.5.

Variables j = and i = are predefined in MATLAB and are used to represent complex

numbers.

MATLAB MODULES

8 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M1.4 Command Window with example operations

MATLAB MODULES

9 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M1.5 Example trigonometric calculations

MATLAB representation of complex number :

or

The later case is always interpreted as a complex number, whereas, the former case is a complex

number in MATLAB only if j has not been assigned any prior local value.

MATLAB representation of complex number :

or

or

In Cartesian form, arithmetic additions on complex numbers are as simple as with real numbers.

Consider two complex numbers and . Their sum is given

by

MATLAB MODULES

10 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

For example, two complex numbers and can be added in MATLAB as:

>> z1=3+4j;

>> z2=1.8+2j;

>> z=z1+z2

z =

4.8000 + 6.0000i

Multiplication of two or more complex numbers is easier in polar/complex exponential form.

Two complex numbers with radial lengths and are given with angles

and rad. We change to radians to give rad= rad.

The complex exponential form of their product is given by

This can be done in MATLAB by:

>> theta1=(35/180)*pi;

>> z1=2*exp(theta1*j);

>> z2=2.5*exp(0.25*pi*j);

>> z=z1*z2

z =

0.8682 - 4.9240j

Magnitude and phase of a complex number can be calculated in MATLAB by commands abs

and angle. The following MATLAB session shows the magnitude and phase calculation of

complex numbers and .

>> abs(5*exp(0.19*pi*j))

MATLAB MODULES

11 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

ans =

5

>> angle(5*exp(0.19*pi*j))

ans =

0.5969

>> abs(1/(2+sqrt(3)*j))

ans =

0.3780

>> angle(1/(2+sqrt(3)*j))

ans =

-0.7137

Some complex numbered calculations are shown in Fig. M1.6.

MATLAB MODULES

12 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M1.6 Example complex numbered calculations

The mathematical quantities and are calculated with exp(x), log10(x), and

log(x), respectively.

All computations in MATLAB are performed in double precision . The screen output can be

displayed in several formats. The default output format contains four digits past the decimal

point for nonintegers. This can be changed by using the format command. Remember that the

format command affects only how numbers are displayed, not how MATLAB computes or

saves them. See how MATLAB prints in different formats.

Format command at MATLAB prompt Display format

format short 31.4159

format short e 3.1416e+001

format long 31.41592653589793

format long e 3.141592653589793e+001

MATLAB MODULES

13 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

format short g 31.416

format long g 31.4159265358979

format bank 31.42

The following exercise will enable the readers to quickly write various mathematical formulas,

interpreting error messages, and syntax related issues.

Exercise M1.1

i. By using arbitrary values of , check that .

ii. Verify with a few arbitrary values of that .

iii. Verify with a few arbitrary values of that .

iv. For t =0, 2, 5, 7, 12 and 25, find the value of the function

.

Exercise M1.2

1. Try entering complex number in MATLAB as 3+j4 and check the answer.

Initialize and then enter 3+4j, 3+j*4, and 3+4*j and check the various

answers. Interpret messages given by MATLAB.

2. Calculate magnitude and phase of the following complex numbers for

using MATLAB.

a.

b. .

3. Use MATLAB to calculate the magnitude and phase of for

MATLAB MODULES

14 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Exercise M1.3

1. Calculate the quantity for .

2. Calculate for .

Note: Inf, and NaN are predefined in MATLAB. NaN stands for Not-a-Number and results from

undefined operations like 0/0. Inf represents .

Current Directory Window

This window (Fig. M1.7) shows the directory, and files within the directory which are in use

currently in MATLAB session to run or save our program or data. The default directory is

„C:\MATLAB7\work'. We can change this directory to the desired one by clicking on the square

browser button near the pull-down window.

MATLAB MODULES

15 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M1.7 Current directory window

One can also use command line options to deal with directory and file related issues. Some

useful commands are shown in Table M1.1.

Table M1.1

Command Usage

cd, pwd To see the current directory

cd .. To go one directory back from the current directory

cd \ To go back to the root directory

MATLAB MODULES

16 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

cd dir_name To change to the directory named dir_name

ls or dir To see the list of files and subdirectories within the current directory

what Lists MATLAB-specific files in the directory. MATLAB specific files are with the

extensions .m, .mat, .mdl, .mex, and .p.

mkdir (parentdir,dir_name)

mkdir dir_name

Makes new directory with the name dir_name in the parent directory specified by

parentdir .

When supplied with only dir_name, it creates new directory within the current

directory

delete file_name

delete *.m

Deletes file from the current directory.

Deletes all m-files from the current directory.

MATLAB desktop snapshot showing selected commands from Table M1.1 are shown in Fig.

M1.8.

Workspace

Workspace window shows the name, size, bytes occupied, and class of any variable defined in

the MATLAB environment. For example in Fig.M1.9, „b' is 1 X 4 size array of data type

double and thus occupies 32 bytes of memory. Double-clicking on the name of the variable

opens the array editor (Fig. M1.10). We can change the format of the data (e.g., from integer to

floating point), size of the array (for example, for variable A, from 3 X 4 array to 4 X 4 array)

and can also modify the contents of the array.

MATLAB MODULES

17 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M1.8 Example directory related commands

If we right-click on the name of a variable, a menu pops up, which shows various operations for

the selected variable, such as: open the array editor, save selected variable for future usage, copy,

duplicate, and delete the variable, rename the variable, editing the variable, and various plotting

options for the selected variable.

MATLAB MODULES

18 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M1.9 Entries in the Workspace

Fig. M1.10 Array editor window

MATLAB MODULES

19 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Workspace related commands are listed in Table M1.2.

Table M1.2

Command Usage

who Lists variables currently in the workspace

whos Lists more information about each variable including size, bytes stored in the

computer, and class type of the variables

clear Clears the workspace. All variables are removed

clear all

Removes all variables and functions from the workspace. This can also be

done by selecting Edit from the main menu bar and then clicking the option

Clear Workspace .

clear var1 var2 Removes only var1 and var2 from the workspace.

For example, see the following MATLAB session for the use of who and whos commands.

>> who

Your variables are:

A b

>> whos

Name Size Bytes Class

A 3x4 96 double array

b 1x4 32 double array

Grand total is 16 elements using 128 bytes

Command History Window

This window (Fig. M1.11) contains a record of all the commands that we type in the command

window. By double-clicking on any command, we can execute it again. It stores commands from

one MATLAB session to another, hierarchically arranged in date and time. Commands remain in

the list until they are deleted.

MATLAB MODULES

20 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M1.11 Command history window

Commands can also be recalled with the up-arrow key. This helps in editing previous

commands.

Selecting one or more commands and right-clicking them, pops up a menu, allowing users to

perform various operations such as copy, evaluate, or delete, on the selected set of commands.

For example, two commands are being deleted in Fig. M1.12.

MATLAB MODULES

21 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 1

MATLAB Window Environment and the Base Program

Getting Help

MATLAB provides hundreds of built-in functions covering various scientific and engineering

computations. With numerous built-in functions, it is important to know how to look for

functions and how to learn to use them.

For those who want to look around and get a feel for the MATLAB computing environment by

clicking and navigating through what catches their attention, a window- based help is a good

option. To activate the Help window, type helpwin or helpdesk on command prompt or start the

Help Browser (Fig. M1.13) by clicking the icon from the desktop toolbar.

Fig. M1.12 Command history window with two commands being deleted

MATLAB MODULES

22 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

If you know the exact name of a command, type help commandname to get detailed task-

oriented help. For example, type help helpwin in the command window to get the help on the

command helpwin .

If you don't know the exact command, but (atleast !) know the keyword related to the task you

want to perform, the lookfor command may assist you in tracking the exact command. The help

command searches for an exact command name matching the keyword, whereas the lookfor

command searches for quick summary information in each command related to the keyword. For

example, suppose that you were looking for a command to take the inverse of a matrix.

MATLAB does not have a command named inverse; so the command help inverse will not

work. In your MATLAB command window try typing lookfor inverse to see the various

commands available for the keyword inverse.

MATLAB has a wonderful demonstration program that shows its various features through

interactive graphical user interface. Type demo at the MATLAB prompt to invoke the

demonstration program (Fig. M1.14) and the program will guide you throughout the tutorials.

MATLAB MODULES

23 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M1.13 Help browser

Fig. M1.14 Demonstration Window

Elementary Matrices

Basic data element of MATLAB is a matrix that does not require dimensioning. To create the

matrix variable in MATLAB workspace, type the statement (note that any operation that assigns

a value to a variable, creates the variable, or overwrites its current value if it already exists).

>> A=[8 1 6 2;3 5 7 4;4 9 2 6]

The blank spaces (or commas) around the elements of the matrix rows separate the elements.

Semicolons separate the rows. For the above statement, MATLAB responds with the display

A =

MATLAB MODULES

24 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

8 1 6 2

3 5 7 4

4 9 2 6

Vectors are special class of matrices with a single row or column. To create a column vector

variable in MATLAB workspace, type the statement

>> b=[1; 1; 2; 3]

b =

1

1

2

3

To enter a row vector, separate the elements by a space or comma ' , '. For example:

>> b=[1,1,2,3]

b =

1 1 2 3

We can determine the size of the matrices (number of rows, number of columns) by using the

size command.

>> size(A)

ans =

3 4

The command size, when used with the scalar option, returns the length of the dimension

specified by the scalar. For example, size (A,1) returns the number of rows of A and size(A,2)

returns the number of columns of A.

>> size(A,1)

ans =

MATLAB MODULES

25 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

3

>> size(A,2)

ans =

4

For matrices, the length command returns either number of rows or number of columns,

whichever is larger. For example,

>> length(A)

ans =

4

For vectors, length command can be used to determine its number of elements.

>> length(b)

ans =

4

The use of colon ( : ) operator plays an important role in MATLAB. This operator may be used

to generate a row vector containing the numbers from a given starting value xi, to the final value

xf, with a specified increment dx, e.g., x=[xi:dx:xf]

>> x=[0:0.1:1]

x =

Columns 1 through 7

0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000

Columns 8 through 11

0.7000 0.8000 0.9000 1.0000

By default, the increment is taken as unity.

To generate linearly equally spaced samples between x1 and x2, use the command

linspace(x1,x2) . By default, 100 samples will be generated. The command linspace (x1,x2, N)

allows the control over number of samples to be generated. See the example below.

MATLAB MODULES

26 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

>> x=linspace(0,1,11)

x =

Columns 1 through 6

0 0.1000 0.2000 0.3000 0.4000 0.5000

Columns 7 through 11

0.6000 0.7000 0.8000 0.9000 1.0000

Learn how to generate logarithmically spaced vector using the command logspace .

The colon operator can also be used to subscript matrices. For example, A(:,j) is the jth

column

of A, and A(i,:) is the ith row of A. Observe the following MATLAB session.

>> A=[8 1 6 2;3 5 7 4;4 9 2 6];

>> A(2,:)

ans =

3 5 7 4

>> A(3,2:4)

ans =

9 2 6

>> A(1,3)

ans =

6

>> B=A(1:3,2:3)

B =

1 6

5 7

9 2

MATLAB MODULES

27 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

>> A(:,3)=[ ]

A =

8 1 2

3 5 4

4 9 6

Manipulating matrices is almost as easy as creating them. Try the following operations:

>> A+3

>> A-3

>> A*3

>> A/3

When you add/subtract/multiply/divide a vector/matrix by a number (or by a variable with a

number assigned to it), MATLAB assumes that all elements of vector/matrix should be

individually operated on.

Table M1.3 provides the list of basic operations on any two arbitrary matrices A and B and their

dimensional requirements.

Table M1.3 Basic matrix operations

Operation Operator Example Notes

Plus + A+B Must be of same dimensions

Minus - A-B Must be of same dimensions

Multiply * A*B Must be of compatible dimensions

Multiply (element-by-

element) .* A.*B

Must be of same dimensions; multiplies element aij

with element bij

MATLAB MODULES

28 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Divide (element-by-element) ./ A./B Must be of same dimensions; divides element aij by

element bij

Divide (element-by-element) .\ A.\B Must be of same dimensions; divides element bij by

element aij

Matrix power ^ A^k k must be a constant, A must be a square matrix

Matrix power (element-by-

element) .^ A.^k k is a constant, A can be of any dimensions;

gives (aij)k

Example M1.1

To find the solution of the following set of linear equations:

we write the equations in the matrix form as

where

is the matrix of coefficients of x1, x2 and x3

is the column vector which will contain the solutions x1, x2 and x3

is the column vector of values on the right-hand side

The solution vector

MATLAB MODULES

29 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

where stands for adjoint of matrix and stands for determinant of

The determinant of matrix

is a scalar-valued function of . It is found through the use of minors and cofactors.

The minor mij of the element aij is the determinant of a matrix of order obtained

from by removing the row and column containing aij. The cofactor cij of the element aij is

defined by the equation

Determinants can be evaluated by an expansion that reduces the evaluation of an

determinant down to the evaluation of a string of determinants, namely

the cofactors. Selecting an arbitrary row k of matrix or arbitrary column l of matrix , we

have

or

MATLAB MODULES

30 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

The adjoint of matrix is found by replacing each element aij of matrix by its cofactor

and then transposing.

Following MATLAB commands solve the given set of simultaneous linear equations.

>> A = [2 5 -3; 3 -2 4; 1 6 -4];

>> b = [6; -2; 3];

>> x = inv(A) * b

x =

4.8333

-4.5833

-6.4167

MATLAB MODULES

31 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Exercise M1.4

Consider three matrices A, B, and C given below. Perform the following operations: A+B, B-C, A*C, A.*B,

A./C, A.\B, A./B, (B*C)^3, and C.^3. Countercheck MATLAB answers manually. Try to interpret errors, if

any.

Exercise M1.5

Create a vector t with 10 elements 1,2,.,10. Calculate for and , where .

Exercise M1.6

Create a vector t with initial time and final time with an interval of 0.05. Calculate

i.

ii.

Flow Control Functions

There are many flow control functions in MATLAB. The for function in MATLAB provides a

mechanism for repeatedly executing a series of statements a given number of times. The for

function connected to an end statement sets up a repeating circulation loop. An important point

is that each for must be matched with an end . The break statement provides exit jump out of

loop.

The while function in MATLAB allows a mechanism for repeatedly executing a series of

statements an indefinite number of times, under control of a logical condition.

MATLAB MODULES

32 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

The function if evaluates a logical expression and executes a group of statements based on the

value of the expression. The else statement further conditionalizes the if statement.

MATLAB MODULES

33 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 1

MATLAB Window Environment and the Base Program

Plotting

MATLAB is an outstanding tool for visualization. In the following, we will learn how to create

and print simple plots.

We are going to plot sinusoidal oscillations with exponential decay. To do this, first generate the

data ( x- and y- coordinates). x- coordinate in this case is time steps. Let the initial time =0

sec and final time =10 sec with an interval of 0.05 sec. y- coordinate is the value of sinusoidal

oscillations represented by . This plot can be generated by entering the

following commands.

>> t=0:0.05:10; % Generating time steps

>> yt=exp(-t/2).*sin(2*pi*t); %Calculate y(t )

>> plot(t,yt); %Plot t vs. y(t )

>> grid on; %Generating grids on x- and y-coordinates

>> xlabel('Time Steps: t --->'); %Labeling x-axis

>> ylabel('Sinusoid with exponential decay: y(t) --->'); %Labeling y-axis

>> title('Plotting exp(-t/2)*sin(2*pi*t)'); %Put a title on the plot

Response is shown in graphics or figure window snapshot (Fig. M1.15).

Arguments of the xlabel, ylabel, and title commands are text strings. Text strings are entered

within single-quote characters. Lines beginning with % are comments; these lines are not

executed. The print command sends the current plot to the printer connected to your computer.

Rather than displaying the graph as a continuous curve, one can show the unconnected data

points. To display the data points with small stars, use plot(t,yt,'*'). To show the line through the

data points in red color as well as the distinct data points, one can combine the two plots with the

MATLAB MODULES

34 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

command plot(t,yt,'r',t,yt,'*'). To learn more about plot options, type help plot on the

MATLAB prompt and hit return.

One can also produce multiple plots in a single window. Enter the following sequence of

commands to your MATLAB command window and observe the resultant figure (Fig. M1.16).

Fig. M1.15 Plotting sinusoid with exponential decay

>> subplot(3,1,1);plot(sin(2*pi*t));

>> title('plot of sin(2*pi*t)');

MATLAB MODULES

35 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

>> subplot(3,1,2);plot(exp(-t/2));

>> title('plot of exp(-t/2)');

>> subplot(3,1,3);plot(exp(-t/2).*sin(2*pi*t));

>> title('multiply above two plots to get this');

Fig. M1.16 Plotting multiple plots in a single figure window

The command subplot(m,n,p) breaks the figure window into an m-by-n matrix of small axes and

selects the pth axes for the current plot. Labeling, title, and grid commands should be given

immediately after the particular subplot command to apply them to that subplot. Learn more

about subplot using help subplot .

MATLAB MODULES

36 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Click on the Plot Editor icon once and then double click anywhere in the plot to open the

Property Editor - Axes window (Fig M1.17). Using this property editor, title, axes, scale etc...

of the plot can be changed.

Double clicking anywhere exactly on the curve opens the Property Editor – Lineseries (Fig

M1.18). From this, plot type can be changed on the spot. Available plot options are: Line, Area,

Bar, Stairs, and Stem. Line width and markers can be changed by pull down menu Line and

Marker.

Fig. M1.17 Axes property editor

Fig. M1.18 Lineseries property editor

MATLAB MODULES

37 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Exercise M1.7

Generate 50 linearly spaced time steps between 0 and 10. Calculate for:

1. and ,3, and 5. Plot all the three curves in a single figure.

2. k =3 and . Plot all the three curves in a single figure.

Both the plots should be with respect to time. In both the plots, mark each curve with its k and values ( Hint: Use Insert

Text Box option from main menu bar). From the main menu bar, choose Tools Edit Plot and then click anywhere on

a curve. Plot Editor will open. Try several available options. Further to this, do the following:

1. Create legends for both the plots.

2. Use zoom-in and zoom-out tools.

3. Rotate plots using 3D rotation tool.

4. Click on the Data Cursor icon. Move mouse pointer anywhere in the graph sheet. A cross-hair cursor will appear. Clicking the

cross-hair on the curve will give corresponding and axis values. Use Data Cursor to observe values at various time steps.

Exercise M1.8

Assign 0.5, , and to , respectively. Calculate for t =

[0:0.1:10].

Obtain three plots for . Title the graph and label the Draw

all the three plots on the same graph sheet and mark each curve with appropriate value.

Exercise M1.9

1. Study the commands semilogx, semilogy, and loglog using help command.

MATLAB MODULES

38 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

2. Consider the complex number . Using MATLAB, generate the following two plots on

semilog graph sheet for . Use subplot. Title both the plots, label the axes, and generate grid.

a)

b)

Hint: Use logspace command to generate 100 logarithmically spaced samples of between 0.01 and 1000 rad/sec. Use

abs and angle commands for calculations as per ii(a) and ii(b) given above for each Use semilogx to plot.

MATLAB MODULE 1

MATLAB Window Environment and the Base Program

Script files (M-files)

Type edit on MATLAB prompt and hit enter (or follow File New M-File option from the

main menu bar or click on icon in main toolbar). An Editor/Debugger window will open.

This is where you write, edit, create, can run from, and save your own programs (user created

script files with sequences of MATLAB commands) in files called M - files . An example M-file

is shown in Fig. M1.19.

Create the same file in your MATLAB editor and then use the option File Save or File

Save As to save the file with the name decayed_sin.m in current working directory. You can

save all files into your personalized directory. If your personal directory is immediately below

the directory in which the MATLAB application program is installed ( e.g. , c:\MATLAB7p0),

then all user written files are automatically accessible to MATLAB. If you want to store files

somewhere else, then you need to specify the path to the files using the path or addpath

MATLAB MODULES

39 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

command, or change the current working directory to the desired directory before you run the

program. For example, your script file is in the directory my_dir, which is not the current

working directory of the MATLAB. If the location of my_dir is „ c:\docume~1\control\ my_dir

', it can be included in the MATLAB search path by:

>> path(path, ‘c:\docume~1\control\my_dir');

or

>> addpath ‘c:\docume~1\control\my_dir';

To remove specified directory from the MATLAB search path, use the command rmpath .

Learn more about MATLAB search path through online help.

Type simply the name of the file decayed_sin to execute it from the command window. Script

can also be saved and executed simultaneously by clicking the icon in the main toolbar.

To open the existing M-file from the MATLAB command window, type edit filename (or follow

File Open option from the main menu bar or click on icon in the main toolbar).

All variables created during the runtime of the script file are left in the workspace. Using who or

whos , you can get information about them, and also access them by workspace window.

Exercise M1.10

Modify the script file written in Fig. M1.20 in the following way:

1. An error message should prompt, if final time is less than initial time

2. In addition to initial and final time, and time constant, the program should prompt the user to enter the amplitude of

the sine wave.

3. It should plot the Yt curve; however, wherever Yt crosses the zero-axes, an indication through x -mark should

appear.

4. Display current date and time at the end. (Hint: Learn commands date and clock using online help).

5. Calculate the total execution time of the program. (Hint: Learn tic and toc commands).

MATLAB MODULES

40 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Exercise M1.11

Learn more about 1) For loops, 2) While Loops, and 3) If-Else-End constructions using online help.

Fig. M1.19 Example M-file

MATLAB MODULES

41 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 1

MATLAB Window Environment and the Base Program

Developing user-defined Functions

Suppose you want to write a function to generate and plot N data points of the exponentially-

decaying sinusoid of amplitude A, frequency f, and exponential time-constant . A MATLAB

function which can take all these parameters as arguments and provide decaying sinusoid as an

output is shown in Fig. M1.20.

Generate an M-file with the code given in Fig.M1.20. When you attempt to save the file, editor

will automatically assign a function name decaying_sin to your M-file. Save the function to the

current working directory or include your personal directory into MATLAB search path by using

addpath command. We must avoid duplicating function names with built-in MATLAB functions

or keywords.

A function file begins with a function definition line, which contains the keyword function, a

well-defined list of input and output arguments, and function name. Some examples of function

definition are given below (execute help function for details):

function [ph, mag] = complex (z)

function [r,theta] = polar_form(a, b)

function decaying_sin( )

function sys_response( )

The first commented line just after the function definition is called the H1 line. This line is

automatically catalogued in the contents.m file of the directory in which function file resides.

This allows the line to be searched by the lookfor command. Very carefully chosen keywords

related to your function should come in the H1 line. Note that if there is any blank space before

the % sign in the H1 line, then it is no longer H1 line !!

All comment lines immediately following the function definition line and immediately before the

first executable statement of the function are displayed by MATLAB if help is asked on the

function. Type

>> help decaying_sin

and see what MATLAB displays.

MATLAB MODULES

42 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Input-argument names used in the function are local to the function; so arbitrary variable

names can be used to call the function. The name of another function can also be passed as an

input variable. The following are examples of legal function calls:

MATLAB MODULES

43 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M1.20 DECAYING_SIN Function

>> Yt = decaying_sin (time_span, time_const, mag, freq, pts)

In this case, input variables time_span, time_const, mag, freq, and pts must be defined before

the function call.

>> res = decaying_sin ([0 10], tau, 3, 50, 1000)

Here the input variable tau must be defined beforehand; all other inputs have been defined in the

function call.

>> sig = decaying_sin ([0,10], 2, 3, 50, 100)

Here all the inputs have been specified in the call statement.

>> decaying_sin ([0,10], 3, 0.5, 60, 100)

In this case, the output is assigned to generic variable ans.

MATLAB MODULES

44 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Exercise M1.12

1. Execute decaying_sin function with less than four and greater than five arbitrary arguments and interpret the messages. Study nargin and nargout commands through online help.

2. Execute decaying_sin function with tspan = [-1 10] and tspan=[3 0] and interpret the messages.

3. Execute the function as Yt = decaying_sin([0 5], 3, 0.5, 50). What is the length of the vector Yt ?

4. In some applications we don't want to generate the plot every time. We may need only output given by the function. Modify the above function with one more input argument ‘str' to provide control over whether we want to generate the plot or not? If str = ‘Y' or ‘y', then it should generate the plot. If str = ‘N' or ‘n', then it should not. If any other character is passed, then it should give the error message ‘Unrecognized user input' and terminate the program. You also need to modify processing with the nargin command.

Exercise M1.13

Write a function named specifications with the following input and output arguments:

Input arguments:

1. vector tspan of initial and final times.

2. Scalars y0 0, zeta , wn, and theta.

3. Character argument str controlling whether to plot the final result or not.

4. Scalar N of number of data points required to be generated.

Output arguments:

1. Yt calculated by

2. Tau calculated by

3. Tr calculated by

4. Tp calculated by

MATLAB MODULES

45 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

5. Mp calculated by

MATLAB MODULES

46 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 2

Control System Toolbox and Symbolic Math Toolbox

Objectives:

Using 'MATLAB base program + Control System toolbox', for control systems

analysis and design.

Brief introduction to Symbolic Math toolbox.

MATLAB is presented as an alternate method of solving control system problems. You are

encouraged to solve problems first by hand and then by MATLAB so that insight is not lost

through mechanized use of computer programs.

In Module 1, we have presented a tutorial on MATLAB window environment and some of its

basic commands. In the present module, our objective is to take a primary look at MATLAB

Control System Toolbox, which expands MATLAB base program to include control-system

specific commands. In addition, presented is a MATLAB enhancement - Symbolic Math

Toolbox, that gives added functionality to MATLAB base program and Control System Toolbox.

Control System Toolbox

MATLAB MODULES

47 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 2

Control System Toolbox and Symbolic Math Toolbox

Control System Toolbox

Control System Toolbox is a collection of commands to be used for control systems' analysis and

design. We will be using only some of these commands, because of the limited nature of course

profile. Description of these commands will be distributed in different modules.

In this module, we will present commands related to transfer functions and system responses. To

see all the commands in the Control System Toolbox and their functionalities, type help control

in the MATLAB command window. MATLAB will respond with

>> help control

Control System Toolbox

Version 6.0 (R14) 05-May-2004

General.

ctrlpref - Set Control System Toolbox preferences.

ltimodels - Detailed help on the various types of LTI models.

ltiprops - Detailed help on available LTI model properties.

Creating linear models.

tf - Create transfer function models.

zpk - Create zero/pole/gain models.

ss, dss - Create state-space models.

frd - Create a frequency response data models.

filt - Specify a digital filter.

lti/set - Set/modify properties of LTI models.

Data extraction.

tfdata - Extract numerator(s) and denominator(s).

zpkdata - Extract zero/pole/gain data.

ssdata - Extract state-space matrices.

dssdata - Descriptor version of SSDATA.

frdata - Extract frequency response data.

lti/get - Access values of LTI model properties.

MATLAB MODULES

48 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Conversions.

tf - Conversion to transfer function.

zpk - Conversion to zero/pole/gain.

ss - Conversion to state space.

frd - Conversion to frequency data.

chgunits - Change units of FRD model frequency points.

c2d - Continuous to discrete conversion.

d2c - Discrete to continuous conversion.

d2d - Resample discrete-time model.

System interconnections.

append - Group LTI systems by appending inputs and outputs.

parallel - Generalized parallel connection (see also overloaded +).

series - Generalized series connection (see also overloaded *).

feedback - Feedback connection of two systems.

lft - Generalized feedback interconnection (Redheffer star product).

connect - Derive state-space model from block diagram description.

System gain and dynamics.

dcgain - D.C. (low frequency) gain.

bandwidth - System bandwidth.

lti/norm - Norms of LTI systems.

pole, eig - System poles.

zero - System (transmission) zeros.

pzmap - Pole-zero map.

iopzmap - Input/output pole-zero map.

damp - Natural frequency and damping of system poles.

esort - Sort continuous poles by real part.

dsort - Sort discrete poles by magnitude.

stabsep - Stable/unstable decomposition.

modsep - Region-based modal decomposition.

Time-domain analysis.

ltiview - Response analysis GUI (LTI Viewer).

step - Step response.

impulse - Impulse response.

initial - Response of state-space system with given initial state.

lsim - Response to arbitrary inputs.

gensig - Generate input signal for LSIM.

covar - Covariance of response to white noise.

Frequency-domain analysis.

ltiview - Response analysis GUI (LTI Viewer).

bode - Bode diagrams of the frequency response.

bodemag - Bode magnitude diagram only.

MATLAB MODULES

49 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

sigma - Singular value frequency plot.

nyquist - Nyquist plot.

nichols - Nichols plot.

margin - Gain and phase margins.

allmargin - All crossover frequencies and related gain/phase margins.

freqresp - Frequency response over a frequency grid.

evalfr - Evaluate frequency response at given frequency.

frd/interp - Interpolates frequency response data.

Classical design.

sisotool - SISO design GUI (root locus and loop shaping techniques).

rlocus - Evans root locus.

Pole placement.

place - MIMO pole placement.

acker - SISO pole placement.

estim - Form estimator given estimator gain.

reg - Form regulator given state-feedback and estimator gains.

LQR/LQG design.

lqr, dlqr - Linear-quadratic (LQ) state-feedback regulator.

lqry - LQ regulator with output weighting.

lqrd - Discrete LQ regulator for continuous plant.

kalman - Kalman estimator.

kalmd - Discrete Kalman estimator for continuous plant.

lqgreg - Form LQG regulator given LQ gain and Kalman estimator.

augstate - Augment output by appending states.

State-space models.

rss, drss - Random stable state-space models.

ss2ss - State coordinate transformation.

canon - State-space canonical forms.

ctrb - Controllability matrix.

obsv - Observability matrix.

gram - Controllability and observability gramians.

ssbal - Diagonal balancing of state-space realizations.

balreal - Gramian-based input/output balancing.

modred - Model state reduction.

minreal - Minimal realization and pole/zero cancellation.

sminreal - Structurally minimal realization.

Time delays.

hasdelay - True for models with time delays.

totaldelay - Total delay between each input/output pair.

MATLAB MODULES

50 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

delay2z - Replace delays by poles at z=0 or FRD phase shift.

pade - Pade approximation of time delays.

Model dimensions and characteristics.

class - Model type ('tf', 'zpk', 'ss', or 'frd').

size - Model sizes and order.

lti/ndims - Number of dimensions.

lti/isempty - True for empty models.

isct - True for continuous-time models.

isdt - True for discrete-time models.

isproper - True for proper models.

issiso - True for single-input/single-output models.

reshape - Reshape array of linear models.

Overloaded arithmetic operations.

+ and - - Add and subtract systems (parallel connection).

* - Multiply systems (series connection).

\ - Left divide -- sys1\sys2 means inv(sys1)*sys2.

/ - Right divide -- sys1/sys2 means sys1*inv(sys2).

^ - Powers of a given system.

' - Pertransposition.

.' - Transposition of input/output map.

[..] - Concatenate models along inputs or outputs.

stack - Stack models/arrays along some array dimension.

lti/inv - Inverse of an LTI system.

conj - Complex conjugation of model coefficients.

Matrix equation solvers.

lyap, dlyap - Solve Lyapunov equations.

lyapchol, dlyapchol - Square-root Lyapunov solvers.

care, dare - Solve algebraic Riccati equations.

gcare, gdare - Generalized Riccati solvers.

bdschur - Block diagonalization of a square matrix.

Demonstrations.

Type "demo" or "help ctrldemos" for a list of available demos.

control is both a directory and a function.

--- help for modeldev/control.m ---

MODELDEV/CONTROL

In this module, we will learn how to represent transfer functions in the MATLAB, partial

fraction expansion of rational expressions, representation of transfer functions as LTI objects,

and to obtain time domain responses of LTI systems. Important commands for this module are:

MATLAB MODULES

51 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

roots – Find polynomial roots

poly – Convert roots to polynomial

polyval – Evaluate polynomial value

conv – Convolution and polynomial multiplication

deconv – Deconvolution and polynomial division

residue – Partial-fraction expansion (residues)

tf – Creation of transfer functions or conversion to transfer functions

pole – Compute the poles of LTI models

zero – Transmission zeros of LTI systems

tfdada – Quick access to transfer function data

zpkdata – Quick access to zero-pole-gain data

pzmap – Pole-zero map of LTI models

zpk – Create zero-pole-gain models or convert to zero-pole-gain format

step – Step response of LTI models

impulse – Impulse response of LTI models

lsim – Simulate time response of LTI models to arbitrary inputs

gensig – Periodic signal generator for time response simulations with lsim

Polynomials

Consider a polynomial „s 3 +3 s

2 +4', to which we attach the variable name p. MATLAB can

interpret a vector of length n +1 as the coefficients of an n th

-order polynomial. Coefficients of

the polynomial are interpreted in descending powers. Thus, if the polynomial is missing any

coefficient, we must enter zeros in the appropriate places in the vector. For example, polynomial

p can be represented by the vector [1 3 0 4] in MATLAB. For example:

>> p=[1 3 0 4]

p =

1 3 0 4

Roots of the polynomial can be obtained by roots command.

>> r=roots(p)

r =

-3.3553

0.1777 + 1.0773i

0.1777 - 1.0773i

MATLAB MODULES

52 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Given roots of a polynomial in a vector, a vector of polynomial coefficients can be obtained by

the command poly.

>> p=poly(r)

p =

1.0000 3.0000 0.0000 4.0000

Use the command polyval(p, s) to evaluate the polynomial represented by vector p at arbitrary

value of s. For example, to evaluate the polynomial 's 3 +3 s

2 +4' at , type

>> polyval(p,sqrt(2))

ans =

12.8284

The product of two polynomials is found by taking the convolution of their coefficients. The

function conv will do this for us. Consider an example of multiplying polynomial „s 3 +3 s 2 +4'

with „s +2':

>> p1=[1 3 4];

>> p2=[1 2];

>> p3=conv(p1,p2)

p3 =

1 5 10 8

The function deconv divides two polynomials and returns quotient as well as the remainder

polynomial.

>> [q,r]=deconv(p1,p2)

q =

1 1

r =

MATLAB MODULES

53 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

0 0 2

where q is the quotient and r is the remainder polynomial.

Exercise M2.1

Verify the deconvolution result given in vectors q and r.

Hint: Check whether p1 = conv(q,p2) + r or not?

Exercise M2.2

Let and . Obtain .

Consider the rational fractions of the form:

where the coefficients and are real constants, and and are integers.A fraction of

the form G(s) can be expanded into partial fractions. To do this, first of all we factorize the

denominator polynomial D(s) into first-order factors. The roots of D(s) can be real or

complex; distinct or repeated.

Let, vectors N and D specify the coefficients of numerator and denominator polynomials

and respectively. The command [A,p,K]=residue(N,D) returns residues in

column vector A, the roots of the denominator in column vector p, and the direct term in scalar

K. If there are no multiple roots, the fraction can be represented as:

MATLAB MODULES

54 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

If there are roots of multiplicity mr , i.e. , , then the expansion includes

terms of the form:

If , K is empty (zero).

Supplying 3 arguments A, p, and K to residue converts the partial fraction expansion back to the

polynomial with coefficients in N and D.

Consider the rational fraction:

MATLAB solution to partial fraction problem can be given by:

>> N=[10 40];

>> D=[1 4 3 0];

>> [A,p,K]=residue(N,D)

A =

1.6667

-15.0000

13.3333

p =

-3

-1

0

K =

[ ]

MATLAB MODULES

55 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Example M2.1

Consider the function

The following MATLAB session evaluates the residues.

>> N = 13;

>> D = [1 6 22 30 13 0];

>> [A,p,K]=residue(N,D)

A =

0.0200 - 0.0567i

0.0200 + 0.0567i

-1.0400

-1.3000

1.0000

p =

-2.0000 + 3.0000i

-2.0000 - 3.0000i

-1.0000

-1.0000

0

MATLAB MODULES

56 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

K =

[ ]

Exercise M2.3

Represent the matrices A, p, and K obtained in Example M2.1 in partial fraction form and convert back to the polynomial

form. Counter check your answer with MATLAB.

Exercise M2.4

Consider the rational fraction:

Obtain partial fraction form in terms of K. Solve using MATLAB for and countercheck your answer.

Exercise M2.5

Consider the rational fraction: .

Identify the points where:

1. and

2.

Note: The roots of the numerator polynomial, i.e. , , are known as the zeros of and the roots of the

denominator polynomial, i.e. , , are known as the poles of

MATLAB MODULES

57 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Transfer Functions

Transfer functions can be represented in MATLAB as LTI (Linear Time Invariant) objects using

numerator and denominator polynomials. Consider the transfer function given by

It can be represented in MATLAB as:

>> num = [1 1];

>> den = [1 3 1];

>> G = tf(num,den)

Transfer function:

..s + 1

-----------------

s^2 + 3 s + 1

Example M2.2

The function conv has been used to multiply polynomials in the following MATLAB session for

the transfer function

>> n1 = [5 1];

>> n2 = [15 1];

>> d1 = [1 0];

>> d2 = [3 1];

>> d3 = [10 1];

MATLAB MODULES

58 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

>> num = 100*conv(n1,n2);

>> den = conv(d1,conv(d2,d3));

>> GH = tf(num,den)

Transfer function:

7500 s^2 + 2000 s + 100

-----------------------------------

....30 s^3 + 13 s^2 + s

To learn more about LTI objects given by tf, type ltimodels tf in MATLAB command window.

Type ltiprops tf on MATLAB prompt to learn the properties associated with an LTI object

represented by tf.

Transfer functions can also be entered directly in polynomial form as we enter them in the

notebook using LTI objects. For example, observe the following MATLAB session.

>> s=tf('s') %Define 's' as an LTI object in polynomial form

Transfer function:

s

>> G1=150*(s^2+2*s+7)/[s*(s^2+5*s+4)] % Form G1(s) as an LTI transfer function

% in polynomial form.

Transfer function:

150 s^2 + 300 s + 1050

---------------------------------

......s^3 + 5 s^2 + 4s

>> G2=20*(s+2)*(s+4)/[(s+7)*(s+8)*(s+9)] % Form G2(s) as an LTI transfer

% function in polynomial form.

MATLAB MODULES

59 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Transfer function:

.....20 s^2 +120 s + 160

------------------------------------

s^3 + 24 s^2 + 191s + 504

The commands pole and zero calculate the poles and zeros of LTI models.

>> pole(G1)

ans =

0

-4

-1

>> zero(G1)

ans =

-1.0000 + 2.4495i

-1.0000 - 2.4495i

To extract numerator and denominator polynomials, use the function tfdata .

>> [num,den]=tfdata(G,'v')

num =

0 1 1

den =

1 3 1

To extract zeros and poles of transfer function simultaneously, use the function zpkdata .

>> [z,p]=zpkdata(G,'v')

z =

-1

MATLAB MODULES

60 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

p =

-2.6180

-0.3820

If we know zeros and poles of the system with gain constant, the transfer function of LTI system

can be constructed by zpk command. For example, to create a unity gain transfer function G3(s)

with zero at -1 and two poles at -2.618 and -0.382, follow the MATLAB session given below.

>> G3=zpk(-1,[-2.618 -0.382],1)

Zero/pole/gain:

(s+1)

---------------------------

(s+2.618)(s+0.382)

The polynomial transfer function created with tf can be converted to zero-pole-gain model by the

command zpk and vice versa . The following MATLAB session gives the zero-pole-gain format

of LTI system represented by G(s).

>> zpk(G)

Zero/pole/gain:

(s+1)

---------------------------

(s+2.618)(s+0.382)

To observe the polynomial form of the transfer function G3(s), enter

>> tf(G3)

Transfer function:

s+1

----------------------

s^2 + 3s +1

To learn more about LTI objects given by zpk, type ltimodels zpk in MATLAB command

window. Type ltiprops zpk on MATLAB prompt to learn the properties associated with an LTI

object represented by zpk.

MATLAB MODULES

61 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

The function pzmap(G) plots the poles and zeros of the transfer function G(s) on complex plane.

When used with two left hand side arguments, [p,z] = pzmap(G), the function returns the poles

and zeros of the system in two column vectors p and z. For example:

>> [p,z]=pzmap(G)

p =

-2.6180

-0.3820

z =

-1

System Response

Step and impulse responses of LTI objects can be obtained by the commands step and impulse .

For example, to obtain the step response of the system represented in LTI object G, enter

>> step(G)

The MATLAB response to this command is shown in Fig. M2.1.

MATLAB MODULES

62 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M2.1

To obtain the impulse response, enter

>> impulse(G)

The MATLAB response to this command is shown in Fig. M2.2.

MATLAB MODULES

63 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M2.2

Step and impulse response data can be collected into MATLAB variables by using two left hand

arguments. For example, the following commands will collect step and impulse response

amplitudes in yt and time samples in t.

[yt, t] = step(G)

[yt, t] = impulse(G)

Response of LTI systems to arbitrary inputs can be obtained by the command lsim. The

command lsim(G,u,t) plots the time response of the LTI model G to the input signal described

by u and t. The time vector t consists of regularly spaced time samples and u is a matrix with as

many columns as inputs and whose ith -row specifies the input value at time t(i). Observe the

following MATLAB session to obtain the time response of LTI system G to sinusoidal input of

unity magnitude.

>> t=0:0.01:7;

>> u=sin(t);

MATLAB MODULES

64 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

>> lsim(G,u,t)

The response is shown in Fig. M2.3.

Fig. M2.3

Exercise M2.6

i. Obtain the response of to ramp and parabolic inputs using lsim command.

ii. Obtain the response of to ramp and parabolic inputs using step command.

The function gensig generates periodic signals for time response simulation with lsim function.

It can generate sine, square, and periodic pulses. All generated signals have unit amplitude.

MATLAB MODULES

65 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Observe the following MATLAB session to simulate G ( s ) for 20 seconds with a sine wave of

period 5 seconds.

>> [u,t]=gensig( 'sin' ,5,20); %Sine wave with period 5 sec and duration 20 sec

>> lsim(G,u,t) %Simulate G(s) with u and t.

The response is shown in Fig. M2.4.

Fig. M2.4

Exercise M2.7

Generate square and pulse signals with the period of 4 seconds and obtain time response of

for a duration of 30 seconds.

MATLAB MODULES

66 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Example M2.3

The following MATLAB script calculates the step response of second-order system

with and various values of

t=[0:0.1:12]; num=[1];

zeta1=0.1; den1=[1 2*zeta1 1];

zeta2=0.2; den2=[1 2*zeta2 1];

zeta3=0.4; den3=[1 2*zeta3 1];

zeta4=0.7; den4=[1 2*zeta4 1];

zeta5=1.0; den5=[1 2*zeta5 1];

zeta6=2.0; den6=[1 2*zeta6 1];

[y1,x]=step(num,den1,t); [y2,x]=step(num,den2,t);

[y3,x]=step(num,den3,t); [y4,x]=step(num,den4,t);

[y5,x]=step(num,den5,t); [y6,x]=step(num,den6,t);

plot(t,y1,t,y2,t,y3,t,y4,t,y5,t,y6)

xlabel( 't' ), ylabel( 'y(t)' )

grid

Response through the above MATLAB script is shown in Fig M2.5.

MATLAB MODULES

67 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M2.5

The following MATLAB script calculates the impulse response of second-order system

with and various values of

t=[0:0.1:10]; num=[1];

zeta1=0.1; den1=[1 2*zeta1 1];

zeta2=0.25; den2=[1 2*zeta2 1];

zeta3=0.5; den3=[1 2*zeta3 1];

zeta4=1.0; den4=[1 2*zeta4 1];

[y1,x,t]=impulse(num,den1,t);

[y2,x,t]=impulse(num,den2,t);

MATLAB MODULES

68 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

[y3,x,t]=impulse(num,den3,t);

[y4,x,t]=impulse(num,den4,t);

plot(t,y1,t,y2,t,y3,t,y4)

xlabel( 't' ), ylabel( 'y(t)' )

grid

Response through the above MATLAB script is shown in Fig M2.6.

Fig. M2.6

Right-clicking away from the curves obtained by step, impulse, and lsim commands brings up a

menu. From this menu, various time-response characteristics can be obtained and plotted on the

graph ( Discussion on time-response characteristics will appear later in Module 5).

MATLAB MODULES

69 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 3

Simulink

Objectives:

Building simple Simulink simulations.

Running Simulink simulation to predict a system's behaviour.

The MATLAB Control System Toolbox offers functions for finding the transfer functions from a

given block diagram. However, as we shall shortly see, the simulation environment provided by

MATLAB‟s Simulink Toolkit obviates the need for block diagram reduction. The Simulink

model mimics the block diagram of a feedback control system and is used to evaluate the

response of controlled variable to any test input. It also provides the response of any internal

variable of the control system (output variable of a subsystem block) without the need for block

diagram reduction.

Let us reiterate the fact we have emphasized earlier: a good plant/process model is the backbone

of any realistic control design. A Simulink model based on the structure and parameters of the

system model is constructed. The responses of the actual system and its Simulink model are

obtained using a set of test inputs. If the actual responses to the test inputs were significantly

different from the Simulink responses, certain model parameters would have to be revised,

and/or the model structure would have to be refined to better reflect the actual system behaviour.

Once satisfactory model performance has been achieved, various control schemes can be

designed and implemented.

In practice, it is best to test a control scheme off-line by evaluating the system performance in the

“safety” of the Simulink environment. The key components of a control system include

actuators, sensors, and the plant/process itself. A decision to include all aspects such as amplifier

saturation, friction in the motor, backlash in gears, dynamics of all the devices, etc., may

improve the model, but the complexity of the model may result in a more complicated controller

design, which will ultimately increase the cost and sophistication of the system. The design is

usually carried out using an approximated model; the evaluation of the design is done on the

“true” model, which includes nonlinearities, and other aspects neglected in the approximate

model. Simulink is an excellent tool for this evaluation.

SIMULINK (SIMUlation LINK) is an extension of MATLAB for modeling, simulating, and

analyzing dynamic, linear/nonlinear, complex control systems. Graphical User Interface (GUI)

and visual representation of simulation process by simulation block diagrams are two key

features which make SIMULINK one of the most successful software packages, particularly

suitable for control system design and analysis.

MATLAB MODULES

70 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Simulation block diagrams are nothing but the same block diagrams we are using to describe

control system structures and signal flow graphs. SIMULINK offers a large variety of ready-to-

use building blocks to build the mathematical models and system structures in terms of block

diagrams. Block parameters should be supplied by the user. Once the system structure is defined,

some additional simulation parameters must also be set to govern how the numerical

computation will be carried out and how the output data will be displayed.

Because SIMULINK is graphical and interactive, we encourage you to jump right in and try it.

To help you start using SIMULINK quickly, we describe here the simulation process through a

demonstration example with MATLAB version 7.0, SIMULINK version 6.0.

To start SIMULINK, enter simulink command at the MATLAB prompt. Alternatively one can

also click on SIMULINK icon shown in Fig. M3.1.

Fig. M3.1 MATLAB Desktop main menu and SIMULINK icon

A SIMULINK Library Browser (Fig. M3.2) appears which displays tree-structured view of the

SIMULINK block libraries. It contains several nodes; each of these nodes represents a library of

subsystem blocks that is used to construct simulation block diagrams. You can expand/collapse

the tree by clicking on the boxes beside each node and block in the block set pan.

MATLAB MODULES

71 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M3.2 SIMULINK Library Browser

Expand the node labeled Simulink. Subnodes of this node ( Commonly Used Blocks,

Continuous, Discontinuities, Discrete, Logic and Bit Operations, etc…) are displayed. Now

MATLAB MODULES

72 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

for example, expanding the Sources subnode displays a long list of Sources library blocks.

Simply click on any block to learn about its functionality in the description box (see Fig. M3.3).

Fig. M3.3 Blocks in Sources subnode

You may now collapse the Sources subnode, and expand the Sinks subnode. A list of Sinks

library block appears (Fig.M3.4). Learn the purpose of various blocks in Sinks subnode by

clicking on the blocks.

MATLAB MODULES

73 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M3.4 Blocks in Sinks subnode

Exercise M3.1

Expand the Continuous, Discontinuities, Discrete, and Math Operations subnodes. Study the purpose of various blocks

in these subnodes in description box.

We have described some of the subsystem libraries available that contain the basic building

blocks of simulation diagrams. The reader is encouraged to explore the other libraries as well.

MATLAB MODULES

74 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

You can also customize and create your own blocks. For information on creating your own

blocks, see the MATLAB documentation on “Writing S- Functions”.

We are now ready to proceed to the next step, which is the construction of a simulation diagram.

In the SIMULINK library browser, follow File New Model or hit Ctrl+N to open an

„untitled' workspace (Fig.M3.5) to build up an interconnection of SIMULINK blocks from the

subsystem libraries.

Fig. M3.5 Untitled workspace

Let us take a simple example. The block diagram of a dc motor (armature-controlled) system is

shown in Fig. M3.6

MATLAB MODULES

75 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M3.6 Block diagram of a dc motor (armature-controlled) system

where

is the resistance of the motor armature (ohms) = 1.75

is the inductance of the motor armature (H) = 2.83

is the torque constant (Nm/A) = 0.0924

is the back emf constant (V sec/rad) = 0.0924

is the inertia seen by the motor (includes inertia of the load) (kg-m2 ) =

is the mechanical damping coefficient associated with rotation (Nm/(rad/sec))= 5.0

is the applied voltage (volts) = 5 volts

We will implement the model shown in Fig. M3.6 in the untitled work space (Fig. M3.5).

Let us first identify the SIMULINK blocks required to implement the block diagram of Fig.

M3.6. This is given in Fig. M3.7.

MATLAB MODULES

76 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M3.7 SIMULINK blocks required for implementation

Identifying the block(s) required for simulation purpose is in fact the first step of the construction

of simulation diagram in SIMULINK. The next step is to “drag and drop ” the required blocks

from SIMULINK block libraries to untitled workspace. Let us put the very first block for

applied voltage (Ea) to workspace.

Expand the Sources subnode, move the pointer and click the block labeled Constant, and while

keeping the mouse button pressed down, drag the block and drop it inside the Simulation

Window; then release the mouse button (Fig. M3.8).

Right clicking on the block will provide various options to users from which one can cut, copy,

delete, format (submenu provides facilities for rotation of the block, flipping, changing the font

of block name,...), etc...

Exercise M3.2

Drag and drop all the blocks we have identified (Fig. M3.7) from the Library Browser to the untitled Workspace and place

them as shown in Fig. M3.9.

MATLAB MODULES

77 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M3.8 Drag and drop blocks to Workspace from Library Browser

Fig. M3.9 Unconnected blocks in Workspace

MATLAB MODULES

78 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

It is visible that all the block parameters are in their default settings. For example, the default

transfer function of Transfer Fcn block is and default signs of Sum block are + +. We

need to configure these block parameters to meet our modeling requirements. It is

straightforward. Double click the block to set up its parameters. For example, double clicking the

Transfer Fcn block opens the window titled Block Parameters: Transfer Fcn, shown in Fig.

M3.10.

Fig. M3.10 Transfer function block parameters window

For armature circuit transfer function, no need to change the numerator parameter. For

denominator parameters, enter for , which will be interpreted by

SIMULINK as .

To enhance the interpretability of simulation diagram, we can also change the block

identification name. Simply click on the text Transfer Fcn to activate the small window around

MATLAB MODULES

79 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

the text to change the block name. For our simulation block diagram, the suitable text for

Transfer Fcn block may be Armature circuit.

Before we move to the last step of interconnecting the blocks as per the desired structure, just

finish Exercise M3.3. Note that the Decimation parameter value by default is 1. Increasing this

value reduces the number of data samples taken over the simulation time. We have used the

default value of 1.

Exercise M3.3

Modify all the block parameters as per system parameters given for Fig. M3.7, and give appropriate names to the

blocks.

Lines are drawn to interconnect these blocks as per the desired structure. A line can connect

output port of one block to the input port of another block. A line can also connect the output

port of one block with input ports of many blocks by using branch lines. We suggest readers to

perform the following line/block operations on blocks dragged in workspace to get hands on

practice.

To connect the output port of one block to the input port of another block:

1. Position the pointer on the first block's output port; note that the cursor shape

changes to cross hair.

2. Press and hold down the left mouse button.

3. Drag the pointer to second block's input port.

4. Position the pointer on or near the port; the pointer changes to a double cross hair.

5. Release the mouse button. SIMULINK replaces the port symbol by a connecting line

with an arrow showing the direction of signal flow.

MATLAB MODULES

80 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Another simple methodology doesn't require dragging the line. Block1 output port is required to

be connected to Block2 input port.

1. select Block1 by clicking anywhere inside the block.

2. Hold down the Ctrl key.

3. Click on block2; both the blocks will be connected.

To connect the output port of one block with the input ports of several blocks, we can use branch

lines. Both the existing line and the branch line carry the same signal. To add a branch line, do

the following:

1. Position the pointer on the line where you want the branch line to start.

2. While holding down the Ctrl key, left click on the line segment; note that the cursor

shape changes to cross hair.

3. Release the control key, while pressing down the left mouse button; drag the pointer

to the input port of the target block.

4. Release the mouse button; target block will be connected to the line segment.

Some of the important line-segment and block operations are as follows:

1. To move a line segment, position the pointer on the segment you want to move.

Press and hold down the left mouse button. Drag the pointer to the desired location

and release. Note that this operation is valid with line segments only, not with the

dedicated connecting lines between two blocks.

2. To disconnect a block from its connecting lines, hold down the shift key, then drag

MATLAB MODULES

81 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

the block to a new location. Incoming and outgoing lines will be converted to red

colored dotted lines. One can insert a different block between these lines.

Exercise M3.4

Connect all the blocks appropriately as per the block diagram given in Fig. M3.7. Make use

of the block interconnection points discussed above.

Now let us give a name to the untitled workspace. Hit Ctrl + S to save the developed simulation

diagram to the disk with an appropriate name. The file will be saved with the extension .mdl , an

abbreviation for the „model'.

We save the file using the name armature_dcmotor.mdl; the complete simulation diagram is

shown in Fig. M3.11.

Finally, we need to set the parameters for the simulation run. Press Ctrl + E to open the

simulation parameter configuration window. Left panel of the window (Fig. M3.12) displays a

tree structured view of parameter submenu. In the Solver submenu, enter the start and stop time

of the simulation (Fig. M3.13).

MATLAB MODULES

82 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M3.11 Final simulation diagram ( download )

MATLAB MODULES

83 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M3.12 Parameter configuration submenu

Fig. M3.13 Enter simulation time

Now we are ready to simulate our block diagram of armature-controlled dc motor. Press

icon to start the simulation. Note that the icon changes to ; pressing this icon, one can

stop the simulation before stop time. After simulation is done, double click the Scope block to

display the angular velocity variation with time. Click the autoscale icon in the display

window to scale the axes as per the variable ranges. Autoscaled scope display is shown in Fig.

M3.14. With zoom facility, try zooming the portion of graph between 0.5 to 1 sec, and 20 to 25

unit angular velocity to identify the numerical value of angular velocity at 0.8 seconds.

MATLAB MODULES

84 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M3.14 Scope display of angular velocity

Set y-axis limits by right-clicking the axis and choosing Axes Properties. In Y-min, enter the

minimum value for the y-axis. In Y-max, enter the maximum value for the y-axis. In Title, enter

the title of the plot. See Fig. M3.15.

MATLAB MODULES

85 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M3.15 Scope axis properties editor

Click the icon shown on the icon bar of Fig. M3.14 to open scope parameter editor (Fig.

M3.16). General parameters include Number of axes, Time range, Tick labels, and Sampling.

Click on the Data history button. If you want input-output data from this scope to be available to

MATLAB workspace for further analysis, check the button Save data to workspace. In the box

Variable name, enter the variable name for saving the data. By default it will save the data with

variable name ScopeData. With the pop-down menu Format, select the format in which you

want to save the data.

Three specific formats for saving the data are as follows:

1. Structure with time: Data will be saved in structured format with time steps. Type the

following commands in your MATLAB prompt and observe the outputs.

MATLAB MODULES

86 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M3.16 Scope parameter setting window

>> ScopeData

ScopeData =

time: [4663x1 double]

signals: [1x1 struct]

blockName: 'armature_dcmotor/Angular Velocity'

Structures are used in MATLAB to store mixed mode data types, and individual fields of the

structure can be accessed by „dot ' operator. To see the information stored in the field signals,

type:

>> ScopeData.signals

ans =

values: [4663x1 double]

MATLAB MODULES

87 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

dimensions: 1

label: ''

title: ''

plotStyle: 0

It indicates that the field signals contains subfield values, which is of 4663 x 1 size vector

containing the values of angular velocity. Try accessing the field time of ScopeData.

Exercise M3.5

Plot the angular velocity against time using the plot command. Give suitable title to the plot and labels to x and

y axes.

Hint: You need to plot ScopeData.signals.values against ScopeData.time.

2. Structure : This is the same as Structure with time; the only difference is that the time steps

will not be saved.

Exercise M3.6

Run the simulation with scope data to be saved as Structure format. Verify that the time field of ScopeData

structure is actually an empty matrix.

3. Array : Array format is simply a two column matrix with number of data points being equal

to number of rows. The maximum number of data points limits to the number entered in the box

Limit data points to last. In Fig. M3.16, the limit is 5000 data points.

Exercise M3.7

Run the simulation with scope data to be saved as Array format. Repeat Exercise M3.5 with saved data matrix.

MATLAB MODULES

88 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

We have used an example to show how to build the simulink diagram, how to enter data and

carry out a simulation in the SIMULINK environment. The reader will agree that this is a very

simple process.

Solving the following exercises will make the readers more confident in solving the control

system design and analysis problems through SIMULINK.

Exercise M3.8

This problem requires some modification in the above considered armature-controlled d.c. motor SIMULINK

example.

1. The angular position is obtained by integrating the angular velocity. Implement this in the model and

display angular position in a different scope.

2. Remove the constant applied voltage block. Obtain the Step, Ramp, and Sinusoidal responses of the

system.

3. Simulate a closed-loop position control system assuming a proportional controller of gain KP .

Hint: Add a reference input signal for angular position and add a summing block which calculates the error

between the angular position reference and the measured angular position. Multiply this error by the gain KP

and let this signal be the applied voltage Ea .

Exercise M3.9

Consider a dynamic system consisting of a single output , and two inputs r and w :

where

MATLAB MODULES

89 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Model the system in SIMULINK.

For and both step signals, obtain the system output . Display the output on scope. Also, using a

SIMULINK block, etch the output to the workspace.

Hint: To implement deadtime, use the block Transport delay from Continuous, and identify suitable block

from Sinks library to fetch the variable directly to the workspace.

Exercise M3.10

Assign 0.5, , and to , respectively.

Simulate for 10 seconds.

Display plots for on scope, and also save to the MATLAB file Yt.mat.

Hint: Use Math Function, Add, Divide, and Trigonometric Function from Math Operations block

libraries.

Exercise M3.11

This problem is to study the effects of Proportional (P), Proportional + Integral (PI), and Proportional +

Derivative (PD) control schemes on the temperature control system. A temperature control system has the

block diagram given in Fig.M3.17. The input signal is a voltage and represents the desired temperature

Simulate the control system using SIMULINK and find the steady-state error of the system when is a

unit-step function and (i) (ii) and (iii) .

MATLAB MODULES

90 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M3.17

Hint: Use PID Controller block from Simulink Extras Additional Linear to implement the PID

controller.

Exercise M3.12

The block diagram in Fig. M3.18 shows the effect of a simple on-off controller on second-order process with

deadtime.

Fig. M3.18

Implement and test the model in SIMULINK for step inputs of 5.0 and 10.0. Display the control signal u( t )

and output the on separate scopes and also fetch both the signals with time information to MATLAB

workspace. Using MATLAB plot function, plot the control signal and the output; both against time on single

graph.

Hint: To implement on-off controller, use Relay from Discontinuous block library.

Exercise M3.13

Simulate the Van der Pol oscillator, described by the following nonlinear differential equation:

,

where is the disturbance (forcing function) given by . Assign

Hint: Rewrite the second-order Van der Pol differential equation as a system of coupled first-order differential

MATLAB MODULES

91 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

equations. Let,

The SIMULINK block diagram is to be built using Signal Generator, Gain, Integrator, Add, and Scope.

The output of Add block is . Integrating it once will lead you to and second integration will lead you to

Double click the Integrator block to add the initial conditions .

MATLAB MODULES

92 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 4

Feedback System Simulation

Objectives:

Presenting MATLAB functions to carryout block diagram manipulations, followed by time-response analysis.

Using Simulink simulation for time-response analysis.

Transfer Function Manipulation

System Response

Simulink Simulation

MATLAB MODULES

93 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 4

Feedback System Simulation

Transfer Function Manipulation

Suppose we have developed mathematical models in the form of transfer functions for the plant,

represented by G(s), and the controller, represented by D(s), and possibly many other system

components such as sensors and actuators. Our objective is to interconnect these components to

form block diagram representation of a feedback control system. MATLAB offers several

functions to carry out block diagram manipulations.

Two methods are available:

1. Solution via series, parallel, and feedback commands:

series(G,D) for a cascade connection of G(s) and D(s); parallel(G1,G2) for a parallel

connection of G1(s) and G2(s); feedback(G,H, sign) for a closed-loop connection with G(s) in

the forward path and H(s) in the feedback path; and sign is -1 for negative feedback or +1 for

positive feedback (the sign is optional for negative feedback); and cloop(G,sign) for a unity

feedback system with G(s) in the forward path, and sign is -1 for negative feedback or +1 for

positive feedback (the sign is optional for negative feedback).

2. Solution via algebraic operations:

G*D for a cascade connection of G(s) and D(s); G1+G2 for a parallel connection of G1(s) and

G2(s); G/(1+G*H) for a closed-loop negative feedback connection with G(s) in the forward path

and H(s) in the feedback path; and G/(1-G*H) for positive feedback systems.

MATLAB MODULES

94 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 4

Feedback System Simulation

System Response

The transfer function manipulations give us a transfer function model M(s) between command

input R(s) and output Y(s); model Mw(s) between disturbance input W(s) and output Y(s); a model

between command input R(s) and control U(s), etc. It is now easy to use some of the control

analysis commands available from the Control System Toolbox. impulse(M) and step(M)

commands represent common control analysis operations that we meet in this book. Also

frequently used in the book are frequency-response plots.

Example M4.1

Consider the block diagram in Fig. M4.1.

Fig. M4.1

For value of gain KA = 80, the following two MATLAB sessions evaluate the step responses with

respect to reference input R(s) and disturbance signal W(s) for

>> %Step response with respect to R(s)

MATLAB MODULES

95 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

>> s = tf('s');

>> KA = 80;

>> G1 = 5000/(s+1000);

>> G2 = 1/(s*(s+20));

>> M = feedback(series(KA*G1,G2),1)

>> step(M)

The MATLAB responds with

Transfer function:

.......................400000

--------------------------------------------------

s^3 + 1020 s^2 + 20000 s + 400000

and step response plot shown in Fig. M4.2. The grid has been introduced in the plot by right

clicking on the plot and selecting Grid option.

MATLAB MODULES

96 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M4.2

>> %Step response with respect to W(s)

>> s = tf('s');

>> KA = 80;

>> G1 = 5000/(s+1000);

>> G2 = 1/(s*(s+20));

>> Mw = (-1) * feedback(G2, KA*G1)

>> step(Mw)

MATLAB responds with

Transfer function:

.......................-s - 1000

----------------------------------------------------

s^3 + 1020 s^2 + 20000 s + 400000

MATLAB MODULES

97 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

and step response plot shown in Fig. M4.3.

Fig. M4.3

Example M4.2

Let us examine the sensitivity of the feedback system represented by the transfer function

The system sensitivity to parameter K is

MATLAB MODULES

98 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Figure M4.4 shows the magnitudes of and versus frequency for K =

0.25; generated using the following MATLAB script. Text arrows have been introduced in the

plot by following Insert from the main menu and selecting the option Text Arrow.

Note that the sensitivity is small for lower frequencies, while the transfer function primarily

passes low frequencies.

w = 0.1:0.1:10;

M = abs(0.25./((j*w).^2+j*w+0.25));

SMK = abs((j*w .* (j*w + 1))./((j*w).^2 + j*w +0.25));

plot(w,M,'r',w,SMK,'b');

xlabel('Frequency (rad/sec)');

ylabel('Magnitude');

Fig. M4.4

Of course, the sensitivity S only represents robustness for small changes in gain K. If K changes

from 1/4 within the range K = 1/16 to K = 1, the resulting range of step responses, generated by

the following MATLAB script, is shown in Fig. M4.5. This system, with an expected wide range

MATLAB MODULES

99 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

of K, may not be considered adequately robust. A robust system would be expected to yield

essentially the same (within an agreed-upon variation) response to selected inputs.

s = tf('s');

S = (s*(s+1))/(s^2+s+0.25);

M1 = 0.0625/(s^2+s+0.0625);

M2 = 0.25/(s^2+s+0.25);

M3 = 1/(s^2+s+1);

step(M1);

hold on;

step(M2);

step(M3);

Fig. M4.5

MATLAB MODULES

100 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 4

Feedback System Simulation

Simulink Simulation

Simulink simulation is an alternative to block diagram manipulation followed by time-response

analysis. From the Simulink model of a control system, output y in response to command r,

output y in response to disturbance w, control u in response to command r, and all other desired

internal variables can be directly obtained.

Example M4.3

Control system design methods discussed in this course are based on the assumption of

availability of linear time invariant (LTI) models for all the devices in the control loop.

Consider a speed control system. The actuator for the motor is a power amplifier. An amplifier

gives a saturating behaviour if the error signal input to the amplifier exceeds linear range value.

MATLAB simulink is a powerful tool to simulate the effects of nonlinearities in a feedback loop.

After carrying out a design using LTI models, we must test the design using simulation of the

actual control system, which includes the nonlinearities of the devices in the feedback loop.

Figure M4.6 is the simulation diagram of a feedback control system: the amplifier gain is 100

and the transfer function of the motor is 0.2083/(s +1.71). We assume the amplifier of gain 100

saturates at +5 or -5volts. The result of the simulation is shown in Fig. M4.7.

The readers are encouraged to construct the simulink model using the procedure described in

Module 3. All the parameter settings can be set/seen by double clicking on related blocks.

MATLAB MODULES

101 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M4.6 ( download )

Time and Output response data have been transferred to workspace using To Workspace block

from Sinks main block menu. Clock block is available in Sources main menu. These variables

are stored in the structure Output and Time in the workspace, along with the information

regarding simulink model name. For example,

>> Output

Output =

time: [ ]

signals: [1x1 struct]

blockName: 'M4_3/To workspace Output'

>> Time

Time =

time: [ ]

signals: [1x1 struct]

blockName: 'M4_3/To workspace Time'

MATLAB MODULES

102 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

To access output and time values, one needs to access Output.signals.values and

Time.signals.values . The step response plot has been generated by the following MATLAB

script.

>> plot(Time.signals.values,Output.signals.values)

>> xlabel('Time (sec)');

>> ylabel('Output');

>> title('Step Response');

Fig. M4.7

Example M4.4

In this example, we simulate a temperature control system with measurement noise added to the

feedback signal. The process transfer function is

MATLAB MODULES

103 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

The deadtime minutes. The measurement noise parameters we have used are: mean of

0, variance of 0.5, initial seed of 61233, and sample time of 0. The simulink inputs a step of 30 to

the system (Fig. M4.8). Deadtime block in this figure is Transport Delay block from

Continuous library, and Random Number block is from Sources library.

Fig. M4.8 ( download )

The data has been transferred to the workspace using To Workspace block. The step response,

generated using the following MATLAB script is shown in Fig. M4.9.

>> plot(Time.signals.values,Y.signals.values);

>> ylabel('Output (Y)');

>> xlabel('Time(min)');

>> title('Step Response');

MATLAB MODULES

104 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M4.9

The performance of the system with measurement noise removed, is shown in Fig. M4.10. To

remove the effect of noise, simply disconnect the Random number block from the Sum block

in the feedback path.

MATLAB MODULES

105 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M4.10

MATLAB MODULES

106 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 5

Time Response Characteristics and LTI Viewer

Objectives:

Analysis of the system behaviour to changes in input reference signals or

disturbances using steady-state and transient performance indices.

Brief introduction to LTI Viewer, and time response analysis using this

GUI tool.

Time response characteristics of interest to us in analysis and design of control systems are: rise

time (tr), settling time (ts), peak time (tp) , and peak overshoot (Mp) of step response of a system.

These parameters can directly be obtained from the plot generated by the command step. Right-

clicking away from the curve generated by step brings up a menu. From this menu, various time-

response characteristics can be selected.

MATLAB has a powerful GUI tool, called LTI Viewer, for obtaining both the time and

frequency response characteristics of a given Linear Time Invariant system. In this module, we

give the basic features of this GUI tool and use it for time response analysis. Later in Module 9,

this tool will be exploited for frequency response analysis.

LTI Viewer

Time response characteristics in Matlab window

Time response characteristics in Simulink window

MATLAB MODULES

107 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 5

Time Response Characteristics and LTI Viewer

Time Response Characteristics in MATLAB window

Example M5.1

Consider the position control system shown in Fig. M5.8.

.

Fig. M5.8

(transfer function of motor, gears, and load)

(transfer function of power amplifier)

KA = preamplifier gain

sensitivity of input and output potentiometers

Time response characteristics of the system are generated by the following MATLAB script.

s = tf('s');

G1 = 100/(s+100);

MATLAB MODULES

108 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

G2 = 0.2083/(s*(s+1.71));

K = 1000;

G = series(K*G1,G2);

H = 1/pi;

M = series(feedback(G,H),H);

ltiview(M);

MATLAB response is shown in Fig. M5.9.

In the following we compare the time response characteristics of this system with the one

obtained by replacing the power amplifier with a transfer function of unity (Fig. M5.10).

s = tf('s');

G1 = 1;

G2 = 0.2083/(s*(s+1.71));

K = 1000;

G = series(K*G1,G2);

H = 1/pi;

M1 = series(feedback(G,H),H);

ltiview(M1);

MATLAB MODULES

109 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M5.9

MATLAB MODULES

110 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M5.10

The second-order approximation seems to be quite reasonable.

The two responses in Figs M5.9 and M5.10 can be obtained in a single plot using the command

ltiview(M,M1). Alternatively, choose Import... under the File menu in the LTI Viewer window

and select M.

Example M5.2

Consider a unity feedback system shown in Fig. M5.11.

MATLAB MODULES

111 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M5.11

We will consider the following three controllers:

D1(s) = 3; D2(s)=3+(15/ s ); and D3(s)=(3+(15/ s )+0.3 s )

The following MATLAB code generates the step responses shown in Fig. M5.12.

s = tf('s');

G = 59.292/(s^2+6.9779*s+15.12);

D1 = 3;

D2 = 3 + 15/s;

D3 = 3 + 15/s +0.3*s;

M1 = feedback(D1*G,1);

M2 = feedback(D2*G,1);

M3 = feedback(D3*G,1);

step(M1);

hold;

step(M2);

step(M3);

MATLAB MODULES

112 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

We need not access LTI viewer to find out the time response characteristics of the closed-loop

system. The step command in MATLAB has this feature inbuilt in it as is seen in Fig. M5.12.

Fig. M5.12

Note that adding the integral term increases the oscillatory behaviour but eliminates the steady-

state error, and that adding the derivative term reduces the oscillations, while maintaining zero

steady-state error.

MATLAB MODULES

113 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 5

Time Response Characteristics and LTI Viewer

Time Response Characteristics in SIMULINK window

Example M5.3

Consider a unity feedback, PID controlled system with following parameters:

Plant transfer function:

PID controller transfer function:

Reference input:

A Simulink block diagram is shown in Fig. M5.13.

MATLAB MODULES

114 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M5.13 (download)

The Simulink model inputs a step of 30 to the system.

Time response characteristics of the model developed in Simulink can be obtained by invoking

the LTI Viewer directly from the Simulink. LTI Viewer for Simulink can be invoked by

following Tools -- Control Design -- Linear Analysis as shown in Fig. M5.14.

Fig. M5.14

This opens Control and Estimation Tools Manager shown in Fig. M5.15.

MATLAB MODULES

115 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M5.15

Select linearization input-output points by right clicking on the desired line and selecting

Linearization Points in your Simulink model. Fig. M5.16 explains the selection of input point.

Similarly output point has been selected. Once input-output linearization points appear in the

Control and Estimation Tools Manager window, click on the Linearize Model at the bottom

of the window (Fig. M.5.15). The type of response can be selected from the drop down menu just

near the Linearize Model button. Other linear analysis plots available are: Bode, Impulse,

Nyquist, Nichols, Bode magnitude plot, and pole-zero map.

MATLAB MODULES

116 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M5.16

The step response with the characteristics is shown in Fig. M5.17.

MATLAB MODULES

117 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M5.17

Example M5.4

Consider a unity feedback, PI controlled system with following parameters:

Plant transfer function:

Plant deat-time: = 0.15 minutes

PI controller transfer function:

Actuator saturation characteristic: Unit slope; maximum control signal =1.7.

MATLAB MODULES

118 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Reference input:

A Simulink block diagram is shown in Fig. M5.18. PID controller block is available in

Additional Linear block set in Simulink Extras block library. The parameters of PID controller

block have been set as : P = 0.09, I = 0.95, and D = 0.

Fig. M5.18 (download)

We can invoke LTI Viewer to determine the time response characteristics of the system of Fig.

M5.18. However, LTI Viewer will linearize the system and then plot the characteristics. An

alternative is to transfer the output response data to workspace using To Workspace block and

then generate the time response using the plot command. A MATLAB code can then be written

to determine the required characteristics. The following code gives settling time, peak overshoot,

and peak time for the output response data of Fig. M5.18.

time = t.signals.values;

y = Y.signals.values;

plot(time,y);

title('Step response');

xlabel('Time (min)');

ylabel('Output');

ymax = max(y);

MATLAB MODULES

119 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

step_size = 10;

peak_overshoot = ((ymax-step_size)/step_size)*100

index_peak = find(y == ymax);

peak_time = time(index_peak)

s = length(time);

while((y(s)>=0.95*step_size) & (y(s)<=1.05*step_size))

s = s-1;

end

settling_time = time(s)

The MATLAB responds with Fig. M5.19 and the following characteristics.

peak_overshoot =

39.0058

peak_time =

1.9339

settling_time =

5.9739

MATLAB MODULES

120 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M5.19

MATLAB MODULES

121 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 6

Stability Analysis on Root Locus Plots

Objectives:

Stability analysis in state space.

Stability analysis using root locus plots.

Stability Analysis in State Space

Root Locus Analysis

MATLAB MODULES

122 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 6

Stability Analysis on Root Locus Plots

Stability Analysis in State Space

There are several useful MATLAB commands related to analysis and design in state space.

Commands useful for stability analysis in state space are:

ss; step; initial; eig; tf; minreal

The MATLAB program below forms the matrices A,b,c and d for the system

>> A = [0 1 0; 0 0 1; 0 -2 -3];

>> b = [0; 0; 1];

>> c = [1 0 0 ];

>> d = 0;

The output generated in the MATLAB Command Window by executing these commands is

A =

0 1 0

0 0 1

0 -2 -3

b =

0

0

1

c =

1 0 0

MATLAB MODULES

123 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

d =

0

The command ss (A,b,c,d) creates the state space model; let us call it stmod . The MATLAB

dialogue is given below.

>> stmod = ss(A,b,c,d)

a =

......x1 .x2 x3

x1 ..0 ..1 ...0

x2 ..0 ..0 ...1

x3 ..0 .-2 ..-3

b =

.......u1

x1 ...0

x2 ...0

x3 ...1

c =

......x1 x2 x3

y1 ..1 ..0 ...0

d =

.......u 1

y1 ....0

Continuous-time model.

MATLAB MODULES

124 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

The system stmod can then be used as an argument for many of the MATLAB commands we

have already discussed. For instance, the command step(stmod) generates the plot of unit-step

response y(t) (with zero initial conditions).

The command initial(stmod, x0) creates the free response (with input u(t) = 0) to initial

condition vector x0.

Typing eig(stmod) in the command window produces the dialogue

>> eig(stmod)

ans =

0

-1

-2

Thus the eigenvalues of the plant matrix A are

MATLAB has the means to perform model conversions. Given the state model stmod, the syntax

for conversion to transfer function model is

tfmod = tf(stmod)

Common pole-zero factors of the transfer function model must be cancelled before we can claim

that we have the transfer function representation of the system. To assist us in pole-zero

cancellation, MATLAB has mineral (tfmod) function.

Asymptotic stability is given by the command eig(A). If conversion of the state model to transfer

function gives a model with no pole-zero cancellations, the system is both controllable and

observable; asymptotic stability implies BIBO stability and vice versa. Stability analysis can be

carried out using transfer functions under the assumption of controllability and observability of

the corresponding dynamic system.

The command pole(tfmod) finds the poles of a transfer function. The command pzmap(tfmod)

plots the poles and zeros of the transfer function. A MATLAB code for the Routh stability

criterion can easily be written for stability analysis. However, our focus in this course is on root

locus for stability analysis. The focus in this MATLAB module will therefore be on root locus

analysis.

MATLAB MODULES

125 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 6

Stability Analysis on Root Locus Plots

Root Locus Analysis

In the following, we provide brief description of powerful MATLAB commands for root locus

analysis. The reader may wonder why the instructors emphasize learning of hand calculations

when powerful MATLAB commands are available. For a given set of open-loop poles and zeros,

MATLAB immediately plots the root loci. Any changes made in the poles and zeros,

immediately result in new root loci and so on.

Depending on our background and aptitude, we may, after a while, begin to make some sense of

the patterns. May be we finally begin to formulate a set of rules that enables us to quickly make a

mental sketch of the root locus the moment the poles and zeros appear. In other words, by trial-

and-error, we find the rules of the root locus.

Through the systematic formulation of set of rules of the root locus, we look for the clearest, and

simplest explanation of the dynamic phenomena of the system. The rules of the root locus give

us a clear and precise understanding of the endless patterns that can be created by an infinite set

of characteristic equations. We could eventually learn to design without these rules, but our level

of skill would never be as high or our understanding as great. This is true of other analysis

techniques also such as Bode plots, Nyquist plots, Nichols charts, and so on, covered later in the

course.

MATLAB allows root locus for the characteristic equation

1 + G (s)H(s) = 0

to be plotted with the rlocus(GH) command. Points on the root loci can be selected interactively

(placing the cross-hair at the appropriate place) using the [K,p] = rlocfind(GH) command.

MATLAB then yields the gain K at that point as well as all the poles p that have that gain. The

root locus can be drawn over a grid generated using the sgrid (zeta, wn) command, that allows

constant damping ratio zeta and constant natural frequency wn curves. The command rlocus

(GH, K) allows us to specify the range of gain K for plotting the root locus. Also study the

commands [p,K]=rlocus(GH) and [p]=rlocus(GH,K) using MATLAB online help.

Example M6.1

Consider the system shown in the block diagram of Fig. M6.1.

MATLAB MODULES

126 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M6.1

The characteristic equation of the system is

1 + G(s) = 0

with

The following MATLAB script plots the root loci for

s = tf('s');

G = 1/(s*(s+7)*(s+11));

rlocus(G);

axis equal;

Clicking at the point of intersection of the root locus with the imaginary axis gives the data

shown in Fig. M6.2. We find that the closed-loop system is stable for K < 1360; and unstable for

K > 1360.

MATLAB MODULES

127 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M6.2

Fig. M6.3 shows step responses for two values of K .

>> K = 860;

>> step(feedback(K*G,1),5)

>> hold;

% Current plot held

>> K = 1460;

>> step(feedback(K*G,1),5)

MATLAB MODULES

128 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M6.3

Example M6.2

Consider the system shown in Fig. M6.4.

Fig M6.4

The plant transfer function G(s) is given as as

The following MATLAB script plots the root locus for the closed-loop system.

MATLAB MODULES

129 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

clear all;

close all;

s = tf('s');

G = (s+1)/(s*(0.1*s-1));

rlocus(G);

axis equal;

sgrid;

title('Root locus for (s+1)/s(0.1s-1)');

[K,p]=rlocfind(G)

Fig M6.5

selected_point =

-2.2204 + 3.0099i

K =

MATLAB MODULES

130 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

1.4494

p =

-2.2468 + 3.0734i

-2.2468 - 3.0734i

Example M6.3

For a unity feedback system with open-loop transfer function

a root locus plot shown in Fig. M6.6 has been generated using the following MATLAB code.

s = tf('s');

G = (s^2-4*s+20)/((s+2)*(s+4));

rlocus(G);

zeta = 0.45;

wn = 0;

sgrid(zeta,wn);

Properly redefine the axes of the root locus using Right click --> Properties --> Limits.

MATLAB MODULES

131 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M6.6

Clicking on the intersection of the root locus with zeta=0.45 line gives the system gain K = 0.415

that corresponds to closed-loop poles with Clicking on the intersection of the root

locus with the real axis gives the breakaway point and the gain at that point.

MATLAB MODULES

132 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 7

Root Locus Design and SISO Design Tools

Objectives:

Design using root locus plots.

Brief introduction to SISO Deisgn Tool, and root locus design using this GUI tool.

We will carry out Control system design using MATLAB dialogues. MATLAB is an interpreted

language. That is, it runs along executing each instruction as it comes to it. This interactive

feature of MATLAB will be exploited in our design exercise. The designer will be in the loop.

The MATLAB SISO Design Tool, developed on the MATLAB dialogue pattern, is a powerful

GUI tool wherein the designer is always in the design loop. We will outline this tool, with an

example, at the end of this module.

Design using Matlab Dialogues

MATLAB's SISO Design tool

MATLAB MODULES

133 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 7

Root Locus Design and SISO Design Tools

Design using MATLAB dialogues

Example M7.1

A unity feedback system has forward path transfer function

Our goal is to design a cascade PID compensator that improves the transient as well as steady-

state performance of the closed-loop system (refer Nise(2004)).

We want to achieve a transient response that has no more than 20% overshoot. This, as we know,

can be achieved by simple gain adjustment. We therefore first evaluate the uncompensated

system operating at 20% overshoot. The following MATLAB dialogue is helpful for this

evaluation.

s = tf('s');

G1 = (s+8)/((s+3)*(s+6)*(s+10));

zeta = 0.456;

rlocus(G1);

sgrid(zeta,0);

MATLAB MODULES

134 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig.M7.1

Selecting the point of intersection of the root locus with 20% overshoot line in Fig.

M7.1 using rlocfind(G) command, MATLAB yields the gain at that point, as well as all the

poles that have that gain . The MATLAB session follows:

>> [K, p] = rlocfind(G1)

Select a point in the graphics window

selected_point =

-5.4171 +10.4814i

K =

119.6589

MATLAB MODULES

135 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

p =

-5.4142 +10.4814i

-5.4142 -10.4814i

-8.1716

The unit step response of the uncompensated system with K =119.6589, is given by the

following dialogue:

>> M = feedback(K*G1,1)

Transfer function:

.............119.7 s + 957.3

-------------------------------------------

s^3 + 19 s^2 + 227.7 s + 1137

>> step(M)

Fig. M7.2

MATLAB MODULES

136 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

The step response is shown in Fig. M7.2; the peak time t p =0.296 sec.

The position error constant is

Therefore

Let us now fix specifications for design. Say, we want to design a PID controller so that the

closed-loop system operates with a peak time that is two-thirds that of the uncompensated system

at 20% overshoot, with zero steady-state error for a step input.

To compensate the system to reduce the peak time to two-thirds of the uncompensated system,

we must first find the compensated system's desired dominant pole location. The imaginary part

of the compensated dominant pole is

and the real part is

Next we design a PD compensator. We search for compensator's zero location so that the root

locus of the compensator system passes through the desired dominant pole location. If we are

using SISO Design Tool (described later in this module), the trial-and-error search for the

compensator zero is straightforward. Otherwise, we may proceed as follows.

Evaluate the angle contributed by all the poles and zeros of G(s) at s d = -8.1571+ j 15.9202

using the following MATLAB command:

>> Sd = -8.1571+15.9202i

Sd =

-8.1571 +15.9202i

MATLAB MODULES

137 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

angle_at_dominant_pole=(180/pi)*(angle(polyval([1,8],Sd))-(angle(polyval([1,3],Sd))...

+angle(polyval([1,6],Sd))+angle(polyval([1,10],Sd))))

angle_at_dominant_pole =

-198.4967

We find the sum of angles from uncompensated system's poles and zero to the desired

compensated dominant pole to be -198.4967o. Thus the contribution required from the

compensator zero is 198.4967 180 = 18.4967o. Assuming that compensator zero is located at

as shown in Fig. M7.3, we obtain

This gives

zc = 55.7467.

MATLAB MODULES

138 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Thus the PD controller is

The complete root locus for the PD-compensated system is sketched in Fig. M7.4. Using

rlocfind command, the gain at the design point is 5.2410. Complete analysis of PD-compensated

system is as follows:

>> D1 = s+55.7467;

>> rlocus(D1*G1);

>> sgrid(zeta,0);

>> [K,p]=rlocfind(D1*G1)

Select a point in the graphics window

selected_point =

-8.1043 +15.6832i

K =

5.2410

p =

-8.0799 +15.6914i

-8.0799 -15.6914i

-8.0812

The zeros are at -8,-55.7467. The effect of third closed-loop pole is nearly cancelled by a zero.

MATLAB MODULES

139 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M7.4

The PD-compensated system has settling time 0.454 sec., peak time 0.178 sec., and steady-state

error 0.072, as seen in simulation shown in Fig.M7.5.

>> M=feedback(K*D1*G1,1);

>> step(M)

We see the reduction in peak time and improvement in steady-state error over the

uncompensated system.

We now design a PI compensator to reduce the steady-state error to zero for a step input. Any PI

compensator will work as long as the zero is placed close to the origin. This ensures that PI

compensator will not change the transient response obtained with the PD compensator (The

placement of the zero of the PI compensator is not entirely arbitrary. The location of the zero

influences the magnitude of the relevant error constants. In the case of example under

consideration, the placement of the zero influences the magnitude of Kv ).

Choosing

MATLAB MODULES

140 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

we sketch the root locus for the PID-compensated system.

Fig. M7.5

The following session generates the root locus and simulates the PID-compensated system.

>> D2 = (s+0.5)/s

Transfer function:

s + 0.5

----------

.....s

>> D = D1*D2;

>> rlocus(D*G1)

>> sgrid(zeta,0)

>> [K,p]=rlocfind(D*G1)

Select a point in the graphics window

MATLAB MODULES

141 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

selected_point =

-7.2512 +14.3478i

K =

4.3928

p =

-7.4116 +14.3004i

-7.4116 -14.3004i

-8.1037

-0.4660

>> step(feedback(K*D*G1,1))

The zeros are at -0.5,-8,-55.7467. The effects of third and fourth closed-loop poles are nearly

cancelled by zeros.

MATLAB MODULES

142 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M7.6

MATLAB MODULES

143 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M7.7

Searching the 0.456 damping ratio line (Fig. M7.6), we find the dominant second-order poles to

be , with an associated gain of 4.3928. Simulation in Fig. M7.7 gives

settling time 2.67 sec, peak time 0.184 sec, and zero steady state error.

PD compensator improved the transient response by decreasing the time required to reach the

first peak as well as yielding some improvement in the steady-state error. The complete PID

controller further improved the steady-state error without appreciably changing the transient

response designed with the PD controller.

Example M7.2

Given a unity feedback position control system with forward path transfer function:

The goal is to design a cascade compensator to meet the following requirements (refer

Nise(2004)).

................(i) 25% overshoot, (ii) settling time: 2 sec, and (iii) Kv = 20.

MATLAB MODULES

144 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

The 25% overshoot corresponds to a damping ratio of 0.404. Consider the following MATLAB

session.

s = tf('s');

G1 = 6.63/((s)*(s+1.71)*(s+100));

zeta = 0.404;

rlocus(G1);

sgrid(zeta,0);

Properly redefine the axes of the root locus using Right click --> Properties --> Limits.

[K,p] = rlocfind(G1);

Select a point in the graphics window

selected_point =

-0.8057 + 1.8944i

>> K

K =

64.6665

>> p

p =

1.0e+002 *

-1.0004

-0.0083 + 0.0190i

-0.0083 - 0.0190i

MATLAB MODULES

145 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M.7.8

The intersection of 25% overshoot line with the root locus (Fig. M7.8) locates the system's

dominant second-order poles at and the gain at the dominant poles is

64.6665. The location of the third closed-loop pole is at 100.04; second-order approximation is

thus valid.

The simulation of the closed-loop system's step response is given by the following commands:

M = feedback(K*G1,1);

step(M);

MATLAB MODULES

146 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M7.9

Figure M7.9 shows that the design requirement of 25% overshoot is met.

The settling time is 4.07 sec. and

Comparing these values with the design requirements, we want to improve the settling time by a

factor of two and we want approximately eight-fold improvement in Kv .

We first attempt lead compensator design to improve transient response. To obtain a settling time

ts of 2 secs and 25% overshoot, the real part of dominant closed-loop poles should be at

and the imaginary part at

We now assume a lead compensator zero and find the compensator pole location so that lead-

compensated root locus passes through Let us assume compensator zero at

Angular contribution at the design point by open-loop poles and compensator zero

is obtained as follows:

MATLAB MODULES

147 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Sd = -2+4.5285i;

angle_at_dominant_pole=(180/pi)*(angle(polyval([1,2],Sd))-(angle(polyval([1,0],Sd))...

+angle(polyval([1,1.71],Sd))+angle(polyval([1,100],Sd))))

angle_at_dominant_pole =

-120.1384

Compensator pole must contribute 120.1384 -180 = -59.8616o for the design point to be on the

compensated system's root locus. From the geometry shown in Fig. M7.10,

This gives pc = 4.6291.

Thus the lead compensator is

MATLAB MODULES

148 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Root locus plot and its analysis for the lead-compensated system is given by the following

MATLAB session.

>> D1 = (s+2)/(s+4.6291);

>> rlocus(D1*G1);

>> sgrid(zeta,0)

Properly redefine the axes of the root locus using Right click --> Properties --> Limits .

>> [K,p] = rlocfind(D1*G1)

Select a point in the graphics window

selected_point =

-1.9621 + 4.4410i

K =

372.8743

p =

1.0e+002 *

-1.0026

-0.0200 + 0.0444i

-0.0200 - 0.0444i

-0.0208

>> step(feedback(K*D1*G1,1));

MATLAB MODULES

149 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M7.11

MATLAB MODULES

150 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M7.12

The transient response specifications are satisfied, with gain = 372.8743 (Figs. M7.11-M7.12).

The lead-compensated system Kv becomes

Since we want Kv=20, the amount of improvement required over the lead-compensated system is

20/6.2462=3.2. Choose pc =0.01 and calculate zc =0.0032, which is 3.2 times larger than pc, that

is we choose the lag compensator as

Root locus plot and its analysis for the complete lag-lead compensated system is given by the

following session:

D2 = (s+0.032)/(s+0.01);

rlocus(D1*D2*G1);

sgrid(zeta,0);

MATLAB MODULES

151 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Properly redefine the axes of the root locus using Right click --> Properties --> Limits.

>> [K,p] = rlocfind(D1*D2*G1)

Select a point in the graphics window

selected_point =

-1.9621 + 4.4410i

K =

373.5528

p =

1.0e+002 *

-1.0026

-0.0199 + 0.0444i

-0.0199 - 0.0444i

-0.0208

-0.0003

>> step(feedback(K*D1*D2*G1,1))

MATLAB MODULES

152 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M7.13

MATLAB MODULES

153 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M7.14

The design point has not moved with the addition of the lag compensator, and the gain at this

point is 373.5528 (Fig. M7.13). We also see from Fig. M7.14 that peak overshoot is higher than

specified. The system may be redesigned to reduce the peak overshoot.

Example M7.3

Consider a unity feedback system with the plant

The plant varies significantly:

It is desired to achieve robust behaviour (refer Dorf and Bishop (1998)). A design carried on the

nominal plant with K =1, gives the following cascade compensator.

For qualitative robustness analysis, we have obtained step response for the four conditions:

and . The results obtained using the

following MATLAB code, are summarized in Fig. M7.15, and Table M7.1.

s = tf('s');

G1 = 1/((s+1)^2);

G2 = 1/((0.5*s+1)^2);

G3 = 2/((s+1)^2);

G4 = 2/((0.5*s+1)^2);

D = (1+0.16*s)*(72.54+12/s);

M1 = feedback(G1*D,1);

M2 = feedback(G2*D,1);

M3 = feedback(G3*D,1);

MATLAB MODULES

154 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

M4 = feedback(G4*D,1);

step(M1);

hold;

step(M2);

step(M3);

step(M4);

The scale has been modified using Right click --> Properties -->Limits.

Fig. M7.15

Table M7.1

Plant conditions M1 (nominal

system)

M2 M3 M4

Percent 11.9 2.4 8.69 1.63

MATLAB MODULES

155 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

overshoot

Settling time

(sec)

0.551 0.155 0.40 0.0351

As is seen from this robustness analysis, the deviations from the nominal design performance do

not take the system outside the acceptable range; the design is therefore robust.

Example M7.4

A control system has the structure shown in Fig M7.16. The parameter variations are

and with the nominal conditions Km = 2 and p =4. Furthermore, a

third pole at s= 50 has been omitted from the model (refer Dorf and Bishop(1998)).

Fig. M7.16

A design carried out on the nominal system gives the following result.

We examine the performance of the system with nominal parameters Km =2, p =4; and worst-

case parameters Km =1.5, p =3. We also examine the nominal system with the third-pole added,

so that the control plant is

The robustness analysis results, obtained using the following MATLAB code, are summarized in

Fig. M7.17 and Table M7.2.

s = tf('s');

G1 = 2/(s*(s+4));

G2 = 1.5/(s*(s+3));

MATLAB MODULES

156 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

G3 = 2*50/(s*(s+4)*(s+50));

D = (1+0.06*s)*(294.69+4453/s);

M1 = feedback(G1*D,1);

M2 = feedback(G2*D,1);

M3 = feedback(G3*D,1);

step(M1);

hold;

step(M2);

step(M3);

The scale has been modified using Right click --> Properties -->Limits.

Fig M7.17

MATLAB MODULES

157 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Table M7.2

Plant conditions M1 (nominal

system)

M2 M3

Percent

overshoot

31.9 39.2 81.6

Settling time

(sec)

0.266 0.394 0.847

The system does not offer robust performance to parameter variations. The response of the

system with added pole shows that again the system fails the requirement of robust performance.

Since the results are not robust, it is possible to iterate on the design until an acceptable

performance is achieved.

The interactive capability of MATLAB allows us to check the robustness by simulation.

MATLAB MODULES

158 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 7

Root Locus Design and SISO Design Tools

MATLAB's SISO Design Tool

The SISO ( Single- Input/ Single- Output) Design Tool is a graphical user interface which

allows one to design single-input/single-output compensators by interacting with the root locus

plots and Bode plots of the closed-loop/open-loop systems. The tool also has the option of using

a Nichols chart, which can be selected under the View menu. After the tool produces these plots,

one can adjust the closed-loop poles along the root locus and read gain, damping ratio, natural

frequency, and pole locations. These changes immediately get reflected to Bode plots and

immediate changes in the system's closed-loop response can be viewed in the LTI Viewer for

SISO Design Tool window.

One can add poles, zeros, and compensators, which can be interactively changed to see the

immediate effects on the root locus, Bode plots, and time response.

With Bode plots, one can affect the gain change by shifting the Bode magnitude curve up and

down; and gain, gain margin, gain crossover frequency, phase margin, phase crossover

frequency, and whether the loop is stable or unstable can be checked. These changes

immediately get reflected to root locus plots and immediate changes in the system's closed-loop

response can be viewed in the LTI Viewer for SISO Design Tool window.

The following steps are required to use the SISO Design Tool.

1. Access the SISO Design Tool: The SISO Design Tool window, shown in Fig. M7.18, can be

accessed by typing sisotool in the MATLAB Command Window or by executing this command

in an M-file. In the block diagram given in the top-right corner of SISO Design Tool window, C

represents the compensator.

...............An interactive tutorial on SISO Design Tool can be invoked by selecting SISO Design

Tool Help under the SISO Design Tool window Help menu.

2. Create LTI transfer functions: Create open-loop LTI transfer functions for which you want

to analyze closed-loop characteristics or design compensators. The transfer functions can be

created in an M-file or in the MATLAB Command Window. Run the M-file or MATLAB

Command Window statements to place the transfer function in the MATLAB workspace. All

LTI objects in the MATLAB workspace can be exported to the SISO Design Tool .

MATLAB MODULES

159 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

The following MATLAB commands create the transfer function .

num=4500;

den=[1 361.2 0];

G=tf(num,den)

3. Create the closed-loop model for the SISO Design Tool: Choose Import… under the File

menu in the SISO Design Tool window to display the window shown in Fig. M7.19.

LTI objects can be selected from the SISO Models list and can be exported to one of the

blocks of the system by pressing the right-facing arrow next to the selected block ( G, H, F, or C

) located in the section of the window labeled System Data. Press the Other… button to rotate

through a selection of feedback structures and select the desired configuration. Alternatively, this

can also be done by pressing the FS button on the bottom right corner of closed-loop block

diagram in the SISO Design Tool window (Fig. M7.18). Root locus and Bode diagrams will

change immediately to reflect the changes in the feedback structure (Fig. M7.20).

LTI transfer function generating command, tf(num,den), can also be supplied directly into the

spaces for transfer functions in Fig. M7.19.

MATLAB MODULES

160 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M7.18 SISO Design Tool window

4. Interact with the SISO Design Tool: After the Import System Data window closes, the

SISO Design Tool window now contains the root locus and Bode plots for the system as shown

in Fig. M7.20. In this example, we have considered the open-loop system given by

.

MATLAB MODULES

161 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Under the Analysis menu, select the desired response to open the LTI Viewer for SISO Design

Tool window (Fig. M7.21). Right-click on the LTI Viewer for SISO Design Tool and choose

desired Plot Types, Systems, and Characteristics.

Fig. M7.19 Import System Data Window

Loop gain can be changed in three different ways:

i. In Root Locus Editor: Keep the mouse pointer on a closed-loop pole (squares)

on the root locus. The arrow cursor changes to a hand. Hold down the left mouse

button and drag the closed-loop pole along the root locus. Bode plot and the

closed-loop response in the LTI Viewer will immediately change to reflect the

gain change. The value of the gain will be displayed in the Current

Compensator section of the SISO Design Tool window.

ii. In Open-Loop Bode Editor: Keep the mouse pointer anywhere on the Bode

magnitude curve. The arrow cursor changes to a hand. Hold down the left mouse

button and shift the curve up or down. Root locus and closed-loop response in the

LTI Viewer will immediately change to reflect the gain change.

MATLAB MODULES

162 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

iii. In the Current Compensator Window: Type the desired gain value in the C(s)=

box in the SISO Design Tool window.

With gain changes, you can read the gain and phase margins and gain crossover and

phase crossover frequencies at the bottom of the Bode magnitude and phase plots. Also,

at the bottom of the Bode magnitude plot, you are told whether or not the closed-loop

system is stable.

Fig. M7.20 Root locus and Bode plots of G in SISO Design Tool window

MATLAB MODULES

163 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M7.21 LTI Viewer for SISO Design Tool window

5. Design constraints: Design constraints may be added to your plots. These constraints

may be selected by right-clicking a respective plot and selecting Design Constraints. To

put new constraints, choose New… and to edit existing constraints, choose Edit… . For

example, Fig.M7.22 shows the selection of design constraint: damping ratio=0.5. On

pressing OK, indicators appear identifying portions of the root locus where the damping

ratio is less than 0.5(shaded gray), equal to 0.5(damping line), and greater than 0.5(

Fig.M7.23 ). Note the change made in axes limits in this figure with respect to Fig.M7.20

using the Property Editor (the description of the Property Editor is given in the next

step).

Constraints may also be edited on the plots. Two black squares appear on the

constraint. You can drag these with your mouse anywhere in the plot region. Point the

mouse at the boundary of the constraint. When it changes to four-pointed arrow, you can

MATLAB MODULES

164 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

drag the boundary to a new position. The values of the constraints are displayed in the

Status Bar at the bottom of the plots.

Fig. M7.22 Adding design constraints

Fig.M7.23 Adding design constraints

MATLAB MODULES

165 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

6. Properties: Right-clicking in a plot's window and selecting Properties… displays the

Property Editor window. From this window, some of the properties of the plot such as

axes labels and limits can be controlled. Try exploring various options available with root

locus and Bode plot properties editor.

7. Add poles, zeros, and compensators: Poles and zeros may be added from the SISO

Design Tool window toolbar shown in Fig. M7.23. Let your mouse pointer rest on the

button for a few seconds to see the functionality of the button in the form of screen tips.

Add real pole; Add real zero; Add complex pole; Add complex zero; Delete

pole/zero; ..... functions are available.

Use the SISO Design Tool toolbar and select the desired real/complex pole/zero

compensator. Move the mouse on the plots; your cursor shows that a compensator was

selected.. Place the cursor arrow to the point on the root locus or Bode plot where you

want to add the compensator, and click. The compensator will be updated in the Current

Compensator section of the SISO Design Tool window. Compensator addition will be

reflected immediately in the root locus, Bode plots, and LTI Viewer for SISO Design

Tool window.

Go to SISO Tool Preferences… --> Options under the Edit menu to change the way the

compensator is represented.

8. Editing compensators and prefilters: The pole and zero values of the compensators

and prefilters can be edited in several ways. The most convenient is to click on C or F

blocks in the block diagram representation in top-right corner of the SISO Design Tool

window (Fig. M7.23).This operation will open prefilter or compensator editor window

shown in Fig. M7.24. Desired real/complex zero/pole locations can be edited here. The

same windows can also be opened by following Compensators Edit C or F from

the SISO Design Tool window.

In control systems design, we use compensators of the form

that alter the roots of the characteristic equation of the closed-loop system. However, the

closed-loop transfer function, M(s), will contain the zero of D(s) as a zero of M(s).This

zero may significantly affect the response of the system M(s). We may use a prefilter F(s)

to reduce the effect of this zero on M(s). For example, if we select

we cancel the effect of the zero without changing the dc gain.

MATLAB MODULES

166 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Prefilters may be employed with lead/PD compensation.

Fig. M7.24 Editing compensators and prefilters

Example 7.4

Consider a plant with the following transfer function:

MATLAB MODULES

167 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

We will design a cascade controller using SISO Design Tool in interactive mode, so that

the unity feedback closed-loop system meets the following criteria (refer Kuo and

Golnaraghi(2003)):

Steady-state error due to unit-ramp input 0.000443

Maximum overshoot 5 percent

Rise time 0.002 sec

Settling time sec

The first step is to import the model into SISO Design Tool. System transfer functions

can be imported in SISO Design Tool by clicking on File and then going to Import…

Before executing this sequence, create transfer function G in MATLAB Command

Window:

num=4500;

den=[1 361.2 0];

G=tf(num,den)

In order to examine the system performance, we start by using a proportional controller.

The system root locus can be obtained by clicking on View in the main menu and then

selecting Root Locus only. Fig. M7.25 shows the root locus of the system. The plot is for

K =1(by default).

MATLAB MODULES

168 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M7.25

In order to see the poles and zeros of G and H , go to the View menu and select System

Data, or alternatively, double click the block G or H in the top-right corner of the block

diagram in the SISO Design Tool window. The System Data window is shown in

Fig.M7.26.

MATLAB MODULES

169 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M7.26

You may obtain the closed-loop system poles by selecting Closed-Loop Poles from the

View menu. Closed-loop poles are given in Fig.M7.27.

Fig. M7.27

MATLAB MODULES

170 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

In order to see the closed-loop system time response to a unit-step input, select the

Response to Step Command in the Analysis main menu. With specific selections made

in Systems and Characteristics submenus, we generate Fig. M7.28, which shows the

unit step response of the closed-loop system with unity gain controller, i.e. , K= 1.

Fig. M7.28

As a first step to design a controller, we use the built-in design criteria option within the

SISO Design Tool to establish the desired closed-loop poles regions on the root locus.

To add the design constraints, use the Edit menu and choose the Root Locus option.

Select New to enter the design constraints. The Design Constraints option allows the

user to investigate the effect of the following:

o Settling time

o Percent overshoot

o Damping ratio

MATLAB MODULES

171 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

o Natural frequency

We will use the settling time and the percent overshoot as primary constraints. After

designing a controller based on these constraints, we will determine whether the system

complies with the rise time constraint or not. Figure M7.29 shows the addition of settling

time constraint. Peak overshoot constraint is added on similar lines.

Fig. M7.29

Figure M7.30 shows the desired closed-loop system pole locations on the root locus after

inclusion of the design constraints (Note that the scale has been modified by following

Right click --> Properties --> Limits. Left-clicking anywhere inside plot will remove

the black squares on the zeta lines). Obviously, closed-loop poles of the system for K = 1

are not in the desired area. Note the definition of the desired area: the vertical gray bar

signifies the boundary for that portion of the root locus where the settling time

requirement is not met; and the gray bars on damping lines signify the boundary for that

portion of the root locus where the peak overshoot requirement is not met.

Changing K will affect the pole locations. In the Root Locus window, C(s) represents the

controller transfer function. Fig.M7.30 corresponds to C(s) = K = 1 . Hence, if C(s) is

increased, the effective value of K increases, forcing the closed-loop poles to move

together on the real axis, and then ultimately to move apart to become complex. See Fig.

M7.31 wherein K= 16.8 gives closed-loop poles on the damping lines. However, the

settling time requirement is not met.

MATLAB MODULES

172 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M7.30

MATLAB MODULES

173 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M7.31

The closed-loop poles of the system must lie to the left of the boundary imposed by the

settling time(Fig.M7.31). Obviously, it is impossible to use the proportional controller

(for any value of K ) to move the poles of the closed-loop system farther to the left-hand

plane. However, a PD controller C(s)= K (1+ sTD ) may be used to accomplish this task.

The zero s = - 1/ TD of the compensator has to be placed far into the left half plane to

move the root-locus plot to the left. We have tried various values:

s = - 1/0.0005; - 1/0.001; - 1/0.0015; - 1/0.002,...

The value s = -1/0.00095 gives satisfactory results.

To add a zero to the controller, click the C block in the block diagram in top-right corner

of Fig. M7.31. Fig.M7.32 shows the Edit Compensator window and how the PD

controller is added:

MATLAB MODULES

174 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M7.32

Figure M7.33 shows the plot for s= - 1/0.00095. Note that the closed-loop poles have

been dragged to the desired locations. The value of K that achieves the desired dominent

closed-loop poles is 282. This value of K forces the closed-loop poles to the desired

region. The system closed-loop poles are shown in Fig. M7.34.

MATLAB MODULES

175 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M7.33

MATLAB MODULES

176 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M7.34

The step response of the controlled system in Fig. M7.35 shows that the system has now

complied with all design criteria.

MATLAB MODULES

177 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M7.35

MATLAB MODULES

178 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 8

Stability Analysis on Bode / Nyquist Plots

Objectives:

Introducing MATLAB commands for Bode and Nyquist plots.

Stability analysis using these plots .

As with the root locus plots, it will be tempting to rely exclusively on MATLAB to obtain Bode,

Nyquist, and other frequency-response plots. We strongly recommend that MATLAB should be

treated as one tool in the tool kit that can be used to design and analyze control systems. There is

no substitute for a clear understanding of the underlying theory.

MATLAB font does not permit the frequency symbol , which will appear as w in our

MATLAB codes. Also note that the default unit for frequency is rad/sec. This can be altered, if

required, to hertz by editing the plot axes; but we will continue to use rad/sec

Bode Plots

Nyquist Plots

Stability Margins

MATLAB MODULES

179 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 8

Stability Analysis on Bode / Nyquist Plots

Bode Plots

For a given transfer function G(s), Bode plot can be produced in different ways:

1. By simply using the command

bode (G)

We will get the Bode plot of G(s) in the current window for a default frequency range set by the

MATLAB package. MATLAB will automatically choose the frequency values by placing more

points in regions where the frequency response is changing rapidly. Fig. M8.1 shows the Bode

diagram for the transfer function

generated by the following code.

s = tf('s');

G = (s+1)/(0.1*s+1);

bode(G);

MATLAB MODULES

180 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M8.1

2. To produce a Bode plot over a specified frequency range wmin to wmax, we use the

command

bode (G, {wmin, wmax})

For example, bode(G,{0.1,10}) will produce a Bode plot in the range 0.1 to 10 rad/sec, shown in

Fig. M8.2.

MATLAB MODULES

181 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M8.2

If we supply the vector

w = [0.1; 0.3; 0.5; 0.7; 0.9; 1.0; 3.0; 5.0; 7.0; 9.0; 10];

and type

bode (G,w)

MATLAB will compute the magnitude and phase at the frequency points supplied in the

frequency vector.

If you choose to specify the frequencies explicitly, it is desirable to generate the vector w using

the logspace function. logspace (d1,d2) generates a vector of 50 points logarithmically equally

spaced between decades 10d1

and 10d2

. (50 points include both endpoints. There are 48 points

between the endpoints). To generate 50 points between 0.1 rad/sec and 100 rad/sec, enter the

command

w = logspace (-1,2)

logspace(d1,d2,n) generates n points logarithmically equally spaced between decades 10d1

and

10d2

( n points include both endpoints). For example, to generate 100 points between 1 rad/sec

and 1000 rad/sec, enter the command

MATLAB MODULES

182 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

w = logspace (0,3,100)

3. When invoked with left-hand arguments, such as

[mag,phase,w] = bode (G)

bode returns the frequency response of the system in variables mag, phase and w. No plot is

drawn on the screen. The magnitude and phase characteristics are placed in the workspace

through the matrices mag and phase. The vector w contains the values of the frequency in

rad/sec at which the magnitude and phase will be calculated.

If we supply the vector w and type

[mag, phase, w] = bode (G,w)

MATLAB will use the frequency vector supplied and compute the magnitude and phase at those

frequency points. This is clear from the following MATLAB session.

>> w = logspace(-1, 1, 5)

w =

0.1000 0.3162 1.0000 3.1623 10.0000

>> [mag,phase,w]=bode(G,w)

mag(:,:,1) =

1.0049

mag(:,:,2) =

1.0483

mag(:,:,3) =

1.4072

mag(:,:,4) =

3.1623

mag(:,:,5) =

7.1063

MATLAB MODULES

183 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

phase(:,:,1) =

5.1377

phase(:,:,2) =

15.7372

phase(:,:,3) =

39.2894

phase(:,:,4) =

54.9032

phase(:,:,5) =

39.2894

w =

0.1000

0.3162

1.0000

3.1623

10.0000

MATLAB does not assume that the system is a SISO system, but allows greater flexibility for

dealing with more complex systems. MATLAB stores mag and phase variables as matrices of

dimension p x q x n, where p is the number of inputs, q is the number of outputs, and n is the

number of frequency points. For SISO systems, the dimension of mag and phase will be

To access the magnitude and phase points for pth input and q

th output, we have to write

mag(p, q, :) or phase(p, q, :). For example,

>> mag(1,1,3)

ans =

1.4072

>> phase(1,1,3)

MATLAB MODULES

184 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

ans =

39.2894

For SISO systems, mag(:,:,3) and phase(:,:,3) will also give the same answer.

We use mag(:,:)', phase(:,:)' to convert arrays to column vectors, where the apostrophe signifies

matrix transpose. For example, the following command stores points of the Bode plot in matrix

form with magnitude in dB, phase in degrees, and frequency in rad/sec.

bode_points = [w, 20*log10( mag(:,:)' ), phase(:,:)' ]

Information about the plots obtained with bode can be found by left-clicking the mouse on the

curve. You can find the curve's label, as well as the coordinates of the point on which you

clicked. Right-clicking away from a curve brings up a menu. Form this menu, you can select (i)

system responses to be displayed (magnitude plot, phase plot, or both), and (ii) characteristics,

such as peak response and stability margins. When selected, a dot appears on the curve at the

appropriate point. Let your mouse rest on the point to read the value of the characteristic. You

may also (iii) select the frequency units in Hz., magnitude in absolute, phase in radians, (iv) set

axis limits, and (v) grid etc.

A Bode plot with grid selected is shown in Fig. M8.3.

Fig. M8.3

MATLAB MODULES

185 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 8

Stability Analysis on Bode / Nyquist Plots

Nyquist Plots

We can use MATLAB to make Nyquist plots using the command nyquist(G). Information about

the plots obtained with this command can be found by left-clicking the mouse on the curve. You

can find the curve's label, as well as the coordinates of the point on which you have clicked and

the frequency. Right-clicking away from a curve brings up a menu. From this menu, you can

select (i) system responses to be displayed (with and without negative frequencies), and (ii)

characteristics, such as peak response and stability margins. When selected, a dot appears on the

curve at the appropriate point. Let your mouse rest on the point to read the value of the

characteristic. You may also (iii) select the frequency units in Hz., (iv) set axis limits, and (v)

grid etc.

We can obtain points on the plot by using [re im w] = nyquist(G), where the real part,

imaginary part, and frequency are stored in re, im, and w, respectively. re and im are 3-

dimensional arrays. We use re(:,:)' and im(:,:)' to convert the arrays to column vectors. We can

specify the range of w by using [re,im] = nyquist(G,w).

A sample Nyquist plot generation is illustrated below.

s = tf('s');

G = 1/(s^2+0.8*s+1);

nyquist(G);

axis equal;

MATLAB MODULES

186 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M8.4

Axis used should be ' equal ', otherwise circles appear squashed.

Note that when a MATLAB operation involves ' Divide by zero ', the resulting Nyquist plot may

be erroneous. For example, Nyquist plot of

is shown in Fig. M8.5.

G=1/((s)*(s+1));

nyquist(G)

MATLAB MODULES

187 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M8.5

If such an erroneous Nyquist plot appears, then it can be corrected by manipulating the axes. For

example, manipulating the x-axis to [-2,2] and y-axis to [-5,5] in Fig. M8.5, results in the

Nyquist plot shown in Fig. M8.6.

MATLAB MODULES

188 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M8.6

Sometimes in the course of using the nyquist function, we may find that a Nyquist plot looks

nontraditional or that some information appears to be missing. It may be necessary in these cases

to adjust the axes and override the automatic scaling, and/or to use the nyquist function with

left-hand arguments with specified frequency range in conjunction with the plot function. In this

way we can focus on the critical region for our stability analysis.

MATLAB MODULES

189 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 8

Stability Analysis on Bode / Nyquist Plots

Stability Margins

We use [GM, PM] = margin(G) to find gain margin (GM) and phase margin (PM).

We use [GM, PM, wg, wphi] = margin(G) to find gain margin (GM), phase margin (PM), gain

crossover frequency (wg), and phase crossover frequency (wphi).

The margin function is invoked in conjunction with the bode function to compute gain and phase

margins. If the margin(G) is invoked without left-hand arguments, the Bode plot is

automatically generated with gain margin, phase margin, gain crossover frequency, and phase

crossover frequency labeled on the plot. This is illustrated in Fig. M8.7.

s = tf('s');

G = 1/(s^2+0.8*s+1);

margin(G);

MATLAB MODULES

190 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M8.7

Stability margins, and gain and phase crossover frequencies are also given by the right-clicking

feature on the plots generated using the MATLAB functions nyquist and

MATLAB MODULES

191 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 9

Frequency Response Characteristics

Non-unity Feedback Systems

Example M9.1

Consider a non-unity feedback system with forward-path transfer function

and feedback-path transfer function

Resonance peak, resonance frequency, and bandwidth of the closed-loop frequency response

may be obtained by generating Bode plot of the closed-loop transfer function.

s = tf('s');

G = 10/(s*(s+5));

H = 1/(0.1*s+1);

M = feedback(G,H);

w = logspace(-1,1);

bode(M,w);

grid;

This MATLAB program produces Bode plots for the closed-loop system shown in Fig.M9.1.

Right-clicking away from a curve brings up a menu. From this menu, select Characteristics -->

Peak Response. When selected, a dot appears on the curve at the appropriate point Let your

mouse rest on the point to read the parameters of the resonance peak. Now point the mouse at

any point on the magnitude curve and left-click. The arrow curser changes to four-pointed arrow.

Hold down the left mouse button and drag the four-pointed arrow along the magnitude curve. By

MATLAB MODULES

192 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

trial-and-error, locate the point where magnitude is - 3dB. The frequency at this point is the

bandwidth.

Fig. M9.1

From Fig.M9.1, we obtain the following:

Mr = 0.311dB, = 1.53 rad/sec., and = 3.38 rad/sec.

The gain margin and phase margin can be obtained from the Bode plot of G(s)H(s). The Bode

plot and the performance measures generated by the command margin(G*H) are shown in Fig.

M9.2.

MATLAB MODULES

193 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M9.2

MATLAB MODULES

194 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 9

Frequency Response Characteristics

Unity Feedback Systems on Nichols Chart

Nichols chart can be generated using the nichols(G) function for the MATLAB transfer function

G. If the nichols function is invoked without left-hand arguments, the Nichols chart is

automatically generated; otherwise one must use nichols in conjunction with the plot function. A

Nichols grid can be drawn with the ngrid function.

Information about the plots obtained with nichols(G) can be found by left-clicking the mouse on

the curve. You can find the curve's label, as well as the coordinates of the point on which you

clicked, and the frequency. Right-clicking away from a curve brings up a menu. From this menu,

you can select characteristics, such as peak response and stability margins. When selected, a dot

appears on the curve at the appropriate point Let your mouse rest on the point to read the value

of the characteristic. You may also select choice for grid on or off, returning to full view after

zooming, and properties, such as labels, limits, units, style, and characteristics.

Example M 9.2

Consider a unity feedback system with open-loop transfer function

To produce a Nichols chart for the given system, with the closed-loop dB M-contours

superimposed, use the commands:

s = tf('s');

G = 45/(s*(s+5));

w = 0.5:50;

nichols(G,w);

ngrid;

MATLAB MODULES

195 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

The corner frequency of the lag term is at w = 5 rad/sec. We will like to include a range of

frequencies a decade above and below this corner frequency. Setting the frequency range from

0.5 to 50 rad/sec meets our requirements.

Fig. M9.3

We see from Fig. M9.3 that the response line is nearly tangential to the 3dB M -contour.

Therefore the closed-loop frequency has no peak value above 3dB. Resonance frequency, read

from the plot, is 5.79 rad/sec.

The intersection of the response line with - 3dB contour gives the bandwidth of the closed-loop

system. Bandwidth, read from Fig.M9.3,is 9.37 rad/sec.

Gain and phase margins can also be determined from Nichols chart. However, the margin

function is a convenient alternative.

Example M9.3

MATLAB MODULES

196 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

In this example, we study how to adjust the system gain to meet specifications on gain margin,

phase margin, bandwidth and resonance peak. We consider a unity feedback system with open-

loop transfer function

to illustrate the design process.

Bode plot generated using the command margin(G) for K = 1 is shown in Fig. M9.4.

s = tf('s');

G = 6.63/((s)*(s+1.71)*(s+100));

margin(G)

In order to find the range of K for stability, we notice from Fig.M9.4 that gain margin is 68.4 dB.

Therefore the gain can be raised by

before the system is driven to the verge of instability.

Reconsider the system with K = 1. We now intend to find the gain K required for a closed-loop

response of 20% overshoot for a step input. Using second-order approximation, a 20% overshoot

implies a damping ratio of 0.456 and, this implies a phase margin of about 48 degrees. The phase

angle should therefore be at gain crossover frequency. Point the mouse at

any point on the phase curve and left-click. The arrow curser changes to four-pointed arrow.

Hold down the left mouse button and drag the four-pointed arrow along the phase curve. By

trial-and-error, locate the point where the phase is - 132o.

The phase angle is at 1.5 rad/sec where the gain is dB (Fig. M9.4). Thus

for 20% overshoot.

Since the system is third-order, the second order approximation should be checked. Figure M9.5

shows the step response generated using the following code.

K = 52.48;

M = feedback(K*G,1);

step(M);

MATLAB MODULES

197 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M9.4

From Fig. M9.5, we find the peak overshoot 20.6%.

MATLAB MODULES

198 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M9.5

Example M9.4

Consider a unity feedback system with open-loop transfer function

The Nichols chart for K = 1 is shown in Fig. M9.6.

s = tf('s');

G = 20/(500*s^2+60*s+1);

nichols(G)

The scale has been modified using Right click --> Properties --> Limits .

MATLAB MODULES

199 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M9.6

We would like to alter K to provide a closed-loop resonance peak of 1dB. Finding a value of K to

meet this specification is not as straightforward as satisfying a gain margin or phase margin

specification. This is because it is not easy by inspection to locate the point on the original curve

which would become tangential to the required M-contour. We proceed by trial-and-error.

Luckily, the use of MATLAB makes this a fairly simple procedure and we find that by trying a

couple of gain values, we can 'home in' on the most appropriate gain setting.

For the design problem under consideration, the trial-and-error gives a gain adjustment by a

factor of 8.25/20. That is, reduction of gain by 7.69 dB.

Similar trial-and-error procedure can be used to meet the specifications on bandwidth.

Example M9.5

We can use MATLAB and frequency response methods to include the time delay in the loop.

Consider a unity feedback system with the transfer function

MATLAB MODULES

200 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

The response of the following MATLAB script is given in Fig. M9.7. The scale has been

modified using Right click --> Properties -->Limits.

s = tf('s');

G = 1/(s*(s+1)*(s+10));

bode(G);

hold;

G1 = G;

G1.InputDelay = 1;

bode(G1);

In LTI object G1 created by MATLAB, input delay can be accessed by G1. InputDelay. In our

case, deadtime is 1 second; the command G1.InputDelay=1 sets the deadtime in the transfer

function model, as seen from the following MATLAB response.

>> G1

Transfer function:

...................................1

exp(-1*s) * ----------------------------

....................s^3 + 11 s^2 + 10s

MATLAB MODULES

201 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M9.7

MATLAB MODULES

202 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 10

Frequency Response Design and SISO Design Tool

Objectives:

Design using Bode plots and Nichols chart.

Frequency response design using SISO Design Tool.

We will carry out Control system design using MATLAB dialogues. MATLAB is an interpreted

language. That is, it runs along executing each instruction as it comes to it. This interactive

feature of MATLAB will be exploited in our design exercise. The designer will always be in the

loop.

The MATLAB SISO Design Tool, developed on the MATLAB dialogue pattern, is a powerful

GUI tool, wherein the designer is always in the design loop. We have outlined this tool earlier in

MATLAB Module 7. An example of frequency response design using this tool will be given at

the end of this module.

Design Using MATLAB Dialogues

Robustness Analysis

Design Using SISO Design Tool

MATLAB MODULES

203 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 10

Frequency Response Design and SISO Design Tool

Design Using MATLAB Dialogues

Example M10.1

A unity feedback system has forward path transfer function

Our goal is to design a cascade PD compensator so that the closed-loop system meets the

following specifications (refer Kuo and Golnaraghi (2003)).

Steady-state error due to unit-ramp input 0.000443

Phase angle

Resonance peak

Bandwidth

We want to achieve a steady-state response that has no more than 0.000443 error due to unit-

ramp input. This, as we know, can be achieved by simple gain adjustment. We therefore first

evaluate the „uncompensated system' that meets the steady-state accuracy requirement. K should

be set at 181.17.

We now examine the performance of the uncompensated system. The following MATLAB

dialogue is helpful:

s = tf('s');

G = (4500*181.17)/(s*(s+361.2));

figure(1);

margin(G);

MATLAB MODULES

204 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

grid;

figure(2);

nichols(G);

ngrid;

Fig. M10.1

MATLAB MODULES

205 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M10.2

Since the plot in Nichols coordinate system does not touch any of the M-contours

available by default in the ngrid command, we may generate Bode plot of uncompensated

feedback system to obtain resonance peak Mr.

MATLAB MODULES

206 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M10.3

The uncompensated system with K = 181.17 has (Figs M10.1-10.3) a phase margin

gain crossover frequency resonance peak Mr = 2.5527 (

Mr=108.14/20

), and bandwidth

A PD compensator with transfer function

has asymptotic Bode plot of the form shown in Fig. M10.4.

MATLAB MODULES

207 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

The logical way to approach the design problem is to first examine how much additional phase is

needed to realize a of 80o. Since the uncompensated system with the gain set to meet the

steady-state requirement has of only 22.6o, the PD compensator must provide an additional

phase of 80 22.6=57.4o. The additional phase must be placed at the desired gain crossover

frequency of the compensated system in order to realize a of 80o.

Referring to the asymptotic Bode plot of PD compensator shown in Fig. M10.4, we see that the

additional phase at frequencies > 1/ TD is always accompanied by a gain in the magnitude curve.

As a result, the gain crossover of the compensated system will be pushed to a higher frequency.

At new gain crossover, the phase of the uncompensated system would correspond to smaller

. Thus we may run into the problem of diminishing returns.

MATLAB MODULES

208 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Simple trial-and-error placement of corner frequency of the compensator around the gain

crossover frequency can meet the design requirements. The performance measures in the

frequency domain for the compensated system with the compensator parameters: TD = 0.0005,

0.001, 0.0015, 0.002, and 0.0017, are tabulated in Table M10.1. With TD = 0.0017, the

performance requirements in frequency domain are all satisfied.

Table M10.1

T D

M r =10 dB/20

0.0005 46.1 913 1330 1.3630

0.001 65.5 1060 1590 1.1311

0.0015 78.5 1320 1600 1.0464

0.002 85.5 1660 2050 1.0125

0.0017 81.9 1450 1650 1.0292

The following MATLAB dialogue gives one result of Table M10.1:

Td = 0.0017;

D = 1+Td*s;

figure(1);

margin(D*G);

grid;

figure(2);

nichols(D*G);

ngrid;

figure(3);

bode(feedback(D*G,1));

MATLAB MODULES

209 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Example M10.2

Let us reconsider the system of Example M10.1 (refer Kuo and Golnaraghi (2003)). Initially we

take gain K = 181.17 simply because the value was used in Example M10.1. We will tune the

total loop gain later to meet the steady-state performance requirement.

The uncompensated system with K =181.17 has =22.6o and gain crossover frequency

(refer Fig. M10.1). Let us specify to be atleast 64o , and ess (parabolic

input)

We know that PI compensator is an approximation for the lag compensator:

The asymptotic Bode plot of a PI compensator is shown in Fig. M10.5.

MATLAB MODULES

210 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

From the Bode plot of uncompensated system (Fig. M10.6), we find that the new gain crossover

frequency at which the phase margin is 64o, is 173 rad/sec. The magnitude of at this

frequency is 21.4 dB. Thus the PI compensator should provide an attenuation of 21.4 dB at =

173 rad/sec.

s = tf('s');

G = (4500*181.17)/(s*(s+361.2));

margin(G);

MATLAB MODULES

211 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M10.6

A simple trial-and-error for values of that are sufficiently small (low- frequency

range) can meet the design requirements. The performance measures in the frequency domain for

the compensated system with the compensator parameters: KP = and KI=

0.00851, 0.0851, 0.851, and 1.702, are tabulated in Table M10.2. Note that for the values of KP /

KI = that are sufficiently small, all vary little. We choose KI = 0.0851.

With this value of KI, the performance requirements in frequency domain are all satisfied.

Table M10.2

KI

Mr=10 dB/20

0.00851 64.3 173 279 1.0022

0.0851 64.1 173 285 1.0070

0.851 61.1 173 324 1.0572

1.702 57.7 174 323 1.1171

The following MATLAB dialogue gives one of the results of Table M10.2.

MATLAB MODULES

212 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

KI = 0.0851;

D = 0.0851+(KI/s);

figure(1);

margin(D*G);

grid;

figure(2);

nichols(D*G);

ngrid;

figure(3);

bode(feedback(D*G,1));

Let us now evaluate the steady-state performance.

Steady-state requirement is thus satisfied.

It should be noted that of the system can be improved further by increasing the value of

above 1/0.0851. However, the bandwidth of the system will be reduced. For example, for

is increased to 75.7o but is reduced to 127 rad/sec.

Example M10.3

Consider the unity-feedback system whose open-loop transfer function is

The system is to be compensated to meet the following specifications:

MATLAB MODULES

213 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

1. Velocity error constant K v = 30.

2. Phase margin .

3. Bandwidth .

It easily follows that K =30 satisfies the specification on KV. The Bode plot of with K

=30 is shown in Fig. M10.7 from which it is found that the uncompensated system has a gain

crossover frequency and phase margin = 17.2o .

s = tf('s');

G = 1/(s*(0.1*s+1)*(0.2*s+1));

K = 30;

margin(K*G);

Fig. M10.7

MATLAB MODULES

214 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

If lag compensation is employed for this system, the bandwidth will decrease sufficiently so as to

fall short of the specified value of 12 rad/sec, resulting in a sluggish system. This fact can be

verified by designing a lag compensator. If on the other hand, lead compensation is attempted,

the bandwidth of the resulting system will be much higher than the specified value; the closed-

loop system will be sensitive to noise, which is undesirable. This fact can also be verified by

designing a lead compensation scheme.

Let us design a lag-lead compensator to overcome the difficulties mentioned above. Since a full

lag compensator would reduce the system bandwidth excessively, the lag section of the lag-lead

compensator must be designed to provide partial compensation only. The lag section design

therefore proceeds by making a choice of the new gain crossover frequency, which must be

higher than the crossover frequency if the system were fully lag compensated. Full lag

compensation demands that the gain crossover frequency should be shifted to a point where the

phase angle of the uncompensated system is:

+specified phase margin +

From Fig. M10.7, we find that this requirement is met at 2.1 rad/sec. For the design of lag

section of lag-lead compensator, the selected gain crossover frequency should be higher than 2.1.

The choice is made as to start with.

From Fig. M10.7, we find that the gain of the uncompensated system at is 20.3 dB.

Therefore to bring the magnitude curve down to 0 dB at , the lag section must provide an

attenuation of 20.3 dB. This gives the parameter of the lag section as

Let us now place the upper corner frequency of the lag section at 1/0.8 rad/sec. This gives the

lag-section transfer function

Bode plot of lag-section compensated system is shown in Fig. M10.8; the phase margin is 23.8o.

D1 = (0.8*s+1)/(8*s+1);

margin(D1*K*G);

MATLAB MODULES

215 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M10.8

We now proceed to design the lead section. We choose The maximum phase lead

provided by the lead section is therefore

The lag-compensated system has a gain of at 5.6 rad/sec. Setting

(the frequency at which the lead section has maximum phase ) = 5.6 rad/sec, we get

.

Take the lead section as

MATLAB MODULES

216 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

From the Bode plot and Nichols chart of the lag-lead compensated system (Figs M10.9 and

M10.10), we find that the phase margin is 55.7 o and the bandwidth is 12.5 rad/sec. The design

therefore does meet the specifications laid down.

D1 = (0.8*s+1)/(8*s+1);

D2 = (0.565*s+1)/(0.0565*s+1);

figure(1);

margin(D1*D2*K*G);

figure(2);

nichols(D1*D2*K*G);

grid;

Fig.M10.9

MATLAB MODULES

217 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig.M10.10

MATLAB MODULES

218 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 10

Frequency Response Design and SISO Design Tool

Robustness Analysis

Example M10.4

A unity feedback system has the plant

It is desired to achieve robust performance. A design carried out on nominal plant with K =1 and

p0 = 1, gives the following cascade compensator (refer Dorf and Bishop (1998)).

We examine here the robustness properties of this controller for a range of plant parameter

variations of with K =5. We also examine the robustness for variations in K with

p0 fixed at 1. The results generated using the following MATLAB code are displayed in Figs

M10.11 and M10.12.

s = tf('s');

G11 = 5/((s+0.1)^2);

G21 = 5/((s+1)^2);

G31 = 5/((s+10)^2);

D = (1+0.137*s)*(4222+26300/s);

M11 = feedback(G11*D,1);

M21 = feedback(G21*D,1);

M31 = feedback(G31*D,1);

figure(1);

MATLAB MODULES

219 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

step(M11);

hold;

step(M21);

step(M31);

G12 = 1/((s+1)^2);

G22 = 2/((s+1)^2);

G32 = 5/((s+1)^2);

M12 = feedback(G12*D,1);

M22 = feedback(G22*D,1);

M32 = feedback(G32*D,1);

figure(2);

step(M12);

hold;

step(M22);

step(M32);

The scale has been modified using Right click --> Properties -->Limits.

MATLAB MODULES

220 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M10.11 Variations in p0

MATLAB MODULES

221 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M10.12 Variations in K

The simulation results indicate that the PID design is robust with respect to changes in p0 and K.

The differences in the step response for are barely discernible on the plot.

Example M10.5

A unity feedback system has the nominal plant

A cascade design on the nominal system:

We examine here the robustness of the system with respect to deadtime in the loop (refer Dorf

and Bishop (1998)). Simulations were carried out with

with and 0.4 secs. The results are summarized in Fig. M10.13 and Table M10.3. The

MATLAB script is given below.

s = tf('s');

G = 3/(3.1*s+1);

D = (1+0.06*s)*(3.22+2.8/s);

M1 = feedback(G*D,1);

[numd1,dend1]=pade(0.1,2);

[numd2,dend2]=pade(0.4,2);

del_1 = tf(numd1,dend1);

del_2 = tf(numd2,dend2);

MATLAB MODULES

222 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Gd1 = G*del_1;

Gd2 = G*del_2;

M2 = feedback(Gd1*D,1);

M3 = feedback(Gd2*D,1);

step(M1);

hold;

step(M2);

step(M3);

The scale has been modified using Right click --> Properties -->Limits.

Fig. M10.13

MATLAB MODULES

223 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Table M10.3

Plant

conditions

M1

(zero deadtime)

M2

(deadtime=0.1)

M3

(deadtime = 0.4)

Percent

overshoot

6.78 8.57 89.4

Settling

time (sec)

3.3 2.89 7.03

Robustness analysis shows that the design is acceptably robust if deadtime is less than 0.1 sec.

However, for large deadtimes of the order of 0.4 sec., the design is not robust. It is possible to

iterate on the design until an acceptable performance is achieved.

The interactive capability of MATLAB allows us to check the robustness by simulation.

MATLAB MODULES

224 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

MATLAB MODULE 10

Frequency Response Design and SISO Design Tool

Design Using SISO Design Tool

Example 10.6

Let us reconsider Example M10.1 (refer Kuo and Golnaraghi (2003)). Given a plant with

the transfer function

we will design a cascade controller using SISO Design Tool in interactive mode, so that the unity

feedback closed-loop system meets the following criteria:

Steady-state error due to a unit-ramp input 0.000443

Phase margin 800

Resonant peak M r

BW 2000 rad/sec

Create transfer function G in MATLAB Command Window:

num=4500;

den=[1 361.2 0];

G=tf(num,den)

Access the SISO Design Tool window by typing sisotool in the MATLAB Command Window.

Now import the model G into SISO Design Tool . System transfer functions can be imported in

SISO Design Tool by clicking on File... and then going to Import…

In order to examine the system performance, we start by using a proportional controller. To

examine the performance of the proportional controller, we need to find the system Bode plots.

The Bode plots can be obtained by clicking on View in the main menu and then selecting Open-

MATLAB MODULES

225 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Loop Bode only. Fig. M10.14 shows the Bode plot of the system. The plot is for C(s) = K =1(by

default).

Fig. M10.14

We want to achieve a steady-state response that has no more than 0.000443 error due to unit-

ramp input. This, as we know, can be achieved by simple gain adjustment. We therefore first

evaluate the „uncompensated system' that meets the steady-state accuracy requirement. K should

be set at 181.17.

In the Current Compensator window, type the desired gain value in the C(s) = box.

Fig.M10.15 shows the Bode plots with C(s) = K =181.17. The uncompensated system with K =

181.17 has a phase margin and gain crossover frequency

MATLAB MODULES

226 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig.M10.15

To determine resonance peak and bandwidth of the uncompensated system, we can select Open-

Loop Nichols under the View menu. Fig.M10.16 shows the Nichols chart. The pointer when

taken near the open-loop frequency response curve, changes into hand. Move the hand along the

curve till it grips the point of intersection of open-loop frequency response curve with the – 3 dB

contour. Fig.M10.16 corresponds to this position; from the data given at the bottom portion of

this figure, we obtain bandwidth of the uncompensated system=1400 rad/sec (Dragging the hand

on zoomed Nichols chart will give better resolution).

MATLAB MODULES

227 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M10.16

Since the plot in Nichols coordinate system does not touch any of the M -contours

available by default in the grid, we may use Bode plot of uncompensated feedback system to

obtain resonance peak Mr. Select Closed-Loop Bode under the Analysis menu. Fig.M10.17

shows the closed-loop Bode plot. Right-clicking anywhere shows a submenu. Select

Characteristics ---> Peak Response. Fig.M10.17 corresponds to this selection. We get

resonance peak Mr = 2.5527 ( Mr=108.14/20

).

MATLAB MODULES

228 | P a g e e n g r k k u m a w a t 2 0 1 2 @ g m a i l . c o m r a h u l k u m a w a t 7 2 @ g m a i l . c o m

Fig. M10.17

We attempt a PD compensator design with transfer function

Simple trial-and-error placement of corner frequency of the compensator around the gain

crossover frequency can meet the design requirements. The performance in the frequency

domain for the compensated system with the compensator parameters: TD = 0.0005, 0.001,

0.0015, 0.002, and 0.0017 was examined. With TD = 0.0017, the performance requirements in

frequency domain are all satisfied. Examining this using SISO Design Tool will be a good

exercise.