Accelerating the pace of engineering and science

# Documentation

## Linear (LTI) Models

### What Is a Plant?

Typically, control engineers begin by developing a mathematical description of the dynamic system that they want to control. The system to be controlled is called a plant. As an example of a plant, this section uses the DC motor. This section develops the differential equations that describe the electromechanical properties of a DC motor with an inertial load. It then shows you how to use the Control System Toolbox™ functions to build linear models based on these equations.

### Linear Model Representations

You can use Control System Toolbox functions to create the following model representations:

• State-space models (SS) of the form

$\begin{array}{l}\frac{dx}{dt}=Ax+Bu\\ y=Cx+Du\end{array}$

where A, B, C, and D are matrices of appropriate dimensions, x is the state vector, and u and y are the input and output vectors.

• Transfer functions (TF), for example,

$H\left(s\right)=\frac{s+2}{{s}^{2}+s+10}$

• Zero-pole-gain (ZPK) models, for example,

$H\left(z\right)=3\frac{\left(z+1+j\right)\left(z+1-j\right)}{\left(z+0.2\right)\left(z+0.1\right)}$

• Frequency response data (FRD) models, which consist of sampled measurements of a system's frequency response. For example, you can store experimentally collected frequency response data in an FRD model.

 Note   The design of FRD models is a specialized subject that this guide does not address. See Frequency Response Data (FRD) Models for a discussion of this topic.

### SISO Example: The DC Motor

A simple model of a DC motor driving an inertial load shows the angular rate of the load, $\omega \left(t\right)$, as the output and applied voltage, ${\upsilon }_{app}\left(t\right)$, as the input. The ultimate goal of this example is to control the angular rate by varying the applied voltage. This figure shows a simple model of the DC motor.

A Simple Model of a DC Motor Driving an Inertial Load

In this model, the dynamics of the motor itself are idealized; for instance, the magnetic field is assumed to be constant. The resistance of the circuit is denoted by R and the self-inductance of the armature by L. If you are unfamiliar with the basics of DC motor modeling, consult any basic text on physical modeling. With this simple model and basic laws of physics, it is possible to develop differential equations that describe the behavior of this electromechanical system. In this example, the relationships between electric potential and mechanical force are Faraday's law of induction and Ampère's law for the force on a conductor moving through a magnetic field.

#### Mathematical Derivation

The torque $\tau$ seen at the shaft of the motor is proportional to the current i induced by the applied voltage,

$\tau \left(t\right)={K}_{m}i\left(t\right)$

where Km, the armature constant, is related to physical properties of the motor, such as magnetic field strength, the number of turns of wire around the conductor coil, and so on. The back (induced) electromotive force, ${\upsilon }_{emf}$, is a voltage proportional to the angular rate $\omega$ seen at the shaft,

${\upsilon }_{emf}\left(t\right)={K}_{b}\omega \left(t\right)$

where Kb, the emf constant, also depends on certain physical properties of the motor.

The mechanical part of the motor equations is derived using Newton's law, which states that the inertial load J times the derivative of angular rate equals the sum of all the torques about the motor shaft. The result is this equation,

$J\frac{dw}{dt}=\sum {\tau }_{i}=-{K}_{f}\omega \left(t\right)+{K}_{m}i\left(t\right)$

where ${K}_{f}\omega$ is a linear approximation for viscous friction.

Finally, the electrical part of the motor equations can be described by

${\upsilon }_{app}\left(t\right)-{\upsilon }_{emf}\left(t\right)=L\frac{di}{dt}+Ri\left(t\right)$

or, solving for the applied voltage and substituting for the back emf,

${\upsilon }_{app}\left(t\right)=L\frac{di}{dt}+Ri\left(t\right)+{K}_{b}\omega \left(t\right)$

This sequence of equations leads to a set of two differential equations that describe the behavior of the motor, the first for the induced current,

$\frac{di}{dt}=-\frac{R}{L}i\left(t\right)-\frac{{K}_{b}}{L}\omega \left(t\right)+\frac{1}{L}{\upsilon }_{app}\left(t\right)$

and the second for the resulting angular rate,

$\frac{d\omega }{dt}=-\frac{1}{J}{K}_{f}\omega \left(t\right)+\frac{1}{J}{K}_{m}i\left(t\right)$

#### State-Space Equations for the DC Motor

Given the two differential equations derived in the last section, you can now develop a state-space representation of the DC motor as a dynamic system. The current i and the angular rate ω are the two states of the system. The applied voltage, ${\upsilon }_{app}$, is the input to the system, and the angular velocity ω is the output.

$\frac{d}{dt}\left[\begin{array}{c}i\\ \omega \end{array}\right]=\left[\begin{array}{cc}-\frac{R}{L}& -\frac{{K}_{b}}{L}\\ \frac{{K}_{m}}{J}& -\frac{{K}_{f}}{J}\end{array}\right]\cdot \left[\begin{array}{c}i\\ \omega \end{array}\right]+\left[\begin{array}{c}\frac{1}{L}\\ 0\end{array}\right]\cdot {\upsilon }_{app}\left(t\right)$

State-Space Representation of the DC Motor Example

$y\left(t\right)=\left[\begin{array}{cc}0& 1\end{array}\right]\cdot \left[\begin{array}{c}i\\ \omega \end{array}\right]+\left[0\right]\cdot {\upsilon }_{app}\left(t\right)$

### Building SISO Models

After you develop a set of differential equations that describe your plant, you can construct SISO models using simple commands. The following sections discuss

• Constructing a state-space model of the DC motor

• Converting between model representations

• Creating transfer function and zero/pole/gain models

#### Constructing a State-Space Model of the DC Motor

Enter the following nominal values for the various parameters of a DC motor.

```R= 2.0 % Ohms
L= 0.5 % Henrys
Km = .015 % torque constant
Kb = .015 % emf constant
Kf = 0.2 % Nms
J= 0.02 % kg.m^2
```

Given these values, you can construct the numerical state-space representation using the ss function.

```A = [-R/L -Kb/L; Km/J -Kf/J]
B = [1/L; 0];
C = [0 1];
D = [0];
sys_dc = ss(A,B,C,D)
```

These commands return the following result:

```a =
x1           x2
x1           -4        -0.03
x2         0.75          -10

b =
u1
x1            2
x2            0

c =
x1           x2
y1            0            1

d =
u1
y1            0

```

#### Converting Between Model Representations

Now that you have a state-space representation of the DC motor, you can convert to other model representations, including transfer function (TF) and zero/pole/gain (ZPK) models.

Transfer Function Representation.  You can use tf to convert from the state-space representation to the transfer function. For example, use this code to convert to the transfer function representation of the DC motor.

```sys_tf = tf(sys_dc)

Transfer function:
1.5
------------------
s^2 + 14 s + 40.02
```

Zero/Pole/Gain Representation.  Similarly, the zpk function converts from state-space or transfer function representations to the zero/pole/gain format. Use this code to convert from the state-space representation to the zero/pole/gain form for the DC motor.

```sys_zpk = zpk(sys_dc)

Zero/pole/gain:
1.5
-------------------
(s+4.004) (s+9.996)
```
 Note   The state-space representation is best suited for numerical computations. For highest accuracy, convert to state space prior to combining models and avoid the transfer function and zero/pole/gain representations, except for model specification and inspection.

#### Constructing Transfer Function and Zero/Pole/Gain Models

In the DC motor example, the state-space approach produces a set of matrices that represents the model. If you choose a different approach, you can construct the corresponding models using tf, zpk, ss, or frd.

```sys = tf(num,den)               % Transfer function
sys = zpk(z,p,k)                % Zero/pole/gain
sys = ss(a,b,c,d)               % State-space
sys = frd(response,frequencies) % Frequency response data
```

For example, you can create the transfer function by specifying the numerator and denominator with this code.

```sys_tf = tf(1.5,[1 14 40.02])

Transfer function:
1.5
------------------
s^2 + 14 s + 40.02
```

Alternatively, if you want to create the transfer function of the DC motor directly, use these commands.

```s = tf('s');
sys_tf = 1.5/(s^2+14*s+40.02)
```

These commands result in this transfer function.

```Transfer function:
1.5
--------------------
s^2 + 14 s + 40.02
```

To build the zero/pole/gain model, use this command.

```sys_zpk = zpk([],[-9.996 -4.004], 1.5)
```

This command returns the following zero/pole/gain representation.

```Zero/pole/gain:
1.5
-------------------
(s+9.996) (s+4.004)
```

### Constructing Discrete Time Systems

The Control System Toolbox software provides full support for discrete-time systems. You can create discrete systems in the same way that you create analog systems; the only difference is that you must specify a sample time period for any model you build. For example,

```sys_disc = tf(1, [1 1], .01);
```

creates a SISO model in the transfer function format.

```Transfer function:
1
-----
z + 1

Sampling time: 0.01
```

#### Adding Time Delays to Discrete-Time Models

You can add time delays to discrete-time models by specifying an input delay, output delay, or I/O delay when building the model. The time delay must be a nonnegative integer that represents a multiple of the sampling time. For example,

```sys_delay = tf(1, [1 1], 0.01,'ioDelay',5)
```

returns a system with an I/O delay of 5 s.

```Transfer function:
1
z^(-5) * -----
z + 1

Sampling time: 0.01
```

### Adding Delays to Linear Models

You can add time delays to linear models by specifying an input delay, output delay, or I/O delay when building a model. For example, to add an I/O delay to the DC motor, use this code.

```sys_tfdelay = tf(1.5,[1 14 40.02],'ioDelay',0.05)
```

This command constructs the DC motor transfer function, but adds a 0.05 second delay.

```Transfer function:
1.5
exp(-0.05*s) * ------------------
s^2 + 14 s + 40.02
```

For a complete description of adding time delays to models and closing loops with time delays, see Models with Time Delays.

### LTI Objects

For convenience, the Control System Toolbox software uses custom data structures called LTI objects to store model-related data. For example, the variable sys_dc created for the DC motor example is called an SS object. There are also TF, ZPK, and FRD objects for transfer function, zero/pole/gain, and frequency data response models respectively. The four LTI objects encapsulate the model data and enable you to manipulate linear systems as single entities rather than as collections of vectors or matrices.

To see what LTI objects contain, use the get command. This code describes the contents of sys_dc from the DC motor example.

```get(sys_dc)
a: [2x2 double]
b: [2x1 double]
c: [0 1]
d: 0
e: []
StateName: {2x1 cell}
InternalDelay: [0x1 double]
Ts: 0
InputDelay: 0
OutputDelay: 0
InputName: {''}
OutputName: {''}
InputGroup: [1x1 struct]
OutputGroup: [1x1 struct]
Name: ''
Notes: {}
UserData: []
```

You can manipulate the data contained in LTI objects using the set command; see the Control System Toolbox online reference pages for descriptions of set and get.

Another convenient way to set or retrieve LTI model properties is to access them directly using dot notation. For example, if you want to access the value of the A matrix, instead of using get, you can type

```sys_dc.a
```

at the MATLAB® prompt. This notation returns the A matrix.

```ans =

-4.0000   -0.0300
0.7500  -10.0000
```

Similarly, if you want to change the values of the A matrix, you can do so directly, as this code shows.

```A_new = [-4.5 -0.05; 0.8 -12.0];
sys_dc.a = A_new;
```