Modeling 101
Modeling 101
com Page 1
System Modeling 101
Dr.Varodom Toochinda
http://www.controlsystemslab.com
May 2011
In any model-based control design scheme, it is essential to first obtain a math model of the
physical system, or the plant we want to control. The design then exploits that information in
certain way to craft a controller for that particular plant, subjecting to user specifications or
design constraints. So it is rational to say, regardless of any sophisticated design paradigm or
software tool used, that a controller will be as good as the model that represents the actual plant.
There are 2 basic approaches to achieve a math model of a physical system. The first relies on
theory. One can start from physics; i.e., form an equation and substitute parameters, either from
datasheet or measurement. The second approach uses data captured from the real plant and tries
to identify the math model from such information. The latter is generally classified as system
identification.
This article introduces some common modeling and identification methods, with emphasis on
practical issues. Examples from our past research are provided.
Physic-based modeling
For simple dynamics, such as a passive electronic circuit or a DC motor, a math model
can be obtained from laws of physics. For example, many dynamic systems are governed by
differential equations. In case the system of interest is linear, or can be linearized around an
operating point, Laplace transform can be used to get a model in the form of transfer function,
which is convenient for classical control analysis and design. One problematic step for this
approach is how to get accurate information of the plant parameters, especially when datasheet(s)
of the device(s) used in the plant is unavailable. In some case the parameters can be measured
and then plugged in the equation. Note that in some modern software tool such as
Matlab/Simulink, a hybrid scheme is provided. A user can select a particular form of equation
for a DC motor, say, then ask the software to find the best approximation of parameters using
data from the real motor. In some systems, other techniques such as finite element analysis can
be used as an alternative to find a model, or to cross check the result obtained from physic-based
modeling approach.
www.controlsystemslab.com Page 2
Example 1: Brushed DC motor
Figure 1 shows a small brushed DC motor used for lab experiment, together with a drive
circuit. We want to demonstrate how to obtain a math model using knowledge from physics. To
simplify the discussion, we address only the armature circuit of DC motor connected with a
mechanical load in Figure 2, and neglect the drive unit. The goal is to find a transfer function
from the armature voltage input v
a
to the shaft angle output u
m
. Start from applying Newtons
law to form a differential equation that describes the rotational mechanics
t u u = +
m m m
b J
(1)
and use Kirchhoffs Voltage Law (KVL) for the armature circuit
e v i R i L
a a a a a
= +
(2)
Notice the electromotive force (emf) voltage e that has polarity opposing the flow of armature
current. This voltage varies proportionally with the shaft angle velocity by the emf constant k
e
Figure 1: a brushed DC motor and drive
Figure 2: DC motor connected to a mechanical load
www.controlsystemslab.com Page 3
m e
k e u
= (3)
Another equation that serves as a link between the electrical and mechanical subsystems is the
relationship between motor torque and armature current
a t
i k = t (4)
where k
t
is called the torque constant. Substitute (4), (3) into (1), (2) respectively, we get
a t m m m
i k b J = + u u
(5)
m e a a a a a
k v i R i L u
= + (6)
This set of equations can be simplified further by observing that, the dynamics of electrical
subsystem is significantly faster than that of the mechanical counterpart. Hence, considering that
the first derivative term in (6) that represents the change of armature current in time is negligible
compared to the rest of the system, we can use engineering judgment to eliminate such term.
After doing so and rearranging (6), we have
a
m e a
a
R
k v
i
u
= (7)
Substitute this into (5)
( )
m e a
a
t
m m m
k v
R
k
b J u u u
= +
a
a
t
m
a
e t
m m
v
R
k
R
k k
b J =
|
|
.
|
\
|
+ + u u
(8)
Then apply Laplace transform
) ( ) ( ) (
2
s V
R
k
s s
R
k k
b s s J
a
a
t
m
a
e t
m m
=
|
|
.
|
\
|
+ + u u (9)
to achieve a transfer function of DC motor
|
|
.
|
\
|
+ +
=
a
e t
m
a
t
a
m
R
k k
b s J s
R
k
s V
s
) (
) (
) ( u
(10)
www.controlsystemslab.com Page 4
Example 2: Brushless servo motor
Brushless servo motors, like those in Figure 3, have more sophisticated dynamics. A
model may not be derived accurately from straightforward physic laws. In this case we could
rely partly on software tools. In this example, MATLAB/Simulink is used to help forming a
math model. The block diagram in Figure 4 represents a servo motor connected to a rotational
mechanics with flexible shaft. This diagram can be constructed in Simulink as in Figure 5. The
parameters for each block may be found from motor datasheet, or measurements.
Figure 3: Brushless servo motor
Figure 4: Block diagram of a servo motor with rotational load
www.controlsystemslab.com Page 5
Figure 5: A Simulink MDL file for servo motor in Figure 4
With some adjustment to the Simulink model in Figure 5; i.e., replacing the input and output
blocks with ports and removing nonlinear components, model data can be easily achieved using
MATLAB command like linmod( ). Alternatively, we show below, omitting details, a block
diagram reduction scheme to obtain a model.
Figure 6 shows the block diagram of servo motor with nonlinear blocks removed. By a divide
and conquer strategy, we locate the middle point v that separates the diagram to two
subsystems, namely T
vu
and T
yv
. Using a hint on block diagram reduction steps for each
subsystem as shown in Figure 7, we leave it as an exercise for readers to verify that
vu yv yu
n n
n x n x n r x
yv
e x m m a m a
m m a a
vu
T T T
s s s
k s k s k k
T
k k k k k s k k s
s k k k k
T
=
+ +
+ +
=
+ + +
=
) 2 (
2 ) (
) 1 (
2 2 2
2 2 2
2 1 2 1 2
2
2 1 2 1
e .e
e .e e
t
(11)
( )
( ) ) 2 ( ) 1 (
2 ) (
2 2
2 1 2 1 2
2
2 2 2
2 1 2 1
n n e x m m a m a
n x n x n r x m m a a
vu
s s k k k k k s k k s s
k s k s k k k k k k
T
e .e t
e .e e
+ + + + +
+ +
=
www.controlsystemslab.com Page 6
Figure 6: Linearized block diagram of servo motor
Figure 7: Steps for block diagram reduction
www.controlsystemslab.com Page 7
System identification
A general concept of system identification, or SysID for short, can be depicted as in
Figure 8. The real plant is treated like a black box. An input signal is applied to the plant and the
resulting output measured. This input and output dataset is then processed by some kind of
matching algorithm, in order to find a good estimate of math model for this plant. There is no
immediate choice for the best identification algorithm, since this area is still an active research
and there are varieties of them out there. One could use curve-fitting, least-square estimation, or
even a neuro-fuzzy approach. There are also online and offline versions.
Nevertheless, we can generally classify SysID into two groups, namely
1. Non-parametric identification
2. Parametric identification
Both will be discussed later in this article. Before that we have something to say about
appropriate input signals used in the identification process.
Choices of input
Even though the concept of SysID sounds simple enough, the success depends
significantly on proper selection of input signals. As an analogy, imagine a psychiatrist who
wants to study a new patient. She cant just walk in and chat with the subject irrelevantly.
Instead, she needs to prepare a set of questions that are rich enough in content, or perhaps
provocative, to obtain answers that contain insights or information that characterizes that patient.
Likewise, the input used in SysID must be persistently exciting, i.e., rich enough to excite all
dynamics of the plant.
So, what kind of inputs is the best candidate? We could see this more clearly in the frequency
domain. Consider a plant described by a transfer function P(s). The input and output
relationships can be written simply as
y(s) = P(s)u(s) (12)
Lets say we feed a sinusoid signal as input, what comes out is a complex number that represents
only a single data point in the Bode frequency response. An input with unit magnitude for all
frequency, on the other hand, should render the output spectrum to match the plant frequency
response exactly, as shown in Figure 8. In most cases, a good candidate for input must energize
the system at least in the frequency range of interest. Ideally, we prefer an input with flat
magnitude for the whole spectrum. Though it might not be possible to find such input in reality,
there are input choices good enough for SysID. Below we list some of those.
www.controlsystemslab.com Page 8
Figure 8: Input for system identification
- Impulse: An ideal impulse has infinite amplitude over zero duration. The
corresponding frequency response has unit magnitude for all frequency. That cannot
be achieved in reality, of course. A practical impulse signal has a very large peak
during a very small time interval. A mechanical example is when one hits an object
hard with a hammer. This signal is suitable for modeling a strong structure, such as a
bridge. Modeling a hard disk with an impulse is a job reserved for a lunatic.
- White noise: A so-called white noise or random signal is a signal with amplitude
varied randomly. In theory, this signal must have flat frequency response for the
whole spectrum. The bandwidth of white noise is limited in practice by certain
factors, such as loss in signal generation circuit and transmission line. White noise is
suitable for modeling electronics such as an amplifier.
- Chirp: A chirp signal is simply sinusoids with frequency varied in selected range.
This signal is used when only a frequency response within a range of interest is
needed, such as a band-pass or band-reject filter.
- Pseudo Random Binary Sequence (PRBS): a PRBS signal has its amplitude switched
between two values, say, + 1, but the switching sequence is random within a time
period. This signal will be depicted and discussed later in this article.
Non-parametric SysID
in some cases, such as when one wants a plant model for classical control design scheme,
a time-domain equation or transfer function of the physical system may not be necessary. It is
sufficient to get frequency response data from the real plant. Then some loopshaping design
scheme can craft a controller directly from such data. If the designer later decides a transfer
function is needed, curve-fitting techniques can be applied to the frequency response. Software
such as MATLAB has toolbox functions handy for such purpose.
A basic approach for non-parametric SysID that can be performed manually or automatically by
a special lab equipment is known as swept-sin method. The idea is very simple. Frequency
response in a Bode plot can be considered as infinite numbers of magnitude and phase data
www.controlsystemslab.com Page 9
points collected for a certain bandwidth. In an undergrad lab experiment, a student may be asked
to connect a sinusoid generator and an oscilloscope to a plant. Then he collects data manually by
adjusting frequency of the sinusoid input, and measure the magnitude and phase shift of the plant
output. From such data points selected properly within the bandwidth, a crude Bode plot can be
sketched on a graph paper. The accuracy depends on the number of data points (and the
students eyes and attention).
This tedious process is intended only for learning purpose. In a real application, there are
commercial lab equipments that have a built-in swept-sin function. An example is Siglab brand
from Spectral Dynamics Inc. Figure 9 shows a setup for active noise control (ANC) in PVC duct
modeling at DACSLAB, UMASS Amherst, where Siglab equipment (indicated by red arrow) is
used. This equipment allows a user to set ranges of frequency and number of data points in each
ranges, then performs the swept-sin process automatically. After the process finishes, the
frequency response data can be transferred to the PC for analysis or controller design. Figure 10
is a snapshot of an experiment result where the performance of closed-loop system is compared
to the open-loop. The frequency response shows clearly the sound attenuation by the ANC in the
desired low frequency range. Note that a simple analysis like this could be conducted without a
model in transfer function or state-space form.
Figure 9: SysID setup for active noise control
www.controlsystemslab.com Page 10
Figure 10: Performance assessment from frequency response data
Parametric SysID
Another class of system identification relies on certain estimation schemes to get good
values for system parameters, such as coefficients of a continuous or discrete-time transfer
function. A sophisticated modeling instrument like Siglab discussed earlier has functions for
parametric SysID as well. In this section we briefly discuss a method known as least-square (LS)
estimation, which can be used to obtain coefficients of a general discrete-time transfer function
of order n
n n
n n
n n
n n
a z a z a z
b z b z b z b
z G
+ + + +
+ + + +
=
1
1
1
1
2
2
1
1
...
...
) ( (13)
with the estimation vector containing the coefficients
T
n n
b b a a ] ... ... [
1 1
= (14)
The objective is to find u
LS
, the best estimate of u in a least-square sense. Let u[k] and y[k]
represent the k
th
input and output samples of the dataset from our measurement, respectively.
Suppose N
p
samples for each of u and y are collected. Form a matrix as follows
www.controlsystemslab.com Page 11
+ +
=
] 1 [ ... ] [ ] 1 [ ... ] [
: : : : : :
] 1 [ ... ] [ ] 1 [ ... ] [
] 0 [ ... ] 1 [ ] 0 [ ... ] 1 [
n N u N u n N y N y
u n u y n y
u n u y n y
p p p p
X (15)
Then u
LS
can be computed from
Y X X X
T T
LS
1
) (
= (16)
where Y = [y[n] y[N
p
]]
T
is a column vector containing N
p
n + 1 output samples. It is
obvious from (16) that u
LS
can be found only when X
T
X is nonsingular, which is true when the
applied input signal is persistently exciting.
Remark: the procedure introduced here is classified as offline LS estimation. There are also
online versions of LS schemes that recursively estimate the parameters in real-time.
PRBS sequence
We mentioned PRBS signal in a previous section. It is a good choice of input for least-
square estimation. A PRBS sequence has its amplitude switched between 2 values, typically + 1.
The switching sequence is random and unique within a specified maximum period, or sequence
length, then the sequence repeats itself. A PRBS sequence can be generated using a number of
unit delays connected in cascade, with selected states XORed and fed back to the first delay. For
a PRBS generator with N-state delay, the maximum sequence length is 2
N
-1. Figure 11 shows an
example of 13-state PRBS generator constructed in Simulink, which gives an output sequence in
Figure 12. In practice, we can simply write a C routine as in Listing 1 to generate the sequence.
Figure 11: A PRBS generator with 13 delay blocks
www.controlsystemslab.com Page 12
Figure 12: PRBS output sequence from generator in Figure 11
/* initialize PRBS generator coefficients */
b[0] = b[3] = b[6] = b[8] = b[9] = 0;
b[1] = b[2] = b[4] = b[5] = b[7] = b[10] = b[11] = b[12] = 1;
int GenPRBS(Void) // A PRBS generator function
{
int i,feedin;
feedin = (b[4]+b[12])%2; // perform exclusive or
feedin = (feedin + b[3])%2;
feedin = (feedin + b[1])%2;
for(i=12;i>0;i--) b[i] = b[i-1]; // shift right
b[0] = feedin;
if(b[12]==0) return -1;
else return 1;
}
Listing 1: A PRBS generator function written in C
Example 3: LS SysID for a brushed DC motor
In Example 1 we derived a math model for DC motor using physic-based method. To
simplify the model, we lump the constants in (10) to a general DC motor transfer function
) (
) (
t +
=
s s
k
s P (17)
www.controlsystemslab.com Page 13
consisting of an integrator 1/s and motor time constant t. We want to perform an LS SysID on
the real DC motor and compare with (17). Using the C function in Listing 1 to input the PRBS to
the motor and capture the resulting output, we obtain the data sequences as shown in Figure 13.
MATLAB file DCM_IDEN.M in listing 2 is then used to compute the best estimate for the
coefficients. After converting the resulting discrete-time transfer function using D2C( ) , we get
the continuous-time transfer function of the DC motor
) 9451339 2393 )( 7577 )( 2000 )( 132 (
) 2127068 1506 )( 30749609 2297 )( 2000 ( 0065 . 0
) (
2
2 2
+ + + + +
+ + + +
=
s s s s s s
s s s s s
s P (18)
Obviously, the transfer function obtained from SysID appears more complicated, but we can see
the dominant dynamics of DC motor from (17). The poles are located at 0, -132, -2000, -7577,
-1196 + 2831i and zeros at 2000, -753 + 1249i, -1148 + 5425i Figure 14 shows pole and zero
plot of (18) in the complex plane. Notice the presence of zeros in the right half plane. This may
result from certain factors such as time delay in the system.
Figure 13: input and output data captured from DC motor
www.controlsystemslab.com Page 14
Figure 14: poles and zeros of DC motor from SysID
%DCM_IDEN.M MATLAB file for LS SysID of DC motor
% Input and output data are captured in u and y vectors
Y = y(6:195,1);
X=[];
for i=1:190,
X=[X; -y(i+4) -y(i+3) -y(i+2) -y(i+1) -y(i) u(i+4) u(i+3) u(i+2) u(i+1) u(i)];
end
theta_ls = inv(X'*X)*X'*Y;
numd = [theta_ls(6) theta_ls(7) theta_ls(8) theta_ls(9) theta_ls(10)];
dend = [1 theta_ls(1) theta_ls(2) theta_ls(3) theta_ls(4) theta_ls(5)];
Pd = tf(numd,dend,0.001); % sampling time = 1 ms
P = D2C(Pd,tustin);
Listing 2: MATLAB file DCM_IDEN.M for LS SysID of DC motor
www.controlsystemslab.com Page 15
Summary
A good model is essential for control system analysis and design, especially when an
engineer wants to craft his/her custom controller from the model data. In this article we discuss
some fundamentals of system modeling, which is by no means comprehensive. Examples are
given to illustrate the concept or procedure for each modeling scheme. Our experience convinces
us that the model data from experiments is a preferred choice for a real application, though
comparing with a theoretical model often gives more insights to the system. We will elaborate
more on this issue in the sequel.
Reference
L. Ljung. System Identification: Theory for the User, 2
nd
ed., Prentice-Hall, 1999.
V.Toochinda. Fundamental Limitations of ANC in One-Dimensional Ducts using 2 Sensors and
1 Actuator, Ph.D. Dissertation, University of Massachusetts, 2002.