Defining Transfer Systems in MATLAB

There are two forms of transfer function representation in MATLAB. The most obvious is the polynomial form where

G(s)=b(s)a(s)=s2+2s+3s3+4s2+5s+6

is entered as two row vectors with the polynomial coefficients entered in the order of descending powers of s.

imatlab_export_fig('print-svg')  % Static svg figures.
Copy to clipboard
b = [1, 2, 3];
a = [1, 4, 5, 6];
Copy to clipboard

Missing coefficients, must be entered as zero: so q(s)=s2+2s and r(s)=s4+s2+1 are entered as

q = [1, 2, 0];
r = [1, 0, 2, 0, 1];
Copy to clipboard

An alternative form of representation for transfer functions is the factored polynomial, for example

G(s)=(s+1)(s+3)s(s+2)(s+4)

The advantage of this formulation is that the zeros of the numerator and denominator polynomials are obvious by inspection. So it is often used in the preliminary analysis of the performance of a dynamic system. The poles of this transfer function are s=0,2,4 and the zeros are s=1,3.

In MATLAB, this form of transfer function is specified by a column vector of the zeros and a column vector of the poles:

z = [-1; -3];
p = [0; -2; -4];
Copy to clipboard

A third parameter, the overall gain K, completes the definition of the so called pole-zero-gain form of transfer function. In this case K=1:

K = 1;
Copy to clipboard

The Linear Time Invariant System Object

Starting from version 4 of the Control System Toolbox (distributed with MATLAB version 5), the Mathworks introduced a new data object for the creation and manipulation of system transfer functions. This object is called the Linear Time Invariant (LTI) System Object. It is used to gather the components of a transfer function (or state-space model) into a single variable which can then easily be combined with other LTI system objects.

To create a LTI system object representing a factored transfer function the following command is issued:

G = zpk(z,p,K)
Copy to clipboard
G =
Copy to clipboard
   (s+1) (s+3)
Copy to clipboard
  -------------
Copy to clipboard
  s (s+2) (s+4)
Copy to clipboard
Continuous-time zero/pole/gain model.
Copy to clipboard

The expanded numerator and denominator form of the transfer function is readily obtained by using a “data extraction” function.

[num,den]=tfdata(G,'v')
Copy to clipboard
num =
     0     1     4     3
Copy to clipboard
den =
     1     6     8     0
Copy to clipboard

LTI system objects can also be created from the expanded form of a transfer function directly:

G2=tf(num,den)
Copy to clipboard
G2 =
Copy to clipboard
    s^2 + 4 s + 3
Copy to clipboard
  -----------------
Copy to clipboard
  s^3 + 6 s^2 + 8 s
Copy to clipboard
Continuous-time transfer function.
Copy to clipboard

and the zeros and poles similarly extracted:

[zeros,poles,gain]=zpkdata(G2,'v')
Copy to clipboard
zeros =
    -3
    -1
Copy to clipboard
poles =
     0
    -4
    -2
Copy to clipboard
gain =
     1
Copy to clipboard

Setting LTI Properties

Numerous options are available to document the LTI system objects that you create. For example, suppose the transfer function G represents a servomechanism with input 'Voltage' and output 'Angular Position'. We can add this information to the LTI system as follows:

set(G,'inputname','Voltage','outputname','Angular Position');
G
Copy to clipboard
G =
Copy to clipboard
  From input "Voltage" to output "Angular Position":
Copy to clipboard
   (s+1) (s+3)
Copy to clipboard
  -------------
Copy to clipboard
  s (s+2) (s+4)
Copy to clipboard
Continuous-time zero/pole/gain model.
Copy to clipboard

Such documentary information is probably best added when the LTI system object is created, for example as:

G3=zpk(z,p,K,'inputname','Armature Voltage (V)',... 
'outputname','Load Shaft Position (rad)',... 
'notes','An armature voltage controlled servomechanism')
Copy to clipboard
G3 =
Copy to clipboard
  From input "Armature Voltage (V)" to output "Load Shaft Position (rad)":
Copy to clipboard
   (s+1) (s+3)
Copy to clipboard
  -------------
Copy to clipboard
  s (s+2) (s+4)
Copy to clipboard
Continuous-time zero/pole/gain model.
Copy to clipboard

Once the LTI object has been documented, the documentation can be extracted using commands like:

get(G3,'notes')
Copy to clipboard
ans =
  1x1 cell array
    {'An armature voltage controlled servomechanism'}
Copy to clipboard

All the documentation available on an LTI system object may be extracted with a single command:

get(G3)
Copy to clipboard
                Z: {[2x1 double]}
                P: {[3x1 double]}
                K: 1
    DisplayFormat: 'roots'
         Variable: 's'
          IODelay: 0
       InputDelay: 0
      OutputDelay: 0
               Ts: 0
         TimeUnit: 'seconds'
        InputName: {'Armature Voltage (V)'}
        InputUnit: {''}
       InputGroup: [1x1 struct]
       OutputName: {'Load Shaft Position (rad)'}
       OutputUnit: {''}
      OutputGroup: [1x1 struct]
            Notes: {'An armature voltage controlled servomechanism'}
         UserData: []
             Name: ''
     SamplingGrid: [1x1 struct]
Copy to clipboard

There are numerous other documentation features provided for LTI system objects. Please consult the on-line help for set and get for full details.

System Transformations

MATLAB supports the easy transformation of LTI system objects between expanded and factored forms1. For example to convert a transfer function from ‘expanded’ form to pole-zero-gain form the following command is used:

G4 = zpk(G2)
Copy to clipboard
G4 =
Copy to clipboard
   (s+3) (s+1)
Copy to clipboard
  -------------
Copy to clipboard
  s (s+4) (s+2)
Copy to clipboard
Continuous-time zero/pole/gain model.
Copy to clipboard

To convert from zero-pole-gain form to expanded form we use the function tf:

G5 = tf(G)
Copy to clipboard
G5 =
Copy to clipboard
  From input "Voltage" to output "Angular Position":
Copy to clipboard
    s^2 + 4 s + 3
Copy to clipboard
  -----------------
Copy to clipboard
  s^3 + 6 s^2 + 8 s
Copy to clipboard
Continuous-time transfer function.
Copy to clipboard

Please note that these transformations are merely a convenience that allow you to work with your preferred form of representation. Most of the tools that deal with LTI system objects will work with any form2.

Combining LTI System Objects

A powerful feature of the LTI system object representation is the ease with which LTI objects can be combined. For example, suppose we have two transfer functions

G1(s)=s+1s+3

and

G2(s)=10s(s+2)

then the series combination of the two transfer functions Gs(s)=G1(s)G2(s) is obtained using the “*” (multiplication) operator:

G1=tf([1 1],[1 3]);
G2=tf(10,conv([1 0],[1 2])); % conv is polynomial multiplication
Gs=G1*G2 % series connection of two sys objects
Copy to clipboard
Gs =
Copy to clipboard
      10 s + 10
Copy to clipboard
  -----------------
Copy to clipboard
  s^3 + 5 s^2 + 6 s
Copy to clipboard
Continuous-time transfer function.
Copy to clipboard

The parallel connection of two LTI system objects corresponds to addition Gp=G1(s)+G2(s):

Gp = G1 + G2
Copy to clipboard
Gp =
Copy to clipboard
  s^3 + 3 s^2 + 12 s + 30
Copy to clipboard
  -----------------------
Copy to clipboard
     s^3 + 5 s^2 + 6 s
Copy to clipboard
Continuous-time transfer function.
Copy to clipboard

The feedback connection of two LTI system objects is also supported. The function feedback is used for this.

Let

G(s)=2s2+5s+1s2+2s+3

be the forward transfer function of a closed-loop system and

H(s)=5(s+2)(s+10)

be the feedback network. Then the closed-loop transfer function3 is

Gc(s)=G(s)1+G(s)H(s).

In MATLAB:

G = tf([2 5 1],[1 2 3],'inputname','torque',...
'outputname','velocity');
H = zpk(-2,-10,5);
Gc = feedback(G,H) % negative feedback assumed
Copy to clipboard
Gc =
Copy to clipboard
  From input "torque" to output "velocity":
Copy to clipboard
  0.18182 (s+0.2192) (s+2.281) (s+10)
Copy to clipboard
  -----------------------------------
Copy to clipboard
   (s+3.419) (s^2 + 1.763s + 1.064)
Copy to clipboard
Continuous-time zero/pole/gain model.
Copy to clipboard

The Analysis of LTI System Objects

MATLAB uses the LTI system objects as parameters for the analysis tools such as impulse, step, nyquist, bode, nichols and rlocus.

As an example of their use try:

rlocus(G*H) % root locus 
Copy to clipboard
../_images/mattf_37_0.svg
bode(G*H)% open-loop frequency response 
Copy to clipboard
../_images/mattf_38_0.svg
step(Gc) % closed-loop step response
Copy to clipboard
../_images/mattf_39_0.svg
bode(Gc) % closed-loop frequency response
Copy to clipboard
../_images/mattf_40_0.svg

Matlab also provides two interactive graphical tools that work with LTI system objects.

  • linearSystemAnalyzer is a graphical tool that can be used to analyze systems defined by LTI objects. It provides easy access to LTI objects and time and frequency response analysis tools.

  • controlSystemDesigner is an interactive tool for designing controllers.

You are encouraged to experiment with these tools.

Partial Fraction Expansions

MATLAB provides a command called residue that returns the partial fraction expansion of a transfer function. That is, given

G(s)=sm+bm1sm1++b1s+b0sn+an1sn1++a1s+a0

it returns

R1s+p1+R2s+p2+Rns+pn+K(s)

where pi are the poles of the transfer function, ri are the coefficients of the partial fraction terms (called the residues of the poles) and K(s) is a remainder polynomial which is usually empty.

To use this, the starting point must (rather perversely) be the expanded form of the transfer function in polynomial form. Thus given

C(s)=5(s+2)s(s+3)(s+10)

we obtain the partial fraction expansion using the MATLAB command sequence:

k = 5; z = [-2]; p = [0; -3; -10]; % zero-pole-gain form 
C = zpk(z,p,k); 
[num,den] = tfdata(C,'v')
Copy to clipboard
num =
     0     0     5    10
Copy to clipboard
den =
     1    13    30     0
Copy to clipboard

(Note that the leading terms in num are zero).

[r,p,k] = residue(num,den)
Copy to clipboard
r =
   -0.5714
    0.2381
    0.3333
Copy to clipboard
p =
   -10
    -3
     0
Copy to clipboard
k =
     []
Copy to clipboard

which we interpret to mean

C(s)=0.3333s+0.2381s+30.5714s+5.

If C(s) represents the step response of the system

G(s)=5(s+2)(s+3)(s+10)

then the step response is, by inspection,

c(t)=0.3333ϵ(t)+0.2381e3t0.5714e10t.

You can check this with the command:

newC = tf([5, 10],[1, 13, 30])
step(newC)
Copy to clipboard
newC =
Copy to clipboard
     5 s + 10
Copy to clipboard
  ---------------
Copy to clipboard
  s^2 + 13 s + 30
Copy to clipboard
Continuous-time transfer function.
Copy to clipboard
../_images/mattf_48_7.svg

(where the 1/s term has been eliminated because step provides the forcing function itself). This should give exactly the same results as:

t = 0:.05:1.5; % time vector 
c = 0.3333 + 0.2381 * exp(-3*t) - 0.5714 * exp(-10*t);
plot(t,c),...
title('Step response'),...
xlabel('Time (seconds)'),...
ylabel('Amplitude'),...
grid
Copy to clipboard
../_images/mattf_50_0.svg

Read More

The Mathworks official documentation on LTI Objects is Linear (LTI) Models.

Footnotes

  1. You can also convert to and from state-space forms.
  2. This is the most significant change from version 4 of MATLAB. There were, for example several forms of the function for obtaining step-responses (`step(num,den)`, `step(A,B,C,D)`) now there is just one `step(sys)`.
  3. Assuming negative feedback.