You are on page 1of 12

MATLAB functions

MATLAB provides a rich library of functions to control and simulation. We


combined transfer functions (tf-command), loop them in feedback model
(feedback command), find their zero plots, and gains (zpk command), and plot the
response behavior when subjected to standard (step, ramp, impulse) or nonstandard inputs.
The transfer function can also be represented in the state-space form, and analog or
digital control solution be obtained. Apart from analysis in the time domain and
frequency domain, one can get the stability margins as well as the basic control
system design processes. The basic commands used in MATLAB are under as
Control system tool box the a rich library of functions apart from the the control
system tool box which provides the basic functionality, additional tool box may be
employed which includes Simulink, fuzzy logic, model predictive control tool box,
robust control, simulink control design tool box and system identification tool box.

Sources on MATLAB
Some of useful resources available function library MATLAB programming
especially related to control engineering are given in
(i)
(ii)

www.mathsworks.com
MATLAB Programming for Engineers by Stephen J Chapman, Thomson
Books, Singapore, 2002

(iii)

Representation of Block Diagram


Each block in the control diagram has a transfer function which is of the general
form
( ) =

()
()

(1)

Where N(s) is the numerator polynomial and D(s) is the denominator polynomial
in Laplace variable s.
Let () = + 1 1 + + 0
() = + 1 1 + + 0
The coefficient of the numerator and denominator polynomials are needed to build
G(s). The MATLAB command used for this purpose is tf
= ([ 1 0 ], [ 1 0 ])
This will store the transfer function given by equation (1) in the variable g
Connection of Blocks
Two blocks could be connected in series, parallel or in feedback mode. Although
MATLAB supports the building of multiple interconnections between the blocks.
We shall learn here two simple commands named series and parallel. If g1 and
g2 are there two transfer function in series we can write

1 ()

2 ()
2 = (1 (), 2 ())
=( 1 , 2 )

If the blocks are connected in parallel as shown


+

B
+

2
Then the corresponding command to express this relationship is
2 = (1 , 2 )
Another very important mode commonly used in controls is feedback. The
standard block diagram with g as forward transfer function and h as feedback
transfer function with negative feedback.

A r

2 =

1 +

This can be represented in MATALAB by using the feedback command. Thus for
figure 3,
a2b=feedback(g1h).
Once we have learnt these four basic operations to develop the control the transfer
function we shall try to solve some examples.
Let a transfer function between two point A and B be given as
1
2 + 3

2 = ([1], [2 3])

3
5 + 6

2
3 2

1 = ([3], [5 6])
2 = ([2], [3 2])
2 = (1, 2)

Consider the following block diagram


+
A
( 2

2
+ 2 + 4)

B
+

1+
3

(2 2

1
+ 3 + 4)

1
1+

Time Response of Systems using MATLAB


Now that we have been able to express the transfer function between the input and
output (presently we are focusing on the single input and single output system)
variable in term of Laplace s. the next step is to study the behavior of the system
in the time. MATLAB provides a good variety of standard functions to help us,
study the performance of the system with a given transfer function. Remember that
these performance curves are equally valid for open loop as well as closed loop
system and will give the performance according to the transfer function given as
input.
These performance curves includes step response, impulse response, initial value
response polar plot, pole zero plot, bode plot, and also includes response of the
system to arbitrary input. We shall study each of these with examples.
Consider the system given by the following diagram

100
1+

The MATLAB Command


a2b=feedback(tf[100] [1 1], tf[2])
gives transfer function

a2b=

100

+201

when this system is subjected to a step input the response can be plotted by the
command
7

step (a2b)
The reponse figure as shown below is generated by MATLAB.

Step Response

0.5

Amplitude

0.4
0.3
0.2
0.1
0
0

0.005

0.01

0.015 0.02
Time (sec)

0.025

0.03

Also note that by putting the grid on modifier the graph can be plotted with the
grid display. The range of this graph is automatically decided by the MATLAB.
However user can specify her own time interval or discrete time steps at which the
response would be plotted. Then command modifies to
step(a2b,t)
Where t could either be a number representing Tfinal ( plot will be generated from
0 to Tfinal) or it could also be a vector of equi-spaced time interval
eg. step(a2b,.02)
or t=0.1;0.01;0.4;
step(a2b,t) gives the plot as
8

shown

Step Response

0.4975
0.4975

Amplitude

0.4975
0.4975
0.4975
0.4975
0.4975
0.1

0.15

0.2

0.25
Time (sec)

0.3

0.35

one of the important response plots of the system is its response to initial condition.
For an nth order system (degree of highest power of s occurring in the transfer
function ) n initial conditions are required, which are specified in the vector
form. The general command syntax used is
initial(sys, x0)
where x0 is the value of
,

at t=0

Consider the transfer function

()
()

= a2b =

1
( 2 +0.1+10)

the initial conditions being


= 0,

=1
9

= 0, = 1

(second order2 initial figure)


We shall use the command
a2b=tf([1],[1 0.1 10])
the function initial works on the state space model. Thus we first need to convert
the model transfer function format to state space format. This being a second order
transfer function would require two states to describe the system. Thus the state
matrix would be 2X2
the syntax function tfzss (transfer function to state space )is
[A,B, C, D]=ftzss(a,b)
Where a and b are the representation of the numerator and denominator
polynomial coefficients.
Thus we shall use
[A,B,C,D]=tfzss([1],[1 0.1 10])
The state space formulation has the general form
= +
= +
Where {x} is state vector and {y} is output vector, {u} is the forcing function for
initial value problems. There is no external force hence {u}=0; and if we are
interested directly in the state variable. We need to solve, only the first equation
which is a differential equation.
=
The syntax function solution boned by
10

A2bs=ss(A,[ ],C,[ ])
a2bs is the system description in state space and then use the command function
initial response after defining the initial condition
1
{x0}={ } = [1 1]
1
Initial (a2bs, x0) will give the response

as shown in figure below

(initial second order figure)


As explain in the previous section step response , the command initial can also be
extended to get the response of the system at specific interval of time. Thus
T=linspace(0,10,100)
Generate a vector of 100 points starting from 0 to 10 (initial 0 and 10 is the last
point)
Initial (a2bs , x0,t) gives the following output which is the initial response between 0
to 10 second.
(initial second order2 figure)

We shall also explore the response of the system (defined by the transfer function
or state- space) to an arbitrary input.
We define an input is as shown as

10
11

In the figure thus

u=0.5t 0<t<10

u=5 t>10 we shall create two array u and t of the same dimension so that for any
time t the corresponding value of forcing function u is at the same location
(index n.)
let t=0: 0.1:20;
this will generate 200 points from 0 to 200sec at an interval of 0.1. The response
of the system to this arbitrary input is generated by
lsim (a2b,u,t,x0)

12

You might also like