System Identification Toolbox™ Getting Started Guide
System Identification Toolbox™ Getting Started Guide
System Identification Toolbox™ Getting Started Guide
R2014a
Lennart Ljung
How to Contact MathWorks
www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
www.mathworks.com/contact_TS.html Technical Support
508-647-7000 (Phone)
508-647-7001 (Fax)
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
March 2007 First printing New for Version 7.0 (Release 2007a)
September 2007 Second printing Revised for Version 7.1 (Release 2007b)
March 2008 Third printing Revised for Version 7.2 (Release 2008a)
October 2008 Online only Revised for Version 7.2.1 (Release 2008b)
March 2009 Online only Revised for Version 7.3 (Release 2009a)
September 2009 Online only Revised for Version 7.3.1 (Release 2009b)
March 2010 Online only Revised for Version 7.4 (Release 2010a)
September 2010 Online only Revised for Version 7.4.1 (Release 2010b)
April 2011 Online only Revised for Version 7.4.2 (Release 2011a)
September 2011 Online only Revised for Version 7.4.3 (Release 2011b)
March 2012 Online only Revised for Version 8.0 (Release 2012a)
September 2012 Online only Revised for Version 8.1 (Release 2012b)
March 2013 Online only Revised for Version 8.2 (Release 2013a)
September 2013 Online only Revised for Version 8.3 (Release 2013b)
March 2014 Online only Revised for Version 9.0 (Release 2014a)
Contents
Product Overview
1
System Identification Toolbox Product Description . . 1-2
Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
What Is System Identification? . . . . . . . . . . . . . . . . . . . . . . 1-5
About Dynamic Systems and Models . . . . . . . . . . . . . . . . . . 1-5
System Identification Requires Measured Data . . . . . . . . . 1-9
Building Models from Data . . . . . . . . . . . . . . . . . . . . . . . . . 1-11
Black-Box Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13
Grey-Box Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-18
Evaluating Model Quality . . . . . . . . . . . . . . . . . . . . . . . . . . 1-19
Learn More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23
v
Linear Model Identification
3
Identify Linear Models Using System Identification
Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
Preparing Data for System Identification . . . . . . . . . . . . . . 3-3
Saving the Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19
Estimating Linear Models Using Quick Start . . . . . . . . . . . 3-21
Estimating Linear Models . . . . . . . . . . . . . . . . . . . . . . . . . . 3-28
Viewing Model Parameters . . . . . . . . . . . . . . . . . . . . . . . . . 3-48
Exporting the Model to the MATLAB Workspace . . . . . . . . 3-52
Exporting the Model to the LTI Viewer . . . . . . . . . . . . . . . . 3-54
vi Contents
Nonlinear Model Identification
4
Identify Nonlinear Black-Box Models Using System
Identification Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
What Are Nonlinear Black-Box Models? . . . . . . . . . . . . . . . 4-3
Preparing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7
Estimating Nonlinear ARX Models . . . . . . . . . . . . . . . . . . . 4-13
Estimating Hammerstein-Wiener Models . . . . . . . . . . . . . . 4-26
vii
viii Contents
1
Product Overview
Key Features
• Transfer function, process model, and state-space model identification
using time-domain and frequency-domain response data
• Autoregressive (ARX, ARMAX), Box-Jenkins, and Output-Error model
estimation using maximum likelihood, prediction-error minimization
(PEM), and subspace system identification techniques
• Online model parameter estimation
• Time-series modeling (AR, ARMA) and forecasting
• Identification of nonlinear ARX models and Hammerstein-Weiner models
with input-output nonlinearities such as saturation and dead zone
• Linear and nonlinear grey-box system identification for estimation of
user-defined models
1-2
System Identification Toolbox™ Product Description
1-3
1 Product Overview
Acknowledgments
System Identification Toolbox software is developed in association with the
following leading researchers in the system identification field:
1-4
Overview
Overview
In this section...
“What Is System Identification?” on page 1-5
“About Dynamic Systems and Models” on page 1-5
“System Identification Requires Measured Data” on page 1-9
“Building Models from Data” on page 1-11
“Black-Box Modeling” on page 1-13
“Grey-Box Modeling” on page 1-18
“Evaluating Model Quality” on page 1-19
“Learn More” on page 1-23
• Measure the input and output signals from your system in time or
frequency domain.
• Select a model structure.
• Apply an estimation method to estimate value for the adjustable
parameters in the candidate model structure.
• Evaluate the estimated model to see if the model is adequate for your
application needs.
1-5
1 Product Overview
F(t)
y(t)
m
C
1-6
Overview
d2 y dy
m +c + ky(t) = F (t)
2 dt
dt
where m is the mass, k the spring’s stiffness constant, and c the damping
coefficient. The solution to this differential equation lets you determine the
displacement of the mass, y(t), as a function of external force F(t) at any time t
for known values of constant m, c and k.
dy(t)
Consider the displacement, y(t), and velocity, v(t) = , as state variables:
dt
y(t)
x(t)
v(t)
You can express the previous equation of motion as a state-space model of
the system:
dx
Ax(t) BF (t)
dt
y(t) Cx(t)
0 1
A k c
m m
1
B 0
m
C 1 0
Y (s) 1
G(s) = =
2
F (s) (ms + cs + k)
1-7
1 Product Overview
Often, for simplicity, Ts is taken as one time unit, and the equation can be
written as:
where a1 and a2 are the model parameters. The model parameters are related
to the system constants m, c, and k, and the sampling interval Ts.
This difference equation shows the dynamic nature of the model. The
displacement value at the time instant t depends not only on the value of
force F at a previous time instant, but also on the displacement values at the
previous two time instants y(t–1) and y(t–2).
You can use this equation to compute the displacement at a specific time.
The displacement is represented as a weighted sum of the past input and
output values:
Alternatively, the output value at a given time t can be computed using the
measured values of output at previous two time instants and the input value
at a previous time instant. This computation is called prediction. For more
1-8
Overview
Obtaining a good model of your system depends on how well your measured
data reflects the behavior of the system. See “Data Quality Requirements”
on page 1-11.
Using this toolbox, you build models using time-domain input-output signals,
frequency response data, time series signals, and time-series spectra.
For example, if you measure the input force, F(t), and mass displacement, y(t),
of the spring-mass-damper system at a uniform sampling frequency of 10 Hz,
you obtain the following vectors of measured values:
1-9
1 Product Overview
If you want to build a discrete-time model from this data, the data vectors
umeas and ymeas and the sampling interval Ts provide sufficient information for
creating such a model.
If you want to build a continuous-time model, you should also know the
intersample behavior of the input signals during the experiment. For
example, the input may be piecewise constant (zero-order hold) or piecewise
linear (first-order hold) between samples.
Frequency domain data can also represent the frequency response of the
system, represented by the set of complex response values over a given
frequency range. The frequency response describes the outputs to sinusoidal
inputs. If the input is a sine wave with frequency ω, then the output is also
a sine wave of the same frequency, whose amplitude is A(ω) times the input
signal amplitude and a phase shift of Φ(ω) with respect to the input signal.
The frequency response is A(ω)e(iΦ(ω)).
In the case of the mass-spring-damper system, you can obtain the frequency
response data by using a sinusoidal input force and measuring the
corresponding amplitude gain and phase shift of the response, over a range
of input frequencies.
1-10
Overview
• Use inputs that excite the system dynamics adequately. For example, a
single step is seldom enough excitation.
• Measure data long enough to capture the important time constants.
• Set up data acquisition system to have good signal-to-noise ratio.
• Measure data at appropriate sampling intervals or frequency resolution.
You can analyze the data quality before building the model using techniques
available in the Signal Processing Toolbox™ software. For example, analyze
the input spectra to determine if the input signals have sufficient power over
the bandwidth of the system.
You can also analyze your data to determine peak frequencies, input
delays, important time constants, and indication of nonlinearities using
non-parametric analysis tools in this toolbox. You can use this information
for configuring model structures for building models from data. See the
following topics:
1-11
1 Product Overview
are transfer functions with adjustable poles and zeros, state space equations
with unknown system matrices, and nonlinear parameterized functions.
The system identification process requires that you choose a model structure
and apply the estimation methods to determine the numerical values of the
model parameters.
You can use one of the following approaches to choose the model structure:
• You want a model that is able to reproduce your measured data and is as
simple as possible. You can try various mathematical structures available
in the toolbox. This modeling approach is called black-box modeling.
• You want a specific structure for your model, which you may have derived
from first principles, but do not know numerical values of its parameters.
You can then represent the model structure as a set of equations or
state-space system in MATLAB and estimate the values of its parameters
from data. This approach is known as grey-box modeling.
ymodel(t) = Gu(t)
1-12
Overview
Accordingly, the error v(t) is called simulation error or prediction error. The
estimation algorithms adjust parameters in the model structure G such that
the norm of this error is as small as possible.
For more information about configuring the estimation algorithm, see the
topics for estimating specific model structures.
Black-Box Modeling
• “Selecting Black-Box Model Structure and Order” on page 1-13
• “When to Use Nonlinear Model Structures?” on page 1-15
• “Black-Box Estimation Example” on page 1-16
1-13
1 Product Overview
provides several linear and nonlinear black-box model structures, which have
traditionally been useful for representing dynamic systems. These model
structures vary in complexity depending on the flexibility you need to account
for the dynamics and noise in your system. You can choose one of these
structures and compute its parameters to fit the measured response data.
You can configure a model structure using the model order. The definition of
model order varies depending on the type of model you select. For example, if
you choose a transfer function representation, the model order is related to the
number of poles and zeros. For state-space representation, the model order
corresponds to the number of states. In some cases, such as for linear ARX and
state-space model structures, you can estimate the model order from the data.
If the simple model structures do not produce good models, you can select
more complex model structures by:
• Specifying a higher model order for the same linear model structure.
Higher model order increases the model flexibility for capturing complex
phenomena. However, unnecessarily high orders can make the model less
reliable.
• Explicitly modeling the noise:
1-14
Overview
y(t)=Gu(t)+He(t)
where H models the additive disturbance by treating the disturbance as
the output of a linear system driven by a white noise source e(t).
Using a model structure that explicitly models the additive disturbance can
help to improve the accuracy of the measured component G. Furthermore,
such a model structure is useful when your main interest is using the model
for predicting future response values.
• Using a different linear model structure.
See “Linear Model Structures” in the User’s Guide.
• Using a nonlinear model structure.
Nonlinear models have more flexibility in capturing complex phenomena
than linear models of similar orders. See “Available Nonlinear Models”
in User’s Guide.
Ultimately, you choose the simplest model structure that provides the best
fit to your measured data. For more information, see “Estimating Linear
Models Using Quick Start” on page 3-21.
Regardless of the structure you choose for estimation, you can simplify the
model for your application needs. For example, you can separate out the
measured dynamics (G) from the noise dynamics (H) to obtain a simpler model
that represents just the relationship between y and u. You can also linearize
a nonlinear model about an operating point.
You can assess the need to use a nonlinear model structure by plotting the
response of the system to an input. If you notice that the responses differ
depending on the input level or input sign, try using a nonlinear model. For
example, if the output response to an input step up is faster than the response
to a step down, you might need a nonlinear model.
1-15
1 Product Overview
G(s) =
( b0 + b1 s + b2 s2 + ...)
(1 + f1 s + f2 s2 + ...)
For the mass-spring damper system, this transfer function is:
1
G(s)
ms 2
cs k
1-16
Overview
bz−1
G ( z−1 ) =
(1 + f1 z−1 + f2 z−2 )
where the model orders correspond to the number of coefficients of the
numerator and the denominator (nb = 1 and nf = 2) and the input-output
delay equals the lowest order exponent of z–1 in the numerator (nk = 1).
In continuous-time, you can build a linear transfer function model using the
tfest command:
m = tfest(data, 2, 0)
Similarly, you can build a discrete-time model Output Error structure using
the following command:
m = oe(data, [1 2 1])
The model order is [nb nf nk] = [1 2 1]. Usually, you do not know the model
orders in advance. You should try several model order values until you find
the orders that produce an acceptable model.
m = ssest(data, 2)
1-17
1 Product Overview
For more information about building models, see “Steps for Using the System
Identification Tool GUI” and “Model Estimation Commands” in the User’s
Guide.
Grey-Box Modeling
In some situations, you can deduce the model structure from physical
principles. For example, the mathematical relationship between the input
force and the resulting mass displacement in the mass-spring-damper system
is well known. In state-space form, the model is given by:
dx
Ax(t) BF (t)
dt
y(t) Cx(t)
where x(t) = [y(t);v(t)] is the state vector. The coefficients A, B, and C are
functions of the model parameters:
A = [0 1; –k/m –c/m]
B = [0; 1/m]
C = [1 0]
Here, you fully know the model structure but do not know the values of its
parameters—m, c and k.
In the grey-box approach, you use the data to estimate the values of the
unknown parameters of your model structure. You specify the model structure
by a set of differential or difference equations in MATLAB and provide some
initial guess for the unknown parameters specified.
2 Configuring the model parameters with initial values and constraints (if
any).
1-18
Overview
The following table summarizes the ways you can specify a grey-box model
structure.
1-19
1 Product Overview
Ultimately, you must assess the quality of your model based on whether the
model adequately addresses the needs of your application. For information
about other available model analysis techniques, see “Model Analysis”.
If you do not get a satisfactory model, you can iteratively improve your results
by trying a different model structure, changing the estimation algorithm
settings, or performing additional data processing. For more information
about estimating each type of model structure, see the User’s Guide. If
these changes do not improve your results, you might need to revisit your
experimental design and data gathering procedures.
You can simulate these models with a particular input and compare their
responses against the measured values of the displacement for the same input
applied to the real system. The following figure compares the simulated and
measured responses for a step input.
1-20
Overview
The previous figure indicates that model2 is better than model1 because
model2 better fits the data (65% vs. 83%).
The % fit indicates the agreement between the model response and the
measured output: 100 means a perfect fit, and 0 indicates a poor fit (that is,
the model output has the same fit to the measured output as the mean of
the measured output).
For more information, see “Simulating and Predicting Model Output” in the
User’s Guide.
Analyzing Residuals
The System Identification Toolbox software lets you perform residual analysis
to assess the model quality. Residuals represent the portion of the output
1-21
1 Product Overview
data not explained by the estimated model. A good model has residuals
uncorrelated with past inputs.
1-22
Overview
Learn More
The System Identification Toolbox documentation provides you with the
necessary information to use this product. Additional resources are available
to help you learn more about specific aspects of system identification theory
and applications.
The following book describes methods for system identification and physical
modeling:
Ljung, L., and T. Glad. Modeling of Dynamic Systems. PTR Prentice Hall,
Upper Saddle River, NJ, 1994.
1-23
1 Product Overview
• Ljung, L. System Identification: Theory for the User. Second edition. PTR
Prentice Hall, Upper Saddle River, NJ, 1999.
• Söderström, T., and P. Stoica. System Identification. Prentice Hall
International, London, 1989.
For information about working with frequency-domain data, see the following
book:
For more information about systems and signals, see the following book:
Oppenheim, J., and Willsky, A.S. Signals and Systems. PTR Prentice Hall,
Upper Saddle River, NJ, 1985.
1-24
Overview
Dennis, J.E., Jr., and R.B. Schnabel. Numerical Methods for Unconstrained
Optimization and Nonlinear Equations. PTR Prentice Hall, Upper Saddle
River, NJ, 1983.
1-25
1 Product Overview
Related Products
The following table summarizes MathWorks® products that extend and
complement the System Identification Toolbox software. For current
information about these and other MathWorks products, point your Web
browser to:
www.mathworks.com
Product Description
“Control System Toolbox™” Provides extensive tools to analyze
plant models created in the System
Identification Toolbox software and
to tune control systems based on
these plant models. You can use
the identified models directly for
advanced linear analysis and control
design tasks — no conversion of the
format required.
“Model Predictive Control Toolbox” Uses the linear plant models
created in the System Identification
Toolbox software for predicting plant
behavior that is optimized by the
model-predictive controller.
“Neural Network Toolbox™” Provides flexible neural-network
structures for estimating nonlinear
models using the System
Identification Toolbox software.
“Optimization Toolbox™” When this toolbox is installed,
you have the option of using
the lsqnonlin optimization
algorithm for linear and nonlinear
identification.
1-26
Related Products
Product Description
“Robust Control Toolbox™” Provides tools to design
multiple-input and multiple-output
(MIMO) control systems based on
plant models created in the System
Identification Toolbox software.
Helps you assess robustness based
on confidence bounds for the
identified plant model.
“Signal Processing Toolbox” Provides additional options for:
• Filtering
(The System Identification
Toolbox software provides only
the fifth-order Butterworth filter.)
• Spectral analysis
1-27
1 Product Overview
1-28
2
• “When to Use the GUI vs. the Command Line” on page 2-2
• “System Identification Workflow” on page 2-3
• “Commands for Model Estimation” on page 2-6
2 Using This Product
You can work either in the GUI or at the command line to preprocess data,
and estimate, validate, and compare models.
New users should start by using the GUI to become familiar with the product.
To open the GUI, on the Apps tab of MATLAB desktop, in the Apps section,
click System Identification. Alternatively, type ident in the MATLAB
Command Window.
To work at the command line, type the commands directly in the MATLAB
Command Window. For more information about a command, type doc
command_name in the MATLAB Command Window.
2-2
System Identification Workflow
Because this toolbox lets you estimate different model structures quickly, you
should try as many different structures as possible to see which one produces
the best results.
2-3
2 Using This Product
• Frequency-response models
• Impulse-response models
• Low-order transfer functions (process models)
• Input-output polynomial models
• State-space models
• Transfer function models
• Nonlinear black-box models
• Ordinary difference or differential equations (grey-box models)
3 Validate models.
You might need to preprocess your data before doing further estimation.
For example, if there is too much high-frequency noise in your data, you
might need to filter or decimate (resample) the data before modeling.
4 Postprocess models:
2-4
System Identification Workflow
2-5
2 Using This Product
2-6
3
Introduction
• “Objectives” on page 3-2
• “Data Description” on page 3-3
Objectives
Estimate and validate linear models from single-input/single-output (SISO)
data to find the one that best describes the system dynamics.
After completing this tutorial, you will be able to accomplish the following
tasks using the System Identification Tool :
• Import data arrays from the MATLAB workspace into the GUI.
• Plot the data.
• Process data by removing offsets from the input and output signals.
• Estimate, validate, and compare linear models.
• Export models to the MATLAB workspace.
3-2
Identify Linear Models Using System Identification Tool
Data Description
This tutorial uses the data file dryer2.mat, which contains
single-input/single-output (SISO) time-domain data from Feedback Process
Trainer PT326. The input and output signals each contain 1000 data samples.
This system heats the air at the inlet using a mesh of resistor wire, similar to
a hair dryer. The input is the power supplied to the resistor wires, and the
output is the air temperature at the outlet.
load dryer2
This command loads the data into the MATLAB workspace as two column
vectors, u2 and y2, respectively. The variable u2 is the input data and y2 is
the output data.
3-3
3 Linear Model Identification
ident
You must have already loaded the sample data into MATLAB, as described in
“Loading Data into the MATLAB Workspace” on page 3-3, and opened the
System Identification Tool, as described in “Opening the System Identification
Tool ” on page 3-4.
3-4
Identify Linear Models Using System Identification Tool
1 In the System Identification Tool, select Import data > Time domain
data. This action opens the Import Data dialog box.
3-5
3 Linear Model Identification
The Import Data dialog box now resembles the following figure.
3 In the Data Information area, click More to expand the dialog box and
specify the following options:
3-6
Identify Linear Models Using System Identification Tool
Input Properties
• InterSample — Accept the default zoh (zero-order hold) to indicate
that the input signal was piecewise-constant between samples during
data acquisition. This setting specifies the behavior of the input signals
between samples when you transform the resulting models between
discrete-time and continuous-time representations.
• Period — Accept the default inf to specify a nonperiodic input.
Note For a periodic input, enter the whole number of periods of the
input signal in your experiment.
Channel Names
• Input — Enter power.
3-7
3 Linear Model Identification
experimental conditions. When you estimate models from this data, these
models inherit your notes.
The expanded Import Data dialog box now resembles the following figure.
3-8
Identify Linear Models Using System Identification Tool
4 Click Import to add the data to the System Identification Tool. The tool
displays an icon to represent the data.
The reason you subtract the mean values from each signal is because,
typically, you build linear models that describe the responses for deviations
from a physical equilibrium. With steady-state data, it is reasonable to
assume that the mean levels of the signals correspond to such an equilibrium.
Thus, you can seek models around zero without modeling the absolute
equilibrium levels in physical units.
3-9
3 Linear Model Identification
You must have already imported data into the System Identification Tool, as
described in “Importing Data Arrays into the System Identification Tool”
on page 3-4.
1 In the System Identification Tool, select the Time plot check box to open
the Time Plot. If the plot window is empty, click the data icon in the
System Identification Tool.
The top axes show the output data (temperature), and the bottom axes
show the input data (power). Both the input and the output data have
nonzero mean values.
3-10
Identify Linear Models Using System Identification Tool
2 Subtract the mean input value from the input data and the mean output
value from the output data. In the System Identification Tool, select
<--Preprocess > Remove means.
3-11
3 Linear Model Identification
This action adds a new data set to the System Identification Tool with
the default name datad (the suffix d means detrend), and updates the
Time Plot window to display both the original and the detrended data. The
detrended data has a zero mean value.
3-12
Identify Linear Models Using System Identification Tool
3 Specify the detrended data to be used for estimating models. Drag the data
set datad to the Working Data rectangle.
4 Split the data into two parts and specify the first part for model estimation,
and the second part for model validation, as described in the following steps.
a Select <--Preprocess > Select range to open the Select Range window.
3-13
3 Linear Model Identification
b In the Select Range window, create a data set containing the first 500
samples. In the Samples field, specify 1 500.
Tip You can also select data samples using the mouse by clicking and
dragging a rectangular region on the plot. If you select samples on the
input-channel axes, the corresponding region is also selected on the
output-channel axes.
3-14
Identify Linear Models Using System Identification Tool
d Click Insert to add this new data set to the System Identification Tool
to be used for model estimation.
e Repeat this process to create a second data set containing a subset of
the data to use for validation. In the Select Range window, specify the
last 500 samples in the Samples field. Type the name data_val in the
Data name field. Click Insert to add this new data set to the System
Identification Tool.
3-15
3 Linear Model Identification
3-16
Identify Linear Models Using System Identification Tool
5 In the System Identification Tool, drag and drop data_est to the Working
Data rectangle, and drag and drop data_val to the Validation Data
rectangle.
3-17
3 Linear Model Identification
6 To get information about a data set, right-click its icon. For example,
right-click data_est to open the Data/model Info dialog box.
3-18
Identify Linear Models Using System Identification Tool
You can also change certain values in the Data/model Info dialog box,
including:
• Changing the name of the data set in the Data name field.
• Changing the color of the data icon in the Color field. You specify colors
using RGB values (relative amounts of red, green, and blue). Each value
is between 0 and 1. For example, [1,0,0] indicates that only red is
present, and no green and blue are mixed into the overall color.
• Viewing or editing the commands executed on this data set in the Diary
And Notes area. This area contains the command-line equivalent to
the processing you performed using the System Identification Tool.
For example, as shown in the Data/model Info: estimate window, the
data_est data set is a result of importing the data, detrending the mean
values, and selecting the first 500 samples of the data.
% Import data
datad = detrend(data,0)
data_est = datad([1:500])
For more information about these and other toolbox commands, see the
corresponding reference pages.
The Data/model Info dialog box also displays the total number of samples, the
sampling interval, and the output and input channel names and units. This
information is not editable.
Tip As an alternative shortcut, you can select Preprocess > Quick start
from the System Identification Tool to perform all of the data processing
steps in this tutorial.
3-19
3 Linear Model Identification
later and use it as a starting point for model estimation and validation
without repeating these preparatory steps.
You must have already processed the data into the System Identification Tool,
as described in “Plotting and Processing Data” on page 3-9.
To delete specific data sets from a session and save the session:
Note Moving items to the Trash does not delete them. To permanently
delete items, select Options > Empty trash in the System Identification
Tool.
The following figure shows the System Identification Tool after moving
the items to Trash.
3-20
Identify Linear Models Using System Identification Tool
2 Drag and drop the data_est and data_val data sets to fill the empty
rectangles, as shown in the following figure.
3 Select File > Save session as to open the Save Session dialog box, and
browse to the folder where you want to save the session file.
Tip You can open a saved session when starting the System Identification
Tool by typing the following command at the MATLAB prompt:
ident('dryer2_processed_data')
For more information about managing sessions, see “Starting and Managing
GUI Sessions”.
3-21
3 Linear Model Identification
You must have already processed the data for estimation, as described in
“Plotting and Processing Data” on page 3-9.
3-22
Identify Linear Models Using System Identification Tool
• imp — Step response over a period of time using the impulse algorithm.
• spad — Frequency response over a range of frequencies using the spa
algorithm. The frequency response is the Fourier transform of the impulse
response of a linear system.
By default, the model is evaluated at 128 frequency values, ranging from
0 to the Nyquist frequency.
• arxqs — Fourth-order autoregressive (ARX) model using the arx algorithm.
This model is parametric and has the following structure:
y(t) represents the output at time t, u(t) represents the input at time t, na is
the number of poles, nb is the number of b parameters (equal to the number
of zeros plus 1), nk is the number of samples before the input affects output
of the system (called the delay or dead time of the model), and e(t) is the
white-noise disturbance. System Identification Toolbox software estimates
the parameters a1 an and b1 bn using the input and output data from
the estimation data set.
In arxqs, na=nb=4, and nk is estimated from the step response model imp.
3-23
3 Linear Model Identification
dx
Ax(t) Bu(t) Ke(t)
dt
y(t) Cx(t) Du(t) e(t)
y(t) represents the output at time t, u(t) represents the input at time t, x
is the state vector, and e(t) is the white-noise disturbance. The System
Identification Toolbox product estimates the state-space matrices A, B,
C, D, and K.
Note The Quick Start option does not create a transfer function model or a
process model which can also be good starting model types.
• Step-response plot
• Frequency-response plot
• Model-output plot
You must have already estimated models using Quick Start to generate
these plots, as described in “How to Estimate Linear Models Using Quick
Start” on page 3-22.
3-24
Identify Linear Models Using System Identification Tool
Tip If you closed the plot window, select the Transient resp check box to
reopen this window. If the plot is empty, click the model icons in the System
Identification Tool window to display the models on the plot.
Tip You can use the step-response plot to estimate the dead time of linear
systems. For example, the previous step-response plot shows a time delay of
about 0.25 s before the system responds to the input. This response delay,
or dead time, is approximately equal to about three samples because the
sampling interval is 0.08 s for this data set.
3-25
3 Linear Model Identification
Tip If you closed this plot window, select the Frequency resp check box to
reopen this window. If the plot is empty, click the model icons in the System
Identification Tool window to display the models on the plot.
Model-Output Plot. The Model Output window shows agreement among the
different model structures and the measured output in the validation data.
Tip If you closed the Model Output window, select the Model output check
box to reopen this window. If the plot is empty, click the model icons in the
System Identification Tool window to display the models on the plot.
3-26
Identify Linear Models Using System Identification Tool
Measured Output and Model Output for Models imp, arxqs, and n4s3
The model-output plot shows the model response to the input in the validation
data. The fit values for each model are summarized in the Best Fits area
of the Model Output window. The models in the Best Fits list are ordered
from best at the top to worst at the bottom. The fit between the two curves is
computed such that 100 means a perfect fit, and 0 indicates a poor fit (that
is, the model output has the same fit to the measured output as the mean of
the measured output).
In this example, the output of the models matches the validation data output,
which indicates that the models seem to capture the main system dynamics
and that linear modeling is sufficient.
3-27
3 Linear Model Identification
1 Identifying initial model orders and delays from your data using a simple,
polynomial model structure (ARX).
2 Exploring more complex model structures with orders and delays close to
the initial values you found.
3-28
Identify Linear Models Using System Identification Tool
y(t) represents the output at time t, u(t) represents the input at time t, na is the
number of poles, nb is the number of zeros plus 1, nk is the input delay—the
number of samples before the input affects the system output (called delay or
dead time of the model), and e(t) is the white-noise disturbance.
You specify the model orders na, nb, and nk to estimate ARX models. The
System Identification Toolbox product estimates the parameters a1 an
and b1 bn from the data.
2 From the Structure list, select ARX: [na nb nk]. By default, this is
already selected.
3-29
3 Linear Model Identification
3 Edit the Orders field to try all combinations of poles, zeros, and delays,
where each value is from 1 to 10:
4 Click Estimate to open the ARX Model Structure Selection window, which
displays the model performance for each combination of model parameters.
3-30
Identify Linear Models Using System Identification Tool
3-31
3 Linear Model Identification
Note When you use the same data set for estimation and validation, use
the MDL and AIC criteria to select model orders. These criteria compensate
for overfitting that results from using too many parameters. For more
information about these criteria, see the selstruc reference page.
5 In the ARX Model Structure Selection window, click the red bar
(corresponding to 15 on the horizontal axis), and click Insert. This
selection inserts na=6, nb=9, and nk=2 into the Polynomial Models dialog
box and performs the estimation.
This action adds the model arx692 to the System Identification Tool and
updates the plots to include the response of the model.
Note The default name of the parametric model contains the model type
and the number of poles, zeros, and delays. For example, arx692 is an ARX
model with na=6, nb=9, and a delay of two samples.
6 In the ARX Model Structure Selection window, click the third bar
corresponding to 4 parameters on the horizontal axis (the lowest order that
still gives a good fit), and click Insert.
• This selection inserts na=2, nb=2, and nk=3 (a delay of three samples)
into the Polynomial Models dialog box and performs the estimation.
• The model arx223 is added to the System Identification Tool and the
plots are updated to include its response and output.
3-32
Identify Linear Models Using System Identification Tool
The overall best fit for this system corresponds to a model with six poles, nine
zeros, and a delay of two samples. It also showed that a low-order model
with na = 2 (two poles), nb = 2 (one zero), and nk = 3 (input-output delay) also
provides a good fit. Thus, you should explore model orders close to these
values.
num(s)
Y (s) U (s) E(s)
den(s)
Y(s), U(s) and E(s) represent the Laplace transforms of the output, input
and error, respectively. num(s) and den(s) represent the numerator and
denominator polynomials that define the relationship between the input and
the output. The roots of the denominator polynomial are referred to as the
model poles. The roots of the numerator polynomial are referred to as the
model zeros.
You must specify the number of poles and zeros to estimate a transfer function
model. The System Identification Toolbox product estimates the numerator
and denominator polynomials, and input/output delays from the data.
The transfer function model structure is a good choice for quick estimation
because it requires that you specify only 2 parameters to get started: np is
the number of poles and nz is the number of zeros.
3-33
3 Linear Model Identification
Use the default Estimation Options. By default, the tool assigns the name
tf1 to the model. The dialog box should look like this.
3-34
Identify Linear Models Using System Identification Tool
4 Click Estimate to add a transfer function model called tf1 to the System
Identification Tool. You can view the output of the estimation of the
transfer function model in comparison with the estimations of other
models, in the Model output window.
3-35
3 Linear Model Identification
Tip If you closed the Model Output window, you can regenerate it by
selecting the Model output check box in the System Identification Tool.
If the new model does not appear on the plot, click the model icon in the
System Identification Tool to make the model active.
Learn More. To learn more about identifying transfer function models, see
“Transfer Function Models”.
3-36
Identify Linear Models Using System Identification Tool
of poles, zeros, and delays that provide a good starting point for systematically
exploring different models.
The overall best fit for this system corresponds to a model with six poles, nine
zeros, and a delay of two samples. It also showed that a low-order model with
na=2 (two poles), nb=2 (one zero), and nk=3 (input-output delay) also provides
a good fit. Thus, you should explore model orders close to these values.
dx
Ax(t) Bu(t) Ke(t)
dt
y(t) Cx(t) Du(t) e(t)
y(t) represents the output at time t, u(t) represents the input at time t, x(t) is
the state vector at time t, and e(t) is the white-noise disturbance.
You must specify a single integer as the model order (dimension of the state
vector) to estimate a state-space model. The System Identification Toolbox
product estimates the state-space matrices A, B, C, D, and K from the data.
The state-space model structure is a good choice for quick estimation because
it requires that you specify only the number of states (which equals the
number of poles). You can optionally also specify the delays and feedthrough
behavior.
1 In the System Identification Tool , select Estimate > State Space Models
to open the State Space Models dialog box.
3-37
3 Linear Model Identification
2 In the Specify value field, specify the model order. Type 6 to create a
sixth-order state-space model.
This choice is based on the fact that the best-fit ARX model has six poles.
The State Space Models dialog box looks like the following figure.
3-38
Identify Linear Models Using System Identification Tool
You can view the output of the estimation of the state-space model in
comparison with the estimations of other models, in the Model output
window.
3-39
3 Linear Model Identification
Tip If you closed the Model Output window, you can regenerate it by
selecting the Model output check box in the System Identification Tool.
If the new model does not appear on the plot, click the model icon in the
System Identification Tool to make the model active.
3-40
Identify Linear Models Using System Identification Tool
The overall best fit for this system corresponds to a model with six poles, nine
zeros, and a delay of two samples. It also showed that a low-order model with
na=2 (two poles), nb=2 (one zero), and nk=3 also provides a good fit. Thus, you
should explore model orders close to these values.
y(t) represents the output at time t, u(t) represents the input at time t, na is
the number of poles for the dynamic model, nb is the number of zeros plus 1, nc
is the number of poles for the disturbance model, nk is the number of samples
before the input affects output of the system (called the delay or dead time of
the model), and e(t) is the white-noise disturbance.
Note The ARMAX model is more flexible than the ARX model because
the ARMAX structure contains an extra polynomial to model the additive
disturbance.
3-41
3 Linear Model Identification
You must specify the model orders to estimate ARMAX models. The System
Identification Toolbox product estimates the model parameters a1 an ,
b1 bn , and c1 cn from the data.
3-42
Identify Linear Models Using System Identification Tool
3 In the Orders field, set the orders na, nb, nc, and nk to the following values:
[2 2 2 2]
The tool assigns the name to the model amx2222, by default, visible in the
Name field.
4 Click Estimate to add the ARMAX model to the System Identification Tool.
3-43
3 Linear Model Identification
Tip If you closed the Model Output window, you can regenerate it by
selecting the Model output check box in the System Identification Tool.
If the new model does not appear on the plot, click the model icon in the
System Identification Tool to make the model active.
3-44
Identify Linear Models Using System Identification Tool
Examining the Model Output. Examine the model output plot to see how
well the model output matches the measured output in the validation data
set. A good model is the simplest model that best describes the dynamics and
successfully simulates or predicts the output for different inputs. Models are
listed by name in the Best Fits area of the Model Output plot. Note that one
of the simpler models, amx3322, produced a similar fit as the highest-order
model you created, arx692.
3-45
3 Linear Model Identification
Tip If you closed the Model Output window, you can regenerate it by selecting
the Model output check box in the System Identification Tool. If the new
model does not appear on the plot, click the model icon in the System
Identification Tool to make the model active.
To validate your models using a different data set, you can drag and drop this
data set into the Validation Data rectangle in the System Identification
Tool. If you transform validation data into the frequency domain, the Model
Output plot updates to show the model comparison in the frequency domain.
3-46
Identify Linear Models Using System Identification Tool
To get a closer look at how well these models fit the data, magnify a portion of
the plot by clicking and dragging a rectangle around the region of interest, as
shown in the following figure.
3-47
3 Linear Model Identification
Releasing the mouse magnifies this region and shows that the output of all
models matches the validation data well.
To view the parameter values of the model amx3322, right-click the model icon
in the System Identification Tool. The Data/model Info dialog box opens.
3-48
Identify Linear Models Using System Identification Tool
3-49
3 Linear Model Identification
The noneditable area of the Data/model Info dialog box lists the parameter
values correspond to the following difference equation for your system:
Note The coefficient of u(t-2) is not significantly different from zero. This
lack of difference explains why delay values of both 2 and 3 give good results.
A( z) 1 a1 z1 ana z na
B( z) b1 z nk bnb z nb nk1
C( z) 1 c1 z1 cnc z nc
y(t) represents the output at time t, u(t) represents the input at time t, na is
the number of poles for the dynamic model, nb is the number of zeros plus 1, nc
is the number of poles for the disturbance model, nk is the number of samples
before the input affects output of the system (called the delay or dead time of
the model), and e(t) is the white-noise disturbance.
3-50
Identify Linear Models Using System Identification Tool
amx3322 =
Discrete-time ARMAX model: A(z)y(t) = B(z)u(t) + C(z)e(t)
Name: amx3322
Sample time: 0.08 seconds
Parameterization:
Polynomial orders: na=3 nb=3 nc=2 nk=2
Number of free coefficients: 8
Use "polydata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Termination condition: Near (local) minimum, (norm(g) < tol).
Number of iterations: 5, Number of function evaluations: 11
3-51
3 Linear Model Identification
3-52
Identify Linear Models Using System Identification Tool
3-53
3 Linear Model Identification
After the model is in the MATLAB workspace, you can perform other
operations on the model. For example, if you have the Control System Toolbox
product installed, you might transform the model to a state-space object using:
ss_model=ss(amx3322)
The LTI Viewer is a graphical user interface for viewing and manipulating
the response plots of linear models. It displays the following plots:
To plot a model in the LTI Viewer, drag and drop the model icon to the To
LTI Viewer rectangle in the System Identification Tool.
For more information about working with plots in the LTI Viewer, see “LTI
Viewer Overview”.
3-54
Identify Linear Models Using the Command Line
Introduction
• “Objectives” on page 3-55
• “Data Description” on page 3-56
Objectives
Estimate and validate linear models from multiple-input/single-output
(MISO) data to find the one that best describes the system dynamics.
After completing this tutorial, you will be able to accomplish the following
tasks using the command line:
3-55
3 Linear Model Identification
Data Description
This tutorial uses the data file co2data.mat, which contains two experiments
of two-input and single-output (MISO) time-domain data from a steady-state
that the operator perturbed from equilibrium values.
In the first experiment, the operator introduced a pulse wave to both inputs.
In the second experiment, the operator introduced a pulse wave to the first
input and a step signal to the second input.
Preparing Data
• “Loading Data into the MATLAB Workspace” on page 3-57
• “Plotting the Input/Output Data” on page 3-57
• “Removing Equilibrium Values from the Data” on page 3-60
• “Using Objects to Represent Data for System Identification” on page 3-60
• “Creating iddata Objects” on page 3-61
• “Plotting the Data in a Data Object” on page 3-64
3-56
Identify Linear Models Using the Command Line
load co2data;
This command loads the following five variables into the MATLAB Workspace:
• Input_exp1 and Output_exp1 are the input and output data from the first
experiment, respectively.
• Input_exp2 and Output_exp2 are the input and output data from the
second experiment, respectively.
• Time is the time vector from 0 to 1000 minutes, increasing in equal
increments of 0.5 min.
For both experiments, the input data consists of two columns of values. The
first column of values is the rate of chemical consumption (in kilograms per
minute), and the second column of values is the current (in amperes). The
output data is a single column of the rate of carbon-dioxide production (in
milligrams per minute).
plot(Time,Input_exp1,Time,Output_exp1)
legend('Input 1','Input 2','Output 1')
figure
plot(Time,Input_exp2,Time,Output_exp2)
legend('Input 1','Input 2','Output 1')
3-57
3 Linear Model Identification
3-58
Identify Linear Models Using the Command Line
The first plot shows the first experiment, where the operator applies a pulse
wave to each input to perturb it from its steady-state equilibrium.
The second plot shows the second experiment, where the operator applies a
pulse wave to the first input and a step signal to the second input.
3-59
3 Linear Model Identification
The reason you subtract the mean values from each signal is because,
typically, you build linear models that describe the responses for deviations
from a physical equilibrium. With steady-state data, it is reasonable to
assume that the mean levels of the signals correspond to such an equilibrium.
Thus, you can seek models around zero without modeling the absolute
equilibrium levels in physical units.
Zoom in on the plots to see that the earliest moment when the operator
applies a disturbance to the inputs occurs after 25 minutes of steady-state
conditions (or after the first 50 samples). Thus, the average value of the first
50 samples represents the equilibrium conditions.
Use the following commands to remove the equilibrium values from inputs
and outputs in both experiments:
Input_exp1 = Input_exp1-...
ones(size(Input_exp1,1),1)*mean(Input_exp1(1:50,:));
Output_exp1 = Output_exp1-...
mean(Output_exp1(1:50,:));
Input_exp2 = Input_exp2-...
ones(size(Input_exp2,1),1)*mean(Input_exp2(1:50,:));
Output_exp2 = Output_exp2-...
mean(Output_exp2(1:50,:));
In this portion of the tutorial, you create two iddata objects, one for each
of the two experiments. You use the data from Experiment 1 for model
estimation, and the data from Experiment 2 for model validation. You work
3-60
Identify Linear Models Using the Command Line
with two independent data sets because you use one data set for model
estimation and the other for model validation.
Note When two independent data sets are not available, you can split one
data set into two parts, assuming that each part contains enough information
to adequately represent the system dynamics.
The iddata constructor requires three arguments for time-domain data and
has the following syntax:
data_obj = iddata(output,input,sampling_interval);
3-61
3 Linear Model Identification
To view the properties of an iddata object, use the get command. For
example, type this command to get the properties of the estimation data:
get(ze)
get(ze)
ans =
Domain: 'Time'
Name: ''
OutputData: [2001x1 double]
y: 'Same as OutputData'
OutputName: {'y1'}
OutputUnit: {''}
InputData: [2001x2 double]
u: 'Same as InputData'
InputName: {2x1 cell}
InputUnit: {2x1 cell}
Period: [2x1 double]
InterSample: {2x1 cell}
Ts: 0.5000
Tstart: []
SamplingInstants: [2001x0 double]
TimeUnit: 'seconds'
ExperimentName: 'Exp1'
Notes: {}
UserData: []
To learn more about the properties of this data object, see the iddata
reference page.
3-62
Identify Linear Models Using the Command Line
To modify data properties, you can use dot notation or the set command. For
example, to assign channel names and units that label plot axes, type the
following syntax in the MATLAB Command Window:
3-63
3 Linear Model Identification
You can verify that the InputName property of ze is changed, or "index" into
this property:
ze.inputname;
Tip Property names, such as InputUnit, are not case sensitive. You can also
abbreviate property names that start with Input or Output by substituting u
for Input and y for Output in the property name. For example, OutputUnit is
equivalent to yunit.
plot(ze)
3-64
Identify Linear Models Using the Command Line
The bottom axes show inputs ConsumptionRate and Current, and the top
axes show the output ProductionRate .
3-65
3 Linear Model Identification
Zoom in on the plots to see that the experiment process amplifies the first
input ( ConsumptionRate ) by a factor of 2, and amplifies the second input
(Current ) by a factor of 10.
Ze1 = ze(1:1000);
3-66
Identify Linear Models Using the Command Line
Zv1 = zv(1:1000);
For more information about indexing into iddata objects, see the
corresponding reference page.
In this portion of the tutorial, you estimate these models using the data set
ze. You must have already created ze, as described in “Creating iddata
Objects” on page 3-61.
The response plots from these models show the following characteristics of
the system:
• The response from the first input to the output might be a second-order
function.
• The response from the second input to the output might be a first-order
or an overdamped function.
3-67
3 Linear Model Identification
• spafdr lets you specify a variable frequency resolution for estimating the
frequency response.
Ge=spa(ze);
bode(Ge)
3-68
Identify Linear Models Using the Command Line
The amplitude peaks at the frequency of about 0.7 rad/s, which suggests
a possible resonant behavior (complex poles) for the first input-to-output
combination - ConsumptionRate to Production .
In both plots, the phase rolls off rapidly, which suggests a time delay for both
input/output combinations.
% model estimation
Mimp = impulseest(Ze1,60);
% step response
step(Mimp)
3-69
3 Linear Model Identification
The step response from the second input to the output shows no overshoot,
which indicates either a first-order response or a higher-order response with
real poles (overdamped response).
3-70
Identify Linear Models Using the Command Line
If you do not know the input/output delays for your system from the
experiment, you can use the System Identification Toolbox software to
estimate the delay.
3-71
3 Linear Model Identification
y(t) represents the output at time t, u(t) represents the input at time t, na is
the number of poles, nb is the number of b parameters (equal to the number
of zeros plus 1), nk is the number of samples before the input affects output
of the system (called the delay or dead time of the model), and e(t) is the
white-noise disturbance.
delayest assumes that na=nb=2 and that the noise e is white or insignificant,
and estimates nk.
delayest(ze)
ans =
5 10
This result includes two numbers because there are two inputs: the estimated
delay for the first input is 5 data samples, and the estimated delay for the
second input is 10 data samples. Because the sampling interval for the
experiments is 0.5 min, this corresponds to a 2.5 -min delay before the first
input affects the output, and a 5.0 -min delay before the second input affects
the output.
• Plot the time plot of the input and output data and read the time difference
between the first change in the input and the first change in the output.
This method is practical only for single-input/single-output system; in the
3-72
Identify Linear Models Using the Command Line
To compute parametric black-box models, you must provide the model order
as an input. If you do not know the order of your system, you can estimate it.
After completing the steps in this section, you get the following results:
• For the first input/output combination: na=2, nb=2, and the delay nk=5.
• For the second input/output combination: na=1, nb=1, and the delay nk=10.
3-73
3 Linear Model Identification
3-74
Identify Linear Models Using the Command Line
3-75
3 Linear Model Identification
Note When you use the same data set for estimation and validation, use
the MDL and AIC criteria to select model orders. These criteria compensate
for overfitting that results from using too many parameters. For more
information about these criteria, see the selstruc reference page.
It makes sense to try the following order combinations for the first
input/output combination:
• na=2:5
• nb=1:5
• n k= 5
NN1 = struc(2:5,1:5,5);
3-76
Identify Linear Models Using the Command Line
2 Use selstruc to compute the loss functions for the ARX models with the
orders in NN1.
selstruc(arxstruc(ze(:,:,1),zv(:,:,1),NN1))
3-77
3 Linear Model Identification
Note The Rissanen MDL and Akaike AIC criteria produces equivalent
results and are both indicated by a blue rectangle on the plot.
The red rectangle represents the best overall fit, which occurs for na=2,
nb=3, and nk=5. The height difference between the red and blue rectangles
is insignificant. Therefore, you can choose the parameter combination that
corresponds to the lowest model order and the simplest model.
3-78
Identify Linear Models Using the Command Line
3 Click the blue rectangle, and then click Select to choose that combination
of orders:
n a= 2
n b= 2
n k= 5
• na=1:3
• nb=1:3
• nk=10
NN2 = struc(1:3,1:3,10);
3-79
3 Linear Model Identification
2 Use selstruc to compute the loss functions for the ARX models with the
orders in NN2.
selstruc(arxstruc(ze(:,:,2),zv(:,:,2),NN2))
Note The Akaike AIC and the overall best fit criteria produces equivalent
results. Both are indicated by the same red rectangle on the plot.
3-80
Identify Linear Models Using the Command Line
3 Click the yellow rectangle on the far left, and then click Select to choose
the lowest order: na=1, nb=1, and nk=10.
You can estimate a transfer function of these orders using the tfest
command. For the estimation, you can also choose to view a progress
report by setting the Display option to on in the option set created by the
tfestOptions command.
Collect the model orders and delays into variables to pass to tfest.
np = [2 1];
3-81
3 Linear Model Identification
mtf
mtf =
Parameterization:
Number of poles: [2 1] Number of zeros: [1 0]
Number of free coefficients: 6
Use "tfdata", "getpvec", "getcov" for parameters and their uncertainties
Status:
Estimated using TFEST on time domain data "Ze1".
Fit to estimation data: 85.89% (simulation focus)
FPE: 6.424, MSE: 6.265
The model’s display shows more than 85% fit to estimation data.
3-82
Identify Linear Models Using the Command Line
compare(Zv1, mtf)
Residual Analysis
Use the resid command to evaluate the characteristics of the residuals.
3-83
3 Linear Model Identification
resid(Zv1, mtf)
3-84
Identify Linear Models Using the Command Line
You must have already prepared your data, as described in “Preparing Data”
on page 3-56.
You can use the following results of estimated model orders to specify the
orders of the model:
Use the idproc command to create two model structures, one for each
input/output combination:
3-85
3 Linear Model Identification
idproc accepts a cell array that contains two strings that specify the model
structure for each input/output combination:
The example also uses the TimeUnit parameter to specify the unit of time
used.
midproc0
midproc0 =
Process model with 2 inputs: y = G11(s)u1 + G12(s)u2
From input 1 to output 1:
1+Tz*s
G11(s) = Kp * ---------------------- * exp(-Td*s)
1+2*Zeta*Tw*s+(Tw*s)^2
Kp = NaN
Tw = NaN
Zeta = NaN
Td = NaN
Tz = NaN
Kp = NaN
Tp1 = NaN
Td = NaN
3-86
Identify Linear Models Using the Command Line
Parameterization:
'P2DUZ' 'P1D'
Number of free coefficients: 8
Use "getpvec", "getcov" for parameters and their uncertainties.
Status:
Created by direct construction or transformation. Not estimated.
The parameter values are set to NaN because they are not yet estimated.
midproc0.Structure(1,1).Td.Value=2.5;
midproc0.Structure(1,2).Td.Value=5;
midproc0.Structure(1,1).Td.Maximum=3;
midproc0.Structure(1,2).Td.Maximum=7;
Note When setting the delay constraints, you must specify the delays in
terms of actual time units (minutes, in this case) and not the number of
samples.
For this portion of the tutorial, you must have already defined the model
structure, as described in “Specifying the Structure of the Process Model” on
3-87
3 Linear Model Identification
page 3-85. Use midproc0 as the model structure and Ze1 as the estimation
data:
midproc =
Process model with 2 inputs: y = G11(s)u1 + G12(s)u2
From input "ConsumptionRate" to output "Production":
1+Tz*s
G11(s) = Kp * ---------------------- * exp(-Td*s)
1+2*Zeta*Tw*s+(Tw*s)^2
Parameterization:
'P2DUZ' 'P1D'
Number of free coefficients: 8
Use "getpvec", "getcov" for parameters and their uncertainties.
Status:
Termination condition: Maximum number of iterations reached.
Number of iterations: 20, Number of function evaluations: 276
3-88
Identify Linear Models Using the Command Line
compare(Zv1,midproc)
3-89
3 Linear Model Identification
The plot shows that the model output reasonably agrees with the measured
output: there is an agreement of 60% between the model and the validation
data.
resid(Zv1,midproc)
3-90
Identify Linear Models Using the Command Line
Because the sample system has two inputs, there are two cross-correlation
plots of the residuals with each input, as shown in the following figure.
3-91
3 Linear Model Identification
After MATLAB displays the first plot, press Enter to view the
cross-correlation with the second input, as shown in the following figure.
In the preceding figure, the autocorrelation plot shows values outside the
confidence region and indicates that the residuals are correlated.
Opt = procestOptions;
Opt.SearchMethod = 'lm';
3-92
Identify Linear Models Using the Command Line
Opt = procestOptions;
Opt.DisturbanceModel = 'ARMA1';
midproc2 = procest(Ze1, midproc0, Opt);
compare(Zv1,midproc2)
3-93
3 Linear Model Identification
The plot shows that the model output maintains reasonable agreement with
the validation-data output.
figure
resid(Zv1,midproc2)
Press Enter to view the cross-correlation of the residuals with the second
input.
3-94
Identify Linear Models Using the Command Line
The next plot shows that adding a noise model produces uncorrelated
residuals: the top set of axes show that the autocorrelation values are inside
the confidence bounds. This indicates a more accurate model.
3-95
3 Linear Model Identification
You must have already prepared your data, as described in “Preparing Data”
on page 3-56.
You can use the following previous results of estimated model orders to specify
the orders of the polynomial model:
y(t) represents the output at time t, u(t) represents the input at time t, na is
the number of poles, nb is the number of zeros plus 1, nk is the number of
samples before the input affects output of the system (called the delay or dead
time of the model), and e(t) is the white-noise disturbance.
3-96
Identify Linear Models Using the Command Line
The ARX model structure does not distinguish between the poles for
individual input/output paths: dividing the ARX equation by A, which
contains the poles, shows that A appears in the denominator for both inputs.
Therefore, you can set na to the sum of the poles for each input/output pair,
which is equal to 3 in this case.
Estimating ARX Models Using arx. Use arx to compute the polynomial
coefficients using the fast, noniterative method arx:
marx =
Discrete-time ARX model: A(z)y(t) = B(z)u(t) + e(t)
Parameterization:
Polynomial orders: na=3 nb=[2 1] nk=[5 10]
Number of free coefficients: 6
Use "polydata", "getpvec", "getcov" for parameters and their uncertainti
Status:
Estimated using ARX on time domain data "Ze1".
Fit to estimation data: 90.7% (prediction focus)
FPE: 2.75, MSE: 2.722
More information in model's "Report" property.
3-97
3 Linear Model Identification
MATLAB estimates the polynomials A , B1 , and B2. The uncertainty for each
of the model parameters is computed to 1 standard deviation and appears in
parentheses next to each parameter value.
Alternatively, you can use the following shorthand syntax and specify model
orders as a single vector:
get(marx)
3-98
Identify Linear Models Using the Command Line
You can access the information stored by these properties using dot notation.
For example, you can compute the discrete poles of the model by finding the
roots of the A polynomial.
marx_poles=roots(marx.a)
marx_poles =
0.7953
0.2883
-0.0570
The model marx describes system dynamics using three discrete poles.
Tip You can also use pole to compute the poles of a model directly.
For more information about accessing model data, see “Data Extraction”.
3-99
3 Linear Model Identification
dx
Ax(t) Bu(t) Ke(t)
dt
y(t) Cx(t) Du(t) e(t)
y(t) represents the output at time t, u(t) represents the input at time t, x(t) is
the state vector at time t, and e(t) is the white-noise disturbance.
You must specify a single integer as the model order (dimension of the state
vector) to estimate a state-space model. By default, the delay equals 1.
The state-space model structure is a good choice for quick estimation because
it contains only two parameters: n is the number of poles (the size of the A
matrix) and nk is the delay.
3-100
Identify Linear Models Using the Command Line
This command uses the fast, noniterative (subspace) method and opens the
following plot. You use this plot to decide which states provide a significant
relative contribution to the input/output behavior, and which states provide
the smallest contribution.
The vertical axis is a relative measure of how much each state contributes to
the input/output behavior of the model (log of singular values of the covariance
matrix). The horizontal axis corresponds to the model order n. This plot
recommends n=4, indicated by a red rectangle.
To select this model order, select 4 from the Model Order drop-down list
and click Apply.
3-101
3 Linear Model Identification
mCanonical =
Discrete-time identified state-space model:
x(t+Ts) = A x(t) + B u(t) + K e(t)
y(t) = C x(t) + D u(t) + e(t)
A =
x1 x2 x3
x1 0 1 0
x2 0 0 1
x3 0.0738 +/- 0.05922 -0.6083 +/- 0.1624 1.445 +/- 0.1284
B =
ConsumptionR Current
x1 1.844 +/- 0.1756 0.5631 +/- 0.1225
x2 1.064 +/- 0.1679 2.309 +/- 0.1226
x3 0.2769 +/- 0.0966 1.878 +/- 0.1061
C =
x1 x2 x3
Production 1 0 0
D =
ConsumptionR Current
Production 0 0
K =
Production
x1 0.8676 +/- 0.03183
x2 0.6864 +/- 0.04166
x3 0.5113 +/- 0.04379
Parameterization:
CANONICAL form with indices: 3.
Feedthrough: none
Disturbance component: estimate
Number of free coefficients: 12
3-102
Identify Linear Models Using the Command Line
Status:
Estimated using N4SID on time domain data "Ze1".
Fit to estimation data: 91.37% (prediction focus)
FPE: 2.456, MSE: 2.341
More information in model's "Report" property.
nu
Bi (q) C(q)
y(t) = ∑ ui ( t − nki ) + e(t)
F
i=1 i
( q) D(q)
To estimate a BJ model, you need to specify the parameters nb, nf, nc, nd,
and nk.
Whereas the ARX model structure does not distinguish between the poles
for individual input/output paths, the BJ model provides more flexibility in
3-103
3 Linear Model Identification
modeling the poles and zeros of the disturbance separately from the poles
and zeros of the system dynamics.
Estimating a BJ Model Using pem. You can use pem to estimate the BJ
model. pem is an iterative method and has the following general syntax:
pem(data,'na',na,'nb',nb,'nc',nc,'nd',nd,'nf',nf,'nk',nk)
3-104
Identify Linear Models Using the Command Line
na = 0;
nb = [ 2 1 ];
nc = 1;
nd = 1;
nf = [ 2 1 ];
nk = [ 5 10];
mbj = polyest(Ze1,[na nb nc nd nf nk]);
This command specifies nf=2 , nb=2 , nk=5 for the first input, and nf=nb=1
and nk=10 for the second input.
present(mbj)
mbj =
Discrete-time BJ model: y(t) = [B(z)/F(z)]u(t) + [C(z)/D(z)]e(t)
B1(z) = 1.823 (+/- 0.1792) z^-5 - 1.315 (+/- 0.2368) z^-6
Parameterization:
Polynomial orders: nb=[2 1] nc=1 nd=1 nf=[2 1]
nk=[5 10]
Number of free coefficients: 8
Use "polydata", "getpvec", "getcov" for parameters and their uncertainti
Status:
Termination condition: Near (local) minimum, (norm(g) < tol).
Number of iterations: 6, Number of function evaluations: 13
3-105
Estimated using POLYEST on time domain data "Ze1".
Fit to estimation data: 90.75% (prediction focus)
FPE: 2.757, MSE: 2.692
3 Linear Model Identification
Tip Alternatively, you can use the following shorthand syntax that specifies
the orders as a single vector:
compare(Zv1,marx,mn4sid,mbj)
3-106
Identify Linear Models Using the Command Line
compare plots the measured output in the validation data set against the
simulated output from the models. The input data from the validation data
set serves as input to the models.
To perform residual analysis on the ARX model, type the following command:
resid(Zv1,marx)
Because the sample system has two inputs, there are two plots showing the
cross-correlation of the residuals with each input. Press Enter to view the
cross-correlation with the second input.
3-107
3 Linear Model Identification
resid(Zv1,mn4sid)
resid(Zv1,mbj)
All three models simulate the output equally well and have uncorrelated
residuals. Therefore, choose the ARX model because it is the simplest of the
three input-output polynomial models and adequately captures the process
dynamics.
For example, the following commands use the iddata and idinput commands
to construct an input data set, and use sim to simulate the model output:
3-108
Identify Linear Models Using the Command Line
Next, simulate the model using the initial states estimated from the data.
% Simulation input
Usim = Zv1(:,[],:);
Opt = simOptions('InitialCondition',X0est);
ysim_2 = sim(midproc2_ss, Usim, Opt);
figure
plot([ysim_2.y, Zv1.y])
legend({'model output','measured'})
xlabel('time'), ylabel('Output')
3-109
3 Linear Model Identification
3-110
Identify Linear Models Using the Command Line
For example, use predict to predict the model response five steps ahead:
predict(midproc2,Ze1,5)
3-111
3 Linear Model Identification
Compare the predicted output values with the measured output values. The
third argument of compare specifies a five-step-ahead prediction. When you
do not specify a third argument, compare assumes an infinite prediction
horizon and simulates the model output instead.
compare(Ze1,midproc2,5)
3-112
Identify Linear Models Using the Command Line
Use pe to compute the prediction error Err between the predicted output of
midproc2 and the measured output. Then, plot the error spectrum using the
spectrum command.
[Err] = pe(midproc2,Zv1);
spectrum(spa(Err,[],logspace(-2,2,200)))
3-113
3 Linear Model Identification
Introduction
• “Objectives” on page 3-114
• “Data Description” on page 3-115
Objectives
Estimate and validate simple, continuous-time transfer functions from
single-input/single-output (SISO) data to find the one that best describes
the system dynamics.
After completing this tutorial, you will be able to accomplish the following
tasks using the System Identification Tool :
• Import data objects from the MATLAB workspace into the GUI.
• Plot and process the data.
• Estimate and validate low-order, continuous-time models from the data.
• Export models to the MATLAB workspace.
3-114
Identify Low-Order Transfer Functions (Process Models) Using System Identification Tool
Data Description
This tutorial uses the data file proc_data.mat, which contains 200 samples
of simulated single-input/single-output (SISO) time-domain data. The input
is a random binary signal that oscillates between -1 and 1. White noise
(corresponding to a load disturbance) is added to the input with a standard
deviation of 0.2, which results in a signal-to-noise ratio of about 20 dB. This
data is simulated using a second-order system with underdamped modes
(complex poles) and a peak response at 1 rad/s:
1
G(s) = e−2 s
2
1 + 0 .2 s + s
You can specify different process model structures by varying the number of
poles, adding an integrator, or including a time delay or a zero. The highest
process model order you can specify in this toolbox is three, and the poles can
be real or complex (underdamped modes).
3-115
3 Linear Model Identification
y = Gu
K
G(s) = e− sTd
1 + sTp1
load proc_data
This command loads the data into the MATLAB workspace as the data
object z. For more information about iddata objects, see the corresponding
reference page.
3-116
Identify Low-Order Transfer Functions (Process Models) Using System Identification Tool
ident
You must have already loaded the sample data into MATLAB, as described in
“Loading Data into the MATLAB Workspace” on page 3-116, and opened the
GUI, as described in “Opening the System Identification Tool ” on page 3-117.
3-117
3 Linear Model Identification
1 In the System Identification Tool , select Import data > Data object.
The Import Data dialog box now resembles the following figure.
3-118
Identify Low-Order Transfer Functions (Process Models) Using System Identification Tool
3-119
3 Linear Model Identification
3 Click Import to add the data to the System Identification Tool. The tool
adds an icon to represent the data.
The reason you subtract the mean values from each signal is because,
typically, you build linear models that describe the responses for deviations
from a physical equilibrium. With steady-state data, it is reasonable to
assume that the mean levels of the signals correspond to such an equilibrium.
Thus, you can seek models around zero without modeling the absolute
equilibrium levels in physical units.
You must have already imported data into the System Identification Tool, as
described in “Importing Data Objects into the System Identification Tool” on
page 3-117.
3-120
Identify Low-Order Transfer Functions (Process Models) Using System Identification Tool
1 In the System Identification Tool, select the Time plot check box to open
the Time Plot window.
The bottom axes show the input data—a random binary sequence, and
the top axes show the output data.
The next two steps demonstrate how to modify the axis limits in the plot.
2 To modify the vertical-axis limits for the input data, select Options > Set
axes limits in the Time Plot figure window.
3-121
3 Linear Model Identification
3 In the Limits for Time Plot dialog box, set the new vertical axis limit of the
input data channel u1 to [-1.5 1.5]. Click Apply and Close.
Note The other two fields in the Limits for Time Plot dialog box, Time
and y1, let you set the axis limits for the time axis and the output channel
axis, respectively. You can also specify each axis to be logarithmic or linear
by selecting the corresponding option.
3-122
Identify Low-Order Transfer Functions (Process Models) Using System Identification Tool
3-123
3 Linear Model Identification
K
G(s) = e−Td s
( 1 + 2ξTw s + Tw2 s2 )
You must have already processed the data for estimation, as described in
“Plotting and Processing Data” on page 3-120.
3-124
Identify Low-Order Transfer Functions (Process Models) Using System Identification Tool
2 In the Model Transfer Function area of the Process Models dialog box,
specify the following options:
• Under Poles, select 2 and Underdamped.
This selection updates the Model Transfer Function to a second-order
model structure that can contain complex poles.
• Make sure that the Zero and Integrator check boxes are cleared to
exclude a zero and an integrator (self-regulating ) from the model.
3 The Parameter area of the Process Models dialog box now shows four
active parameters: K, Tw, Zeta, and Td. In the Initial Guess area, keep
the default Auto-selected option to calculate the initial parameter values
during the estimation. The Initial Guess column in the Parameter table
displays Auto.
4 Keep the default Bounds values, which specify the minimum and
maximum values of each parameter.
3-125
3 Linear Model Identification
Tip If you know the range of possible values for a parameter, you can type
these values into the corresponding Bounds fields to help the estimation
algorithm.
• Initial condition — Auto means that the algorithm analyzes the data
and chooses the optimum method for handling the initial state of the
system. If you get poor results, you might try setting a specific method
for handling initial states, rather than choosing it automatically.
• Covariance — Estimate means that the algorithm computes parameter
uncertainties that display as model confidence regions on plots.
The tool assigns a name to the model, shown in the Name field (located at
the bottom of the dialog box). By default, the name is the acronym P2DU,
which indicates two poles (P2), a delay (D), and underdamped modes (U).
3-126
Identify Low-Order Transfer Functions (Process Models) Using System Identification Tool
6 Click Estimate to add the model P2DU to the System Identification Tool.
3-127
3 Linear Model Identification
If you know the approximate value of a parameter, you can help the estimation
algorithm by entering an initial value in the Initial Guess column. In this
case, keep the Known check box cleared to allow the estimation to fine-tune
this initial guess.
For example, to fix the time-delay value Td at 2s, you can type this value into
Value field of the Parameter table in the Process Models dialog box and select
the corresponding Known check box.
Known checkboxes.
3-128
Identify Low-Order Transfer Functions (Process Models) Using System Identification Tool
• Comparison of the model output and the measured output on a time plot
• Autocorrelation of the output residuals, and cross-correlation of the input
and the output residuals
Examining Model Output. You can use the model-output plot to check how
well the model output matches the measured output in the validation data
set. A good model is the simplest model that best describes the dynamics and
successfully simulates or predicts the output for different inputs.
To generate the model-output plot, select the Model output check box in the
System Identification Tool. If the plot is empty, click the model icon in the
System Identification Tool window to display the model on the plot.
The System Identification Toolbox product uses input validation data as input
to the model, and plots the simulated output on top of the output validation
3-129
3 Linear Model Identification
data. The preceding plot shows that the model output agrees well with the
validation-data output.
The Best Fits area of the Model Output plot shows the agreement (in percent)
between the model output and the validation-data output.
Recall that the data was simulated using the following second-order system
with underdamped modes (complex poles), as described in “Data Description”
on page 3-115, and has a peak response at 1 rad/s:
1
G(s) = e−2 s
1 + 0.2s + s2
Because the data includes noise at the input during the simulation, the
estimated model cannot exactly reproduce the model used to simulate the
data.
To generate a Residual Analysis plot, select the Model resids check box in
the System Identification Tool.
3-130
Identify Low-Order Transfer Functions (Process Models) Using System Identification Tool
The top axes show the autocorrelation of residuals for the output (whiteness
test). The horizontal scale is the number of lags, which is the time difference
(in samples) between the signals at which the correlation is estimated. Any
fluctuations within the confidence interval are considered to be insignificant.
A good model should have a residual autocorrelation function within the
confidence interval, indicating that the residuals are uncorrelated. However,
in this example, the residuals appear to be correlated, which is natural
because the noise model is used to make the residuals white.
The bottom axes show the cross-correlation of the residuals with the
input. A good model should have residuals uncorrelated with past inputs
(independence test). Evidence of correlation indicates that the model does not
describe how a portion of the output relates to the corresponding input. For
example, when there is a peak outside the confidence interval for lag k, this
means that the contribution to the output y(t) that originates from the input
u(t-k) is not properly described by the model. In this example, there is no
correlation between the residuals and the inputs.
3-131
3 Linear Model Identification
Thus, residual analysis indicates that this model is good, but that there might
be a need for a noise model.
1 If the Process Models dialog box is not open, select Estimate > Process
Models in the System Identification Tool. This action opens the Process
Models dialog box.
3-132
Identify Low-Order Transfer Functions (Process Models) Using System Identification Tool
C
H= e
D
3-133
3 Linear Model Identification
3 Click Estimate.
4 In the Process Models dialog box, set the Disturbance Model to Order 2
to estimate a second-order noise model.
5 Edit the Name field to P2DUe2 to generate a model with a unique name
in the System Identification Tool.
6 Click Estimate.
The following Model Output plot shows the simulated model output, by
default. The simulated response of the models is approximately the same for
models with and without noise. Thus, including the noise model does not
affect the simulated output.
3-134
Identify Low-Order Transfer Functions (Process Models) Using System Identification Tool
To view the predicted model output, select Options > 5 step ahead
predicted output in the Model Output plot window.
The following Model Output plot shows that the predicted model output of
P2DUe2 (with a second-order noise model) is better than the predicted output
of the other two models (without noise and with a first-order noise model,
respectively).
3-135
3 Linear Model Identification
3-136
Identify Low-Order Transfer Functions (Process Models) Using System Identification Tool
P2DUe2 falls well within the confidence bounds on the Residual Analysis plot.
To view residuals for P2DUe2 only, remove models P2DU and P2DUe1 from the
Residual Analysis plot by clicking the corresponding icons in the System
Identification Tool.
3-137
3 Linear Model Identification
The whiteness test for P2DUe2 shows that the residuals are uncorrelated, and
the independence test shows no correlation between the residuals and the
inputs. These tests indicate that P2DUe2 is a good model.
3-138
Identify Low-Order Transfer Functions (Process Models) Using System Identification Tool
3-139
3 Linear Model Identification
The noneditable area of the dialog box lists the model coefficients that
correspond to the following model structure:
K
G(s) = e−Td s
( 1 + 2ξTw s + Tw2 s2 )
The coefficients agree with the model used to simulate the data:
1
G(s) = e−2 s
2
1 + 0 .2 s + s
C
H= e
D
3-140
Identify Low-Order Transfer Functions (Process Models) Using System Identification Tool
The models you create in the System Identification Tool are not automatically
available in the MATLAB workspace. To make a model available to other
toolboxes, Simulink, and the System Identification Toolbox commands, you
must export your model from the System Identification Tool to the MATLAB
workspace.
To export the P2DUe2 model, drag the model icon to the To Workspace
rectangle in the System Identification Tool,. The model now appears in the
MATLAB Workspace browser.
3-141
3 Linear Model Identification
• Load the data set, as described in “Loading Data into the MATLAB
Workspace” on page 3-116.
• Estimate the second-order process model, as described in “Estimating a
Second-Order Process Model with Complex Poles” on page 3-132.
• Export the model to the MATLAB workspace, as described in “Exporting
the Model to the MATLAB Workspace” on page 3-141.
3-142
Identify Low-Order Transfer Functions (Process Models) Using System Identification Tool
Learn More. For more information about representing data signals for
system identification, see “Representing Data in MATLAB Workspace”.
2 Select File > New > Model to open a new model window.
4 Drag the following System Identification Toolbox blocks to the new model
window:
• IDDATA Sink block
• IDDATA Source block
• IDMODEL model block
5 In the Simulink Library Browser, select the Simulink > Sinks library,
and drag the Scope block to the new model window.
3-143
3 Linear Model Identification
Next, you configure these blocks to get data from the MATLAB workspace
and set the simulation time interval and duration.
2 In the Configuration Parameters dialog box, type 200 in the Stop time
field. Click OK.
3-144
Identify Low-Order Transfer Functions (Process Models) Using System Identification Tool
3 Double-click the Iddata Source block to open the Source Block Parameters:
Iddata Source dialog box. Then, type the following variable name in the
IDDATA object field:
z_input
This variable is the data object in the MATLAB workspace that contains
the input data.
Tip As a shortcut, you can drag and drop the variable name from the
MATLAB Workspace browser to the IDDATA object field.
Click OK.
P2DUe2
3-145
3 Linear Model Identification
b Clear the Add noise check box to exclude noise from the simulation.
Click OK.
When Add noise is selected, Simulink derives the noise amplitude from
the NoiseVariance property of the model and adds noise to the model
accordingly. The simulation propagates this noise according to the noise
model H that was estimated with the system dynamics:
C
H= e
D
3-146
Identify Low-Order Transfer Functions (Process Models) Using System Identification Tool
Click OK.
5 Double-click the Iddata Sink block to open the Sink Block Parameters:
Iddata Sink dialog box. Type the following variable name in the IDDATA
Name field:
z_sim_out
6 Type 1 in the Sample Time (sec.) field to set the sampling time of the
output data to match the sampling time of the input data.
Click OK.
3-147
3 Linear Model Identification
The resulting change to the Simulink model is shown in the following figure.
2 Double-click the Scope block to display the time plot of the model output.
3-148
Identify Low-Order Transfer Functions (Process Models) Using System Identification Tool
This variable stores the simulated output of the model, and it is now
available for further processing and exploration.
3-149
3 Linear Model Identification
3-150
4
Nonlinear Model
Identification
4 Nonlinear Model Identification
Introduction
• “Objectives” on page 4-2
• “Data Description” on page 4-2
Objectives
Estimate and validate nonlinear models from single-input/single-output
(SISO) data to find the one that best represents your system dynamics.
After completing this tutorial, you will be able to accomplish the following
tasks using the System Identification Tool GUI:
• Import data objects from the MATLAB workspace into the GUI.
• Estimate and validate nonlinear models from the data.
• Plot and analyze the behavior of the nonlinearities.
Data Description
This tutorial uses the data file twotankdata.mat, which contains SISO
time-domain data for a two-tank system, shown in the following figure.
4-2
Identify Nonlinear Black-Box Models Using System Identification Tool
Tank 1
Tank 2
Two-Tank System
In the two-tank system, water pours through a pipe into Tank 1, drains into
Tank 2, and leaves the system through a small hole at the bottom of Tank
2. The measured input u(t) to the system is the voltage applied to the pump
that feeds the water into Tank 1 (in volts). The measured output y(t) is the
height of the water in the lower tank (in meters).
Based on Bernoulli’s law, which states that water flowing through a small
hole at the bottom of a tank depends nonlinearly on the level of the water in
the tank, you expect the relationship between the input and the output data
to be nonlinear.
4-3
4 Nonlinear Model Identification
Nonlinearity Estimator
u Nonlinear
Regressors Function y
u(t),u(t-1),y(t-1), ...
Linear
Function
1 Computes regressors from the current and past input values and past
output data.
In the simplest case, regressors are delayed inputs and outputs, such as
u(t-1) and y(t-3)—called standard regressors. You can also specify custom
4-4
Identify Nonlinear Black-Box Models Using System Identification Tool
By default, all regressors are inputs to both the linear and the nonlinear
function blocks of the nonlinearity estimator. You can choose a subset of
regressors as inputs to the nonlinear function block.
2 The nonlinearity estimator block maps the regressors to the model output
using a combination of nonlinear and linear functions. You can select from
available nonlinearity estimators, such as tree-partition networks, wavelet
networks, and multi-layer neural networks. You can also exclude either
the linear or the nonlinear function block from the nonlinearity estimator.
The nonlinearity estimator block can include linear and nonlinear blocks in
parallel. For example:
F ( x) = LT ( x − r) + d + g ( Q( x − r) )
4-5
4 Nonlinear Model Identification
where:
• w(t) = f(u(t)) is a nonlinear function transforming input data u(t). w(t) has
the same dimension as u(t).
• x(t) = (B/F)w(t) is a linear transfer function. x(t) has the same dimension
as y(t).
where B and F are similar to polynomials in the linear Output-Error model,
as described in “What Are Polynomial Models?”.
For ny outputs and nu inputs, the linear block is a transfer function matrix
containing entries:
B j,i (q)
F j,i (q)
w(t) and x(t) are internal variables that define the input and output of the
linear block, respectively.
Because f acts on the input port of the linear block, this function is called
the input nonlinearity. Similarly, because h acts on the output port of the
linear block, this function is called the output nonlinearity. If system contains
several inputs and outputs, you must define the functions f and h for each
input and output signal.
You do not have to include both the input and the output nonlinearity in the
model structure. When a model contains only the input nonlinearity f, it is
called a Hammerstein model. Similarly, when the model contains only the
output nonlinearity h), it is called a Wiener model.
The nonlinearities f and h are scalar functions, one nonlinear function for
each input and output channel.
4-6
Identify Nonlinear Black-Box Models Using System Identification Tool
2 Computes the output of the linear block using w(t) and initial conditions:
x(t) = (B/F)w(t).
You can configure the linear block by specifying the numerator B and
denominator F orders.
3 Compute the model output by transforming the output of the linear block
x(t) using the nonlinear function h: y(t) = h(x(t)).
Resulting models are idnlhw objects that store all model data, including
model parameters and nonlinearity estimator. See the idnlhw reference page
for more information.
Preparing Data
• “Loading Data into the MATLAB Workspace” on page 4-7
• “Creating iddata Objects” on page 4-8
• “Starting the System Identification Tool” on page 4-10
• “Importing Data Objects into the System Identification Tool” on page 4-11
4-7
4 Nonlinear Model Identification
load twotankdata
This command loads the following two variables into the MATLAB Workspace
browser:
• u is the input data, which is the voltage applied to the pump that feeds the
water into Tank 1 (in volts).
• y is the output data, which is the water height in Tank 2 (in meters).
You must have already loaded the sample data into the MATLAB workspace,
as described in “Loading Data into the MATLAB Workspace” on page 4-7.
Use the following commands to create two iddata data objects, ze and zv,
where ze contains data for model estimation and zv contains data for model
validation. Ts is the sampling interval.
To view the properties of the iddata object, use the get command. For
example, type this command to get the properties of the estimation data:
get(ze)
4-8
Identify Nonlinear Black-Box Models Using System Identification Tool
Domain: 'Time'
Name: ''
OutputData: [1000x1 double]
y: 'Same as OutputData'
OutputName: {'y1'}
OutputUnit: {''}
InputData: [1000x1 double]
u: 'Same as InputData'
InputName: {'u1'}
InputUnit: {''}
Period: Inf
InterSample: 'zoh'
Ts: 0.2000
Tstart: 0.2000
SamplingInstants: [1000x0 double]
TimeUnit: 'seconds'
ExperimentName: 'Exp1'
Notes: {}
UserData: []
4-9
4 Nonlinear Model Identification
To modify data properties, use dot notation or the set command. For example,
to assign channel names and units that label plot axes, type the following
syntax in the MATLAB Command Window:
ze.inputname
Tip Property names, such as InputName, are not case sensitive. You can also
abbreviate property names that start with Input or Output by substituting u
for Input and y for Output in the property name. For example, OutputUnit is
equivalent to yunit.
ident
4-10
Identify Nonlinear Black-Box Models Using System Identification Tool
You must have already created the data objects, as described in “Creating
iddata Objects” on page 4-8, and opened the GUI, as described in “Starting
the System Identification Tool” on page 4-10.
1 In the System Identification Tool, select Import data > Data object.
4-11
4 Nonlinear Model Identification
2 Enter ze in the Object field to import the estimation data. Press Enter.
This action enters the object information into the Import Data fields.
3 Click Import to add the icon named ze to the System Identification Tool
GUI.
4 In the Import Data dialog box, type zv in the Object field to import the
validation data. Press Enter.
5 Click Import to add the icon named zv to the System Identification Tool
GUI.
4-12
Identify Nonlinear Black-Box Models Using System Identification Tool
7 In the System Identification Tool GUI, drag the validation data zv icon to
the Validation Data rectangle. The estimation data ze icon is already
designated in the Working Data rectangle.
4-13
4 Nonlinear Model Identification
You must have already prepared the data, as described in “Preparing Data”
on page 4-7. For more information about nonlinear ARX models, see “What Is
a Nonlinear ARX Model?” on page 4-4
4-14
Identify Nonlinear Black-Box Models Using System Identification Tool
The Configure tab is already open and the default Model type is
Nonlinear ARX.
4-15
4 Nonlinear Model Identification
In the Regressors tab, the Input Channels and Output Channels have
Delay set to 1 and No. of Terms set to 2. The model output y(t) is related
to the input u(t) via the following nonlinear autoregressive equation:
2 Click Estimate.
This action adds the model nlarx1 to the System Identification Tool, as
shown in the following figure.
4-16
Identify Nonlinear Black-Box Models Using System Identification Tool
Note Fit (%) is computed using the estimation data set, and not the
validation data set. However, the model output plot in the next step
compares the fit to the validation data set.
3 In the System Identification Tool, select the Model output check box.
This action simulates the model using the input validation data as input to
the model and plots the simulated output on top of the output validation
data.
4-17
4 Nonlinear Model Identification
The Best Fits area of the Model Output plot shows that the agreement
between the model output and the validation-data output.
4-18
Identify Nonlinear Black-Box Models Using System Identification Tool
1 In the System Identification Tool, select the Nonlinear ARX check box to
view the nonlinearity cross-sections.
By default, the plot shows the relationship between the output regressors
Height(t-1) and Height(t-2). This plot shows a regular plane in the
following figure. Thus, the relationship between the regressors and the
output is approximately a linear plane.
4-19
4 Nonlinear Model Identification
3 To rotate the nonlinearity surface, select Style > Rotate 3D and drag
the plot to a new orientation.
4-20
Identify Nonlinear Black-Box Models Using System Identification Tool
You must have already estimated the nonlinear ARX model with default
settings, as described in “Estimating a Nonlinear ARX Model with Default
Settings” on page 4-14.
1 In the Nonlinear Models dialog box, click the Configure tab, and click
the Regressors tab.
2 For the Voltage input channel, double-click the corresponding Delay cell,
enter 3, and press Enter.
4-21
4 Nonlinear Model Identification
3 Click Estimate.
This action adds the model nlarx2 to the System Identification Tool
GUI and updates the Model Output window to include this model. The
Nonlinear Models dialog box displays the new estimation information in
the Estimate tab.
4 In the Nonlinear Models dialog box, click the Configure tab, and select
the Model Properties tab.
5 In the Number of units in nonlinear block area, select Enter, and type
6. This number controls the flexibility of the nonlinearity.
4-22
Identify Nonlinear Black-Box Models Using System Identification Tool
6 Click Estimate.
This action adds the model nlarx3 to the System Identification Tool GUI.
It also updates the Model Output window, as shown in the following figure.
4-23
4 Nonlinear Model Identification
1 In the Nonlinear Models dialog box, click the Configure tab, and select
the Regressors tab.
2 Click the Edit Regressors button to open the Model Regressors dialog box.
• Height(t-2)
• Voltage(t-3)
Click OK.
4 Click Estimate.
4-24
Identify Nonlinear Black-Box Models Using System Identification Tool
This action adds the model nlarx4 to the System Identification Tool. It also
updates the Model Output window.
1 In the Nonlinear Models dialog box, select the Configure tab. Click
Initialize. This action opens the Initial Model Specification dialog box.
4-25
4 Nonlinear Model Identification
6 Click Estimate.
This action adds the model nlarx5 to the System Identification Tool. It also
updates the Model Output plot, as shown in the following figure.
To view information about the best model, including the model order,
nonlinearity, and list of regressors, right-click the model icon in the System
Identification Tool.
4-26
Identify Nonlinear Black-Box Models Using System Identification Tool
You must have already prepared the data, as described in “Preparing Data”
on page 4-7. For more information about nonlinear ARX models, see “What Is
a Hammerstein-Wiener Model?” on page 4-5
4-27
4 Nonlinear Model Identification
4-28
Identify Nonlinear Black-Box Models Using System Identification Tool
3 Select the Linear Block tab to view the model orders and input delay.
By default, the model orders and delay of the linear output-error (OE)
model are nb=2, nf=3, and nk=1.
4 Click Estimate.
This action adds the model nlhw1 to the System Identification Tool.
4-29
4 Nonlinear Model Identification
5 In the System Identification Tool, select the Model output check box.
This action simulates the model using the input validation data as input to
the model and plots the simulated output on top of the output validation
data.
The Best Fits area of the Model Output window shows the agreement
between the model output and the validation-data output.
4-30
Identify Nonlinear Black-Box Models Using System Identification Tool
The plot displays the input nonlinearity, as shown in the following figure.
4-31
4 Nonlinear Model Identification
4-32
Identify Nonlinear Black-Box Models Using System Identification Tool
The plot updates to display the step response of the linear transfer function.
4-33
4 Nonlinear Model Identification
4 In the Choose plot type list, select Bode. This action displays a Bode
plot of the linear transfer function.
4-34
Identify Nonlinear Black-Box Models Using System Identification Tool
1 In the Nonlinear Models dialog box, click the Configure tab, and select
the Linear Block tab.
3 Click Estimate.
This action adds the model nlhw2 to the System Identification Tool GUI
and the Model Output window is updated to include this model, as shown
in the following figure.
The Best Fits area of the Model Output window shows the quality of the
nlhw2 fit.
4-35
4 Nonlinear Model Identification
2 In the I/O Nonlinearity tab, for the Voltage input, click the Nonlinearity
cell, and select Sigmoid Network from the list. Click the corresponding No.
of Units cell and set the value to 20.
3 Click Estimate.
This action adds the model nlhw3 to the System Identification Tool GUI. It
also updates the Model Output window, as shown in the following figure.
4-36
Identify Nonlinear Black-Box Models Using System Identification Tool
4-37
4 Nonlinear Model Identification
7 Click Estimate.
This action adds the model nlhw4 to the System Identification Tool GUI. It
also updates the Model Output window, as shown in the following figure.
In this example, the best model fit was produced in “Changing the
Nonlinearity Estimator in a Hammerstein-Wiener Model” on page 4-35.
4-38