Mathworks Matlab7 - Toolbox - System Identification Toolbox User's Guide
Mathworks Matlab7 - Toolbox - System Identification Toolbox User's Guide
User’s Guide
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
April 1988 First printing
July 1991 Second printing
May 1995 Third printing
November 2000 Fourth printing Revised for Version 5.0 (Release 12)
April 2001 Fifth printing
July 2002 Online only Revised for Version 5.0.2 (Release 13)
June 2004 Sixth printing Revised for Version 6.0.1 (Release 14)
March 2005 Online only Revised for Version 6.1.1 (Release 14SP2)
September 2005 Seventh printing Revised for Version 6.1.2 (Release 14SP3)
March 2006 Online only Revised for Version 6.1.3 (Release 2006a)
September 2006 Online only Revised for Version 6.2 (Release 2006b)
March 2007 Online only Revised for Version 7.0 (Release 2007a)
September 2007 Online only Revised for Version 7.1 (Release 2007b)
March 2008 Online only 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)
About the Developers
vii
Data Import and Processing
2
Types of Data You Can Model . . . . . . . . . . . . . . . . . . . . . . . 2-2
viii Contents
Naming, Adding, and Removing Data Channels . . . . . . . . . 2-64
Concatenating iddata Objects . . . . . . . . . . . . . . . . . . . . . . . 2-66
ix
Resampling Data at the Command Line . . . . . . . . . . . . . . . 2-103
Resampling Data Without Aliasing Effects . . . . . . . . . . . . . 2-105
See Also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-108
x Contents
Spectrum Normalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8
xi
Data Supported by State-Space Models . . . . . . . . . . . . . . . . 3-77
Supported State-Space Parameterizations . . . . . . . . . . . . . 3-78
Preliminary Step – Estimating State-Space Model
Orders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-79
How to Estimate State-Space Models in the GUI . . . . . . . . 3-84
How to Estimate State-Space Models at the Command
Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-87
How to Estimate Free-Parameterization State-Space
Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-91
How to Estimate State-Space Models with Canonical
Parameterization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-92
How to Estimate State-Space Models with Structured
Parameterization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-94
How to Estimate the State-Space Equivalent of ARMAX
and OE Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-100
Options for Frequency-Weighing Focus . . . . . . . . . . . . . . . . 3-101
Options for Initial States . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-102
Algorithms for Estimating State-Space Models . . . . . . . . . 3-103
xii Contents
Subreferencing Model Objects . . . . . . . . . . . . . . . . . . . . . . 3-120
What Is Subreferencing? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-120
Limitation on Supported Models . . . . . . . . . . . . . . . . . . . . . 3-120
Subreferencing Specific Measured Channels . . . . . . . . . . . 3-120
Subreferencing Measured and Noise Models . . . . . . . . . . . 3-121
Treating Noise Channels as Measured Inputs . . . . . . . . . . 3-123
xiii
Low-Level Manipulation of Nonlinear ARX Components . . 4-41
xiv Contents
Choosing idgrey or idnlgrey Model Object . . . . . . . . . . . 5-4
xv
Estimating AR and ARMA Models at the Command
Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-10
Model Analysis
8
Overview of Model Validation and Plots . . . . . . . . . . . . . 8-2
When to Validate Models . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Ways to Validate Models . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
xvi Contents
Data for Validating Models . . . . . . . . . . . . . . . . . . . . . . . . . 8-3
Supported Model Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-4
Plotting Models in the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5
Getting Advice About Models . . . . . . . . . . . . . . . . . . . . . . . . 8-7
xvii
Pole and Zero Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-53
Supported Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-53
What Does a Pole-Zero Plot Show? . . . . . . . . . . . . . . . . . . . 8-53
How to Plot Model Poles and Zeros Using the GUI . . . . . . 8-55
How to Plot Poles and Zeros at the Command Line . . . . . . 8-56
Reducing Model Order Using Pole-Zero Plots . . . . . . . . . . . 8-57
xviii Contents
Viewing Model Response Using the LTI Viewer . . . . . . . . . 9-5
Combining Model Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-6
Example – Using System Identification Toolbox Software
with Control System Toolbox Software . . . . . . . . . . . . . . 9-6
xix
Opening a Saved Session . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-6
Saving, Merging, and Closing Sessions . . . . . . . . . . . . . . . . 11-6
Deleting a Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-7
Getting Help in the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-7
Exiting the System Identification Tool GUI . . . . . . . . . . . . 11-8
Index
xx Contents
1
1-2
Linear Model Structures
B C
Ay = u+ e
F D
where A, B, C, D and
F are polynomials with
coefficients that the
toolbox estimates from
data.
Typically, you begin
modeling using
simpler forms of
this generalized
structure (such as
ARX: Ay = Bu + e and
B
OE: y = u + e ) and, if
F increase the
necessary,
model complexity.
Grey-box model Use to represent “Estimating Linear
(idgrey object) arbitrary Grey-Box Models” on
parameterizations page 5-6
of state-space models.
For example, you can
use this structure
to represent your
ordinary differential
or difference equation
(ODE) and to
define parameter
dependencies.
1-3
1 Choosing Your System Identification Approach
1-4
Recommended Model Estimation Sequence
Note Model structure is not the only factor that determines model accuracy.
If your model is poor, you might need to preprocess your data by removing
outliers or filtering noise. For more information, see “Ways to Process Data
for System Identification” on page 2-4.
At the command line. Use the arx and the n4sid commands.
1-5
1 Choosing Your System Identification Approach
For general information about choosing you model strategy, see “About
System Identification”. For information about validating models, see
“Overview of Model Validation and Plots” on page 8-2.
1-6
Supported Models for Time- and Frequency-Domain Data
Continuous-Time Models
You can directly estimate the following types of continuous-time models:
Discrete-Time Models
You can estimate all linear and nonlinear models supported by the
System Identification Toolbox product as discrete-time models, except the
continuous-time transfer functions (process models). For more information
about process models, see “Identifying Low-Order Transfer Functions (Process
Models)” on page 3-20.
1-7
1 Choosing Your System Identification Approach
Nonlinear Models
You can estimate discrete-time Hammerstein-Wiener and nonlinear ARX
models from time-domain data. See Chapter 4, “Nonlinear Black-Box Model
Identification”.
You can also estimate nonlinear grey-box models from time-domain data. See
“Estimating Nonlinear Grey-Box Models” on page 5-16.
• Continuous-time data
• Discrete-time data
To designate discrete-time data, you set the sampling interval of the data to
the experimental data sampling interval. To designate continuous-time data,
you must set the sampling interval of the data to zero. Setting the sampling
interval to zero corresponds to taking a Fourier transform of continuous-time
data.
Continuous-Time Models
You can estimate the following types of continuous-time models directly:
1-8
Supported Models for Time- and Frequency-Domain Data
Discrete-Time Models
You can estimate only output-error (OE) polynomial models using
frequency-domain data. See “Identifying Input-Output Polynomial Models”
on page 3-39.
Other linear model structures include noise models, which are not supported
for frequency-domain data.
1-9
1 Choosing Your System Identification Approach
1-10
Supported Continuous-Time and Discrete-Time Models
1-11
1 Choosing Your System Identification Approach
Note For ODEs (grey-box models), you must first construct the model
structure and then apply an estimation command to the resulting model
object.
1-12
Commands for Model Estimation
1-13
1 Choosing Your System Identification Approach
This toolbox includes nine classes for representing models. For example,
idpoly represents linear input-output polynomial models, and idss
represents linear state-space models. For a complete list of available model
objects, see “Commands for Constructing Model Structures” on page 1-16.
Model properties define how a model object stores information. Model objects
store information about a model, including the mathematical form of a
model, names of input and output channels, units, names and values of
estimated parameters, parameter uncertainties, algorithm specifications, and
estimation information. For example, the idpoly model class has a property
called InputName for storing one or more input channel names. Different
model objects have different properties.
1-14
Creating Model Structures at the Command Line
model object. For example, the estimation method n4sid is unique to the
state-space model object idss.
Every class has a special method for creating objects of that class, called the
constructor. Using a constructor creates an instance of the corresponding
class or instantiates the object. The constructor name is the same as the class
name. For example, idpoly is both the name of the class representing linear
black-box polynomial models and the name of the constructor for instantiating
the model object.
For a tutorial about estimating models at the command line, see “Tutorial –
Identifying Linear Models Using the Command Line” in System Identification
Toolbox Getting Started Guide.
You must construct the model object independently of estimation when you
want to:
• Simulate a model
• Analyze a model
• Specify an initial guess for specific model parameter values before
estimation
In most cases, you can use the estimation commands to both construct
and estimate the model—without having to construct the model object
independently. For example, the estimation command pem lets you specify
both the model structure with unknown parameters and the estimation
algorithm. For information about how to both construct and estimate models
with a single command, see “Commands for Model Estimation” on page 1-12.
In case of grey-box models, you must always construct the model object first
and then estimate the parameters of the ordinary differential or difference
equation. For more information, see Chapter 5, “ODE Parameter Estimation
(Grey-Box Modeling)”.
1-15
1 Choosing Your System Identification Approach
After model estimation, you can recognize the corresponding model objects
in the MATLAB® Workspace browser by their class names. The name of the
constructor matches the name of the object it creates.
For information about how to both construct and estimate models with a
single command, see “Commands for Model Estimation” on page 1-12.
• ARX
• ARMAX
• Output-Error
• Box-Jenkins
idss Linear state-space models. Single- or multiple-output
models.
1-16
Creating Model Structures at the Command Line
For more information about when to use these commands, see “When to
Construct a Model Structure Independently of Estimation” on page 1-15.
Model Properties
• “Categories of Model Properties” on page 1-18
• “Specifying Model Properties for Estimation” on page 1-19
• “Viewing Model Properties and Estimated Parameters” on page 1-20
• “Getting Help on Model Properties at the Command Line” on page 1-22
1-17
1 Choosing Your System Identification Approach
Each model object has properties for storing information that are relevant
only to that specific model type. However, the idarx, idgrey, idpoly, idproc,
and idss model objects are based on the idmodel superclass and inherit all
idmodel properties.
Similarly, the nonlinear models idnlarx, idnlhw, and idnlgrey are based on
the idnlmodel superclass and inherit all idnlmodel properties.
In general, all nonlinear model objects have properties that belong to the
following categories:
1-18
Creating Model Structures at the Command Line
- EstimationInfo
Structure includes read-only fields that describe the estimation data set,
quantitative model quality measures, search termination conditions,
how the initial states are handled, and any warnings encountered during
the estimation.
For information about getting help on object properties, see “Getting Help on
Model Properties at the Command Line” on page 1-22.
When using the commands that let you both construct and estimate a model,
you can specify all top-level model properties in the estimator syntax.
Top-level properties are those listed when you type get(object_name). You
can also specify the top-level fields of the Algorithm structure directly in
the estimator using property-value pairs—such as focus in the previous
example—without having to define the structure fields first.
The following commands load the sample data, z8, construct an ARMAX
model, and estimate the model parameters. The arguments of the armax
estimator specify model properties as property-value pairs.
load iddata8
m_armax=armax(z8,'na',4,...
'nb',[3 2 3],...
'nc',4,...
'nk',[0 0 0],...
'focus', 'simulation',...
'covariance', 'none',...
'tolerance',1e-5,...
'maxiter',50);
1-19
1 Choosing Your System Identification Approach
For linear models, you can use a shortcut to specify the second-level
Algorithm properties, such as Advanced. With this syntax, you can reference
the structure fields by name without specifying the structure to which these
fields belong.
However, when estimating nonlinear black-box models, you must set the
specific fields of the Advanced Algorithm structure and the nonlinearity
estimators before estimation. For example, suppose you want to set the value
of the wavenet object property Options, which is a structure. The following
commands set the Options values before estimation and include the modified
wavenet object in the estimator:
where O specifies the values of the Options structure fields and M is the
estimated model. For more information about these and other commands,
see the corresponding reference page.
load iddata8
m_arx=arx(z8,[4 3 2 3 0 0 0]);
get(m_arx)
To access a specific property, use dot notation. For example, to view the A
matrix containing the estimated parameters in the previous model, type the
following command:
m_arx.a
1-20
Creating Model Structures at the Command Line
ans =
1.0000 -0.8441 -0.1539 0.2278 0.1239
m_arx.da
ans =
0 0.0357 0.0502 0.0438 0.0294
Property names are not case sensitive. You do not need to type the entire
property name if the first few letters uniquely identify the property.
To change property values for an existing model object, use the set command
or dot notation. For example, to change the input delays for all three input
channels to [1 1 1], type the following at the prompt:
set(m_arx,'nk',[1 1 1])
or equivalently
m_arx.nk = [1 1 1]
model.algorithm.PropertyName
m_arx.algorithm.MaxIter=50
m_arx.algorithm.MaxIter
1-21
1 Choosing Your System Identification Approach
Some model objects are based on the superclasses idmodel and idnlmodel
and inherit the properties of these superclasses. For such model objects, you
must independently look up the properties for both the model object and for
its superclass.
The following table summarizes the commands for getting help on object
properties.
1-22
Creating Model Structures at the Command Line
See Also
Validate each model directly after estimation to help fine-tune your modeling
strategy. When you do not achieve a satisfactory model, you can try a different
model structure and order, or try another identification algorithm. For more
information about validating and troubleshooting models, see “Overview of
Model Validation and Plots” on page 8-2.
1-23
1 Choosing Your System Identification Approach
If you know that some of the outputs have poor accuracy and should be
less important during estimation, you can control how much each output
is weighed in the estimation. For more information, see “Improving
Multiple-Output Estimation Results by Weighing Outputs During
Estimation” on page 1-26.
1-24
Modeling Multiple-Output Systems
Use this approach when no feedback is present in the dynamic system and
there are no couplings between the outputs. If you are unsure about the
presence of feedback, see “How to Analyze Data Using the advice Command”
on page 2-87.
• For working in the System Identification Tool GUI, see “Creating Data Sets
from a Subset of Signal Channels” on page 2-33.
1-25
1 Choosing Your System Identification Approach
• For working at the command line, see the “Subreferencing iddata Objects”
on page 2-57.
You can try refining the concatenated multiple-output model using the
original (multiple-output) data set.
You can specify output weights directly in the estimation command using
the Criterion and Weighting fields of the Algorithm property. You must
set the Criterion field to Trace, and set the Weighting field to the matrix
that contains the output weights. The Trace criterion minimizes the weighted
sum of the prediction errors using the weights specified by Weighting.
The following code snippet shows how to specify the Criterion and Weighting
Algorithm fields as part of the pem command:
model=pem(z,2,'criterion','trace','weighting',diag(Q,1))
where Q is a vector of positive values and the higher values for outputs to be
emphasized more during estimation.
1-26
Modeling Multiple-Output Systems
For more information about these Algorithm fields for linear estimation, see
the Algorithm Properties reference page. For more information about
the Algorithm fields for nonlinear estimation, see the idnlarx and idnlhw
reference pages.
1-27
1 Choosing Your System Identification Approach
1-28
2
The data can have single or multiple inputs and outputs, and can be either
real or complex.
Your data should be sampled at discrete and uniformly spaced time instants
to obtain an input sequence
u={u(T),u(2T),...,u(NT)}
y={y(T),y(2T),...,y(NT)}
u(t) and y(t) are the values of the input and output signals at time t,
respectively.
2-2
Types of Data You Can Model
2-3
2 Data Import and Processing
The following tasks help to prepare your data for identifying models from data:
You can represent data in the format of this toolbox by doing one of the
following:
• For working in the GUI, import data into the System Identification Tool
GUI.
See “Importing Data into the GUI” on page 2-14.
• For working at the command line, create an iddata or idfrd object.
For time-domain or frequency-domain data, see “Representing Time- and
Frequency-Domain Data Using iddata Objects” on page 2-49.
For frequency-response data, see “Representing Frequency-Response Data
Using idfrd Objects” on page 2-69.
• To simulate data with and without noise, see “Generating Data Using
Simulation” on page 2-117.
2-4
Ways to Process Data for System Identification
Preprocess data
Review the data characteristics for any of the following features to determine
if there is a need for preprocessing:
• Missing or faulty values (also known as outliers). For example, you might
see gaps that indicate missing data, values that do not fit with the rest of
the data, or noninformative values.
See “Handling Missing Data and Outliers” on page 2-93.
• Offsets and drifts in signal levels (low-frequency disturbances).
See “Handling Offsets and Trends in Data” on page 2-97 for information
about subtracting means and linear trends, and “Filtering Data” on page
2-109 for information about filtering.
• High-frequency disturbances above the frequency interval of interest for
the system dynamics.
See “Resampling Data” on page 2-102 for information about decimating and
interpolating values, and “Filtering Data” on page 2-109 for information
about filtering.
You can use data selection as a way to clean the data and exclude parts
with noisy or missing information. You can also use data selection to create
independent data sets for estimation and validation.
To learn more about selecting data, see “Selecting Subsets of Data” on page
2-89.
You can combine data from several experiments into a single data set. The
model you estimate from a data set containing several experiments describes
the average system that represents these experiments.
2-5
2 Data Import and Processing
The System Identification Tool GUI only supports uniformly sampled data.
2-6
Importing Data into the MATLAB® Workspace
You must import your time-domain data into the MATLAB workspace as
the following variables:
• Input data
- For single-input/single-output (SISO) data, the input must be a column
vector.
- For a data set with Nu inputs and NT samples (measurements), the input
is an NT-by-Nu matrix.
• Output data
- For single-input/single-output (SISO) data, the output must be a column
vector.
- For a data set with Ny outputs and NT samples (measurements), the
output is an NT-by-Ny matrix.
2-7
2 Data Import and Processing
For more information about importing data into the MATLAB workspace, see
MATLAB Data Import and Export.
After you import data, you can import it into the System Identification Tool
GUI or create a data object for working at the command line. For more
information about importing data into the GUI, see “Importing Time-Domain
Data into the GUI” on page 2-16. To learn more about creating a data object,
see “Representing Time- and Frequency-Domain Data Using iddata Objects”
on page 2-49.
You must import your time-series data into the MATLAB workspace as the
following variables:
• Output data
- For single-input/single-output (SISO) data, the output must be a column
vector.
- For a data set with Ny outputs and NT samples (measurements), the
output is an NT-by-Ny matrix.
For more information about importing data into the MATLAB workspace, see
MATLAB Data Import and Export.
2-8
Importing Data into the MATLAB® Workspace
After you import data, you can import it into the System Identification Tool
GUI or create a data object for working at the command line. For more
information about importing data into the GUI, see “Importing Time-Domain
Data into the GUI” on page 2-16. To learn more about creating a data object,
see “Representing Time- and Frequency-Domain Data Using iddata Objects”
on page 2-49.
∞
Y (iw) = ∫ y(t) e−iwt dt
−∞
∞
− iwt
U (iw) = 1
2π ∫ u(t)e dt
−∞
N
Y (eiwT ) = T ∑ y(kT ) e−iwkT
k=1
2-9
2 Data Import and Processing
Note This form only discretizes the time. The frequency is continuous.
N
Y (eiwnT ) = ∑ y(kT )e−iw kT
n
k=1
2πn
wn = n = 0, 1, 2,…, N − 1
T
The DFT is useful because it can be calculated very efficiently using the fast
Fourier transform (FFT) method. Fourier transforms of the input and output
data are complex numbers.
• Input data
- For single-input/single-output (SISO) data, the input u must be a column
(
vector containing the values u ei kT ) for k=1, 2, ..., N , where N is the
f f
number of frequencies.
- For a data set with Nu inputs and Nf frequencies, the input is an
Nf-by-Nu matrix.
• Output data
- For single-input/single-output (SISO) data, the output y must be a
(
column vector containing the values y ei kT ) for k=1, 2, ..., N , where
f
Nf is the number of frequencies.
- For a data set with Ny outputs and Nf frequencies, the output is an
Nf-by-Ny matrix.
2-10
Importing Data into the MATLAB® Workspace
• Frequency values
Must be a column vector.
For more information about importing data into the MATLAB workspace, see
MATLAB Data Import and Export.
After you import data, you can import it into the System Identification
Tool GUI or create a data object for working at the command line. For
more information about importing data into the GUI, see “Importing
Frequency-Domain Data into the GUI” on page 2-19. To learn more about
creating a data object, see “Representing Time- and Frequency-Domain Data
Using iddata Objects” on page 2-49.
y = Gu
2-11
2 Data Import and Processing
In this case, the frequency function G(iw) is the transfer function evaluated
on the imaginary axis s=iw.
Y ( z) = G( z)U ( z)
In this case, the frequency function G(eiwT) is the transfer function G(z)
evaluated on the unit circle. The argument of the frequency function G(eiwT)
is scaled by the sampling interval T to make the frequency function periodic
with the sampling frequency 2π T .
When the input to the system is a sinusoid of a specific frequency, the output
is also a sinusoid with the same frequency. The amplitude of the output is G
times the amplitude of the input. The phase of the shifted from the input by
ϕ = arg G . G is evaluated at the frequency of the input sinusoid.
You must import your frequency-response data into the MATLAB workspace
as the following variables:
2-12
Importing Data into the MATLAB® Workspace
For more information about importing data into the MATLAB workspace, see
MATLAB Data Import and Export.
After you import data into the MATLAB workspace, you can import it into
the System Identification Tool GUI or create a data object for working at the
command line. For more information about importing data into the GUI, see
“Importing Frequency-Response Data into the GUI” on page 2-22. To learn
more about creating a data object, see “Representing Frequency-Response
Data Using idfrd Objects” on page 2-69.
2-13
2 Data Import and Processing
2-14
Importing Data into the GUI
To open the GUI, type the following command in the MATLAB Command
Window:
ident
In the Import data list, select the type of data to import from the MATLAB
workspace, as shown in the following figure.
For an example of importing data into the System Identification Tool GUI, see
the Getting Started documentation.
2-15
2 Data Import and Processing
Note Your time-domain data must be sampled at equal time intervals. The
input and output signals must have the same number of data samples.
ident
2 In the System Identification Tool window, select Import data > Time
domain data. This action opens the Import Data dialog box.
2-16
Importing Data into the GUI
Note For time series, only import the output signal and enter [] for the
input.
2-17
2 Data Import and Processing
4 (Optional) In the Data Information area, click More to expand the dialog
box and enter the following settings:
Input Properties
• InterSample — This options specifies the behavior of the input signals
between samples during data acquisition. It is used when transforming
models from discrete-time to continuous-time and when resampling the
data.
– zoh (zero-order hold) indicates that the input was piecewise-constant
during data acquisition.
– foh (first-order hold) indicates that the output was piecewise-linear
during data acquisition.
– bl (bandwidth-limited behavior) specifies that the continuous-time
input signal has zero power above the Nyquist frequency (equal to the
inverse of the sampling interval).
Note See the d2c and c2d reference pages for more information about
transforming between discrete-time and continuous-time models.
Channel Names
• Input — Enter a string to specify the name of one or more input
channels.
2-18
Importing Data into the GUI
5 Click Import. This action adds a new data icon to the System Identification
Tool window.
Before you can import frequency-domain data into the System Identification
Tool GUI, you must import the data into the MATLAB workspace, as
described in “Importing Frequency-Domain Data into MATLAB” on page 2-9.
2-19
2 Data Import and Processing
Note The input and output signals must have the same number of data
samples.
ident
2 In the System Identification Tool window, select Import data > Freq.
domain data. This action opens the Import Data dialog box.
2-20
Importing Data into the GUI
4 (Optional) In the Data Information area, click More to expand the dialog
box and enter the following optional settings:
Input Properties
• InterSample — This options specifies the behavior of the input signals
between samples during data acquisition. It is used when transforming
models from discrete-time to continuous-time and when resampling the
data.
– zoh (zero-order hold) indicates that the input was piecewise-constant
during data acquisition.
– foh (first-order hold) indicates that the output was piecewise-linear
during data acquisition.
– bl (bandwidth-limited behavior) specifies that the continuous-time
input signal has zero power above the Nyquist frequency (equal to the
inverse of the sampling interval).
Note See the d2c and c2d reference page for more information about
transforming between discrete-time and continuous-time models.
Channel Names
• Input — Enter a string to specify the name of one or more input
channels.
2-21
2 Data Import and Processing
5 Click Import. This action adds a new data icon to the System Identification
Tool window.
2-22
Importing Data into the GUI
Prerequisite
Before you can import frequency-response data into the System Identification
Tool GUI, you must import the data into the MATLAB workspace, as described
in “Importing Frequency-Response Data into MATLAB” on page 2-11.
ident
2 In the System Identification Tool window, select Import data > Freq.
domain data. This action opens the Import Data dialog box.
3 In the Data Format for Signals list, select Freq. Function (Complex).
5 (Optional) In the Data Information area, click More to expand the dialog
box and enter the following optional settings:
Channel Names
2-23
2 Data Import and Processing
6 Click Import. This action adds a new data icon to the System Identification
Tool window.
2-24
Importing Data into the GUI
ident
2 In the System Identification Tool window, select Import data > Freq.
domain data. This action opens the Import Data dialog box.
5 (Optional) In the Data Information area, click More to expand the dialog
box and enter the following optional settings:
Channel Names
• Input — Enter a string to specify the name of one or more input
channels.
2-25
2 Data Import and Processing
6 Click Import. This action adds a new data icon to the System Identification
Tool window.
Before you can import a data object into the System Identification Tool GUI,
you must create the data object in the MATLAB workspace, as described in
“Representing Time- and Frequency-Domain Data Using iddata Objects” on
page 2-49 or “Representing Frequency-Response Data Using idfrd Objects”
on page 2-69.
2-26
Importing Data into the GUI
Note You can also import a Control System Toolbox™ frd object. Importing
an frd object converts it to an idfrd object.
Select Import data > Data object to open the Import Data dialog box.
ident
2 In the System Identification Tool window, select Import data > Data
object.
This action opens the Import Data dialog box. IDDATA or IDFRD/FRD is
already selected in the Data Format for Signals list.
2-27
2 Data Import and Processing
• Object — Enter the name of the MATLAB variable that represents the
data object in the MATLAB workspace. Press Enter.
• Data name — Enter the name of the data set, which appears in
the System Identification Tool window after the import operation is
completed.
• (Only for time-domain iddata object) Starting time — Enter the
starting value of the time axis for time plots.
• (Only for frequency domain iddata or idfrd object) Frequency unit
— Enter the frequency unit for response plots.
• Sampling interval — Enter the actual sampling interval in the
experiment. For more information about this setting, see “Specifying the
Data Sampling Interval” on page 2-30.
4 (Optional) In the Data Information area, click More to expand the dialog
box and enter the following optional settings:
2-28
Importing Data into the GUI
Note See the d2c and c2d reference page for more information about
transforming between discrete-time and continuous-time models.
Channel Names
• Input — Enter a string to specify the name of one or more input
channels.
2-29
2 Data Import and Processing
5 Click Import. This action adds a new data icon to the System Identification
Tool window.
The sampling interval is the time between successive data samples in your
experiment and must be the numerical time interval at which your data is
sampled in any units. For example, enter 0.5 if your data was sampled every
0.5 s, and enter 1 if your data was sampled every 1 s.
You can also use the sampling interval as a flag to specify continuous-time
data. When importing continuous-time frequency domain or
frequency-response data, set the Sampling interval to 0.
2-30
Importing Data into the GUI
interval. In addition, the sampling instants are used to set the horizontal
axis on time plots.
To specify Working Data, drag and drop the corresponding data icon into the
Working Data rectangle, as shown in the following figure.
2-31
2 Data Import and Processing
Similarly, to specify Validation Data, drag and drop the corresponding data
icon into the Validation Data rectangle.
Note For information about when to subtract mean values from the data,
see “Handling Offsets and Trends in Data” on page 2-97.
2-32
Importing Data into the GUI
1 In the System Identification Tool GUI, drag the icon of the data from which
you want to select channels to the Working Data rectangle.
2 Select Preprocess > Select channels to open the Select Channels dialog
box.
The Inputs list displays the input channels and the Outputs list displays
the output channels in the selected data set.
2-33
2 Data Import and Processing
3 In the Inputs list, select one or more channels in any of following ways:
Tip To exclude input channels and create time-series data, clear all
selections by holding down the Ctrl key and clicking each selection. To
reset selections, click Revert.
4 In the Outputs list, select one or more channels in any of following ways:
5 In the Data name field, type the name of the new data set. Use a name
that is unique in the Data Board.
6 Click Insert to add the new data set to the Data Board in the System
Identification Tool GUI.
7 Click Close.
2-34
Importing Data into the GUI
Experiments can mean data that was collected during different sessions, or
portions of the data collected during a single session. In the latter situation,
you can create multiexperiment data by splitting a single data set into
multiple segments that exclude corrupt data, and then merge the good data
segments.
2-35
2 Data Import and Processing
For example, suppose that you want to combine the data sets tdata, tdata2,
tdata3, tdata4 shown in the following figure.
2-36
Importing Data into the GUI
2-37
2 Data Import and Processing
2 In the System Identification Tool window, drag a data set icon to the Merge
Experiments dialog box (to the drop them here to be merged rectangle).
3 Repeat step 2 for each data set you want to merge. Go to the next step
after adding data sets.
4 In the Data name field, type the name of the new data set. This name
must be unique in the Data Board.
2-38
Importing Data into the GUI
5 Click Insert to add the new data set to the Data Board in the System
Identification Tool window.
Tip To get information about a data set in the System Identification Tool
GUI, right-click the data icon to open the Data/model Info dialog box.
To create a new data set that includes only the first and third experiments
in this data set:
2-39
2 Data Import and Processing
1 In the System Identification Tool window, drag and drop the tdatam data
icon to the Working Data rectangle.
2-40
Importing Data into the GUI
3 In the Experiments list, select one or more data sets in either of the
following ways:
• Select one data set by clicking its name.
• Select adjacent data sets by pressing the Shift key while clicking the
first and last names.
• Select nonadjacent data sets by pressing the Ctrl key while clicking
each name.
4 In the Data name field, type the name of the new data set. This name
must be unique in the Data Board.
5 Click Insert to add the new data set to the Data Board in the System
Identification Tool GUI.
2-41
2 Data Import and Processing
The Data/model Info dialog box opens. This dialog box describes the contents
and the properties of the corresponding data set. It also displays any
associated notes and the command-line equivalent of the operations you used
to create this data.
Tip To view or modify properties for several data sets, keep this window
open and right-click each data set in the System Identification Tool GUI. The
Data/model Info dialog box updates as you select each data set.
Data object
description
History of
syntax that
created this
object
2-42
Importing Data into the GUI
The Data/model Info dialog box opens. This dialog box describes both the
contents and the properties of the data. The object description area displays
the syntax of the operations you used to create the data in the GUI.
The Data/model Info dialog box also lets you rename the data by entering a
new name in the Data name field.
You can also specify a new display color using three RGB values in the Color
field. Each value is between 0 to 1 and indicates the relative presence of
red, green, and blue, respectively. For more information about specifying
default data color, see “Customizing the System Identification Tool GUI” on
page 11-20.
Tip As an alternative to using three RGB values, you can enter any one of
the following letters in single quotes:
These strings represent yellow, red, blue, cyan, green, magenta, and black,
respectively.
2-43
2 Data Import and Processing
Data object
description
History of
syntax that
created this
object
You can enter comments about the origin and state of the data in the Diary
And Notes area. For example, you might want to include the experiment
name, date, and the description of experimental conditions. When you
estimate models from this data, these notes are associated with the models.
2-44
Importing Data into the GUI
Time-domain data
Frequency-domain
data
Frequency-response
data
Note You cannot drag and drop a data icon into the model area on the right.
When you need additional space for organizing data or model icons, select
Options > Extra model/data board in the System Identification Tool GUI.
This action opens an extra session window with blank rectangles for data and
models. The new window is an extension of the current session and does
not represent a new session.
2-45
2 Data Import and Processing
Tip When you import or create data sets and there is insufficient space for
the icons, an additional session window opens automatically.
You can drag and drop data between the main System Identification Tool
GUI and any extra session windows.
Type comments in the Notes field to describe the data sets. When you save a
session, as described in “Saving, Merging, and Closing Sessions” on page 11-6,
all additional windows and notes are also saved.
Note You cannot delete a data set that is currently designated as Working
Data or Validation Data. You must first specify a different data set in the
System Identification Tool GUI to be Working Data or Validation Data, as
described in “Specifying Estimation and Validation Data” on page 2-31.
2-46
Importing Data into the GUI
To restore a data set from Trash, drag its icon from Trash to the Data or
Model Board in the System Identification Tool window. You can view the
Trash contents by double-clicking the Trash icon.
Note You must restore data to the Data Board; you cannot drag data icons to
the Model Board.
To permanently delete all items in Trash, select Options > Empty trash.
To export a data set to the MATLAB workspace, drag and drop the
corresponding icon to the To Workspace rectangle.
2-47
2 Data Import and Processing
When you export data to the MATLAB workspace, the resulting variables
have the same name as in the System Identification Tool GUI. For example,
the following figure shows how to export the time-domain data object datad.
2-48
Representing Time- and Frequency-Domain Data Using iddata Objects
iddata Constructor
• “Requirements for Constructing an iddata Object” on page 2-49
• “Constructing an iddata Object for Time-Domain Data” on page 2-50
• “Constructing an iddata Object for Frequency-Domain Data” on page 2-51
2-49
2 Data Import and Processing
data = iddata(y,u,Ts)
data = iddata(y,u,Ts,'Property1',Value1,...,'PropertyN',ValueN)
For nonuniformly sampled data, specify Ts as [], and set the value of the
SamplingInstants property as a column vector containing individual time
values. For example:
data = iddata(y,u,Ts,[],'SamplingInstants',TimeVector)
ts_data = iddata(y,[],Ts)
where y is the output data, [] indicates empty input data, and Ts is the
sampling interval.
2-50
Representing Time- and Frequency-Domain Data Using iddata Objects
The default channel name 'y1' is assigned to the first and only output
channel. When y2 contains several channels, the channels are assigned
default names 'y1','y2','y2',...,'yn'. Similarly, the default channel
name 'u1' is assigned to the first and only input channel. For more
information about naming channels, see “Naming, Adding, and Removing
Data Channels” on page 2-64.
data = iddata(y,u,Ts,'Frequency',w)
2-51
2 Data Import and Processing
Note You must specify the frequency vector for frequency-domain data.
For more information about iddata time and frequency properties, see
“Modifying Time and Frequency Vectors” on page 2-61.
You can specify additional properties when you create the iddata object, as
follows:
data = iddata(y,u,Ts,'Property1',Value1,...,'PropertyN',ValueN)
iddata Properties
To view the properties of the iddata object, use the get command. For
example, type the following commands at the prompt:
2-52
Representing Time- and Frequency-Domain Data Using iddata Objects
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.0800
Tstart: []
SamplingInstants: [1000x0 double]
TimeUnit: ''
ExperimentName: 'Exp1'
Notes: []
UserData: []
For a complete description of all properties, see the iddata reference page or
type idprops iddata at the prompt.
You can specify properties when you create an iddata object using the
constructor syntax:
data = iddata(y,u,Ts,'Property1',Value1,...,'PropertyN',ValueN)
To change property values for an existing iddata object, use the set command
or dot notation. For example, to change the sampling interval to 0.05, type
the following at the prompt:
set(data,'Ts',0.05)
or equivalently:
data.ts = 0.05
Property names are not case sensitive. You do not need to type the entire
property name if the first few letters uniquely identify the property.
2-53
2 Data Import and Processing
To view the property list, type the following command sequence at the prompt:
2-54
Representing Time- and Frequency-Domain Data Using iddata Objects
Domain: 'Frequency'
Name: []
OutputData: [501x1 double]
y: 'Same as OutputData'
OutputName: {'y1'}
OutputUnit: {''}
InputData: [501x1 double]
u: 'Same as InputData'
InputName: {'u1'}
InputUnit: {''}
Period: Inf
InterSample: 'zoh'
Ts: 0.0800
Units: 'rad/s'
Frequency: [501x1 double]
TimeUnit: ''
ExperimentName: 'Exp1'
Notes: []
UserData: []
2-55
2 Data Import and Processing
collected during a single session. In the latter situation, you can create a
multiexperiment iddata object by splitting the data from a single session into
multiple segments to exclude bad data, and merge the good data portions.
Note The idfrd object does not support the iddata equivalent of
multiexperiment data.
data = iddata(y,u,Ts)
where y, u, and Ts are 1-by-N cell arrays containing data from the different
experiments. Similarly, when you specify Tstart, Period, InterSample, and
SamplingInstants properties of the iddata object, you must assign their
values as 1-by-N cell arrays.
2-56
Representing Time- and Frequency-Domain Data Using iddata Objects
For example, to add the experiments in the iddata object dat4 to data, use
the following syntax:
data(:,:,:,'Run4') = dat4
This syntax explicitly assigns the experiment name 'Run4' to the new
experiment. The Experiment property of the iddata object stores experiment
names.
2-57
2 Data Import and Processing
data(samples,outputchannels,inputchannels,experimentname)
For example, to retrieve samples 5 through 30 in the iddata object data and
store them in a new iddata object data_sub, use the following syntax:
data_sub = data(5:30)
You can also use logical expressions to subreference data. For example, to
retrieve all data values from a single-experiment data set that fall between
sample instants 1.27 and 9.3 in the iddata object data and assign them to
data_sub, use the following syntax:
data_sub = data(data.sa>1.27&data.sa<9.3)
Note You do not need to type the entire property name. In this example, sa
in data.sa uniquely identifies the SamplingInstants property.
You can retrieve the input signal from an iddata object using the following
commands:
u = get(data,'InputData')
or
data.InputData
or
2-58
Representing Time- and Frequency-Domain Data Using iddata Objects
data.OutputData
or
data(samples,outputchannels,inputchannels,experiment)
To specify several channel names, you must use a cell array of name strings.
For example, suppose the iddata object data contains three output channels
(named y1, y2, and y3), and four input channels (named u1, u2, u3, and u4).
To select all data samples in y3, u1, and u4, type the following command at
the prompt:
or equivalently
Tip Use a colon (:) to specify all samples or all channels, and the empty
matrix ([]) to specify no samples or no channels.
2-59
2 Data Import and Processing
If you want to create a time-series object by extracting only the output data
from an iddata object, type the following command:
data_ts = data(:,:,[])
You can assign new values to subreferenced variables. For example, the
following command assigns the first 10 values of output channel 1 of data to
values in samples 101 through 110 in the output channel 2 of data1. It also
assigns the values in samples 101 through 110 in the input channel 3 of data1
to the first 10 values of input channel 1 of data.
data(1:10,1,1) = data1(101:110,2,3)
Subreferencing Experiments
Use the following general syntax to subreference specific experiments in
iddata objects:
data(samples,outputchannels,inputchannels,experimentname)
When specifying several experiment names, you must use a cell array of name
strings. The iddata object stores experiments name in the ExperimentName
property.
For example, suppose the iddata object data contains five experiments with
default names, Exp1, Exp2, Exp3, Exp4, and Exp5. Use the following syntax to
subreference the first and fifth experiment in data:
or
Tip Use a colon (:) to denote all samples and all channels, and the empty
matrix ([]) to specify no samples and no channels.
2-60
Representing Time- and Frequency-Domain Data Using iddata Objects
Alternatively, you can use the getexp command. The following example
shows how to subreference the first and fifth experiment in data:
or
The following example shows how to retrieve the first 100 samples of output
channels 2 and 3 and input channels 4 to 8 of Experiment 3:
dat(1:100,[2,3],[4:8],3)
Note Property names are not case sensitive. You do not need to type the
entire property name if the first few letters uniquely identify the property.
2-61
2 Data Import and Processing
2-62
Representing Time- and Frequency-Domain Data Using iddata Objects
data.ti = 'msec'
2-63
2 Data Import and Processing
logspace(-1,2,100)
• For multiexperiement
data with Ne
experiments,
Frequency is a
1-by-Ne cell array,
and each cell contains
the frequencies of
the corresponding
experiment.
For multiexperiement
data with Ne experiments,
Units is a 1-by-Ne cell
array, and each cell
contains the frequency
unit for each experiment.
2-64
Representing Time- and Frequency-Domain Data Using iddata Objects
Naming Channels
The iddata properties InputName and OutputName store the channel names
for the input and output signals. When you plot the data, you use channel
names to select the variable displayed on the plot. If you have multivariate
data, it is helpful to assign a name to each channel that describes the
measured variable. For more information about selecting channels on a plot,
see “Selecting Measured and Noise Channels in Plots” on page 11-18.
You can use the set command to specify the names of individual channels.
For example, suppose data contains two input channels (voltage and current)
and one output channel (temperature). To set these channel names, use the
following syntax:
set(data,'InputName',{'Voltage','Current'},
'OutputName','Temperature')
data.una = {'Voltage','Current')
data.yna = 'Temperature'
If you do not specify channel names when you create the iddata object,
the toolbox assigns default names. By default, the output channels
are named 'y1','y2',...,'yn', and the input channels are named
'u1','u2',...,'un'.
2-65
2 Data Import and Processing
Adding Channels
You can add data channels to an iddata object.
For example, consider an iddata object named data that contains an input
signal with four channels. To add a fifth input channel, stored as the vector
Input5, use the following syntax:
data.u(:,5) = Input5;
Input5 must have the same number of rows as the other input channels. In
this example, data.u(:,5) references all samples as (indicated by :) of the
input signal u and sets the values of the fifth channel. This channel is created
when assigning its value to Input5.
You can also combine input channels and output channels of several iddata
objects into one iddata object using concatenation. For more information, see
“Concatenating iddata Objects” on page 2-66.
For example, suppose the iddata object data contains three output channels
(named y1, y2, and y3), and four input channels (named u1, u2, u3, and u4).
To replace data such that it only contains samples in y3, u1, and u4, type
the following at the prompt:
The resulting data object contains one output channel and two input channels.
2-66
Representing Time- and Frequency-Domain Data Using iddata Objects
Horizontal Concatenation
Horizontal concatenation of iddata objects creates a new iddata object
that appends all InputData information and all OutputData. This type of
concatenation produces a single object with more input and output channels.
For example, the following syntax performs horizontal concatenation on the
iddata objects data1,data2,...,dataN:
data = [data1,data2,...,dataN]
data.InputData =
[data1.InputData,data2.InputData,...,dataN.InputData]
data.OutputData =
[data1.OutputData,data2.OutputData,...,dataN.OutputData]
The channels in the concatenated iddata object are named according to the
following rules:
2-67
2 Data Import and Processing
Vertical Concatenation
Vertical concatenation of iddata objects creates a new iddata object that
vertically stacks the input and output data values in the corresponding data
channels. The resulting object has the same number of channels, but each
channel contains more data points. For example, the following syntax creates
a data object such that its total number of samples is the sum of the samples
in data1,data2,...,dataN.
data.InputData =
[data1.InputData;data2.InputData;...;dataN.InputData]
data.OutputData =
[data1.OutputData;data2.OutputData;...;dataN.OutputData]
2-68
Representing Frequency-Response Data Using idfrd Objects
idfrd Constructor
The idfrd represents complex frequency-response data. Before you can
create an idfrd object, you must import your data as described in “Importing
Frequency-Response Data into MATLAB” on page 2-11.
Note The idfrd object can only encapsulate one frequency-response data
set. It does not support the iddata equivalent of multiexperiment data.
fr_data = idfrd(response,f,Ts)
response(ky,ku,kf), where ky, ku, and kf reference the kth output, input,
and frequency value, respectively, is interpreted as the complex-valued
frequency response from input ku to output ky at frequency f(kf).
2-69
2 Data Import and Processing
Note When you work at the command line, you can only create idfrd objects
from complex values of G(eiw). For a SISO system, response can be a vector.
You can specify object properties when you create the idfrd object using
the constructor syntax:
fr_data = idfrd(response,f,Ts,
'Property1',Value1,...,'PropertyN',ValueN)
idfrd Properties
To view the properties of the idfrd object, you can use the get command.
The following example shows how to create an idfrd object that contains
100 frequency-response values with a sampling time interval of 0.08 s and
get its properties:
2-70
Representing Frequency-Response Data Using idfrd Objects
ans =
Name: ''
Frequency: [100x1 double]
ResponseData: [1x1x100 double]
SpectrumData: []
CovarianceData: []
NoiseCovariance: []
Units: 'rad/s'
Ts: 0.0800
InputDelay: 0
EstimationInfo: [1x1 struct]
InputName: {'u1'}
OutputName: {'y1'}
InputUnit: {''}
OutputUnit: {''}
Notes: []
UserData: []
For a complete description of all idfrd object properties, see the idfrd
reference page or type idprops idfrd at the prompt.
To change property values for an existing idfrd object, use the set command
or dot notation. For example, to change the name of the idfrd object, type
the following command sequence at the prompt:
Property names are not case sensitive. You do not need to type the entire
property name if the first few letters uniquely identify the property.
2-71
2 Data Import and Processing
If you import fr_data into the System Identification Tool GUI, this data has
the name DC_Converter in the GUI, and not the variable name fr_data.
ans =
Name: 'DC_Converter'
Frequency: [100x1 double]
ResponseData: [1x1x100 double]
SpectrumData: []
CovarianceData: []
NoiseCovariance: []
Units: 'rad/s'
Ts: 0.0800
InputDelay: 0
EstimationInfo: [1x1 struct]
InputName: {'u1'}
OutputName: {'y1'}
InputUnit: {''}
OutputUnit: {''}
Notes: []
UserData: []
fr_data(outputchannels,inputchannels)
Tip Use a colon (:) to specify all channels, and use the empty matrix ([]) to
specify no channels.
2-72
Representing Frequency-Response Data Using idfrd Objects
fr_data(2,3)
You can also access the data in specific channels using channel names. To list
multiple channel names, use a cell array. For example, to retrieve the power
output, and the voltage and speed inputs, use the following syntax:
fr_data('power',{'voltage','speed'})
fr_data_sub = fselect(fr_data,[200:300])
You can also use logical expressions to subreference data. For example, to
retrieve all frequency-response values between frequencies 1.27 and 9.3 in
the idfrd object fr_data, use the following syntax:
fr_data_sub = fselect(fr_data,fr_data.f>1.27&fr_data.f<9.3)
Tip Use end to reference the last sample number in the data. For example,
data(77:end).
Note You do not need to type the entire property name. In this example, f in
fr_data.f uniquely identifies the Frequency property of the idfrd object.
2-73
2 Data Import and Processing
data = [data1,data2,...,dataN]
u1 Data 1 y1 Data 2 y1
2-by-2-by-nf u3 2-by-1-by-nf
u2 y2 y2
u1 Horizonal Concatenation y1
Combined of Data 1 and Data 2 Same
inputs u2 outputs
2-by-3-by-nf y2
u3
2-74
Representing Frequency-Response Data Using idfrd Objects
The resulting idfrd object data contains the frequency responses from
the same inputs in data1,data2,...,dataN to all the outputs. The
following diagram is a graphical representation of vertical concatenation of
frequency-response data. The (j,i,:) vector of the resulting response data
represents the frequency response from the ith input to the jth output at all
frequencies.
u1 Data 1 y1 u1 Data 1 y3
u2 2-by-2-by-nf y2 u2 1-by-2-by-nf
u1 Vertical Concatenation y1
Same y2 Combined
inputs of Data 1 and Data 2 outputs
u2 3-by-2-by-nf y3
Note Vertical concatenation of idfrd objects requires that they have the
same inputs and frequency vectors. If the input channel names are different
and their dimensions are the same, the concatenation operation uses the
names of input channels in the first idfrd object you listed. Output channels
must have unique names.
2-75
2 Data Import and Processing
However, when the idfrd objects are spectral models that you estimated, the
SpectrumData property is not empty and contains the power spectra and
cross spectra of the output noise in the system. For each output channel, the
toolbox estimates one noise channel to explain the difference between the
output of the model and the measured output.
⎛ data1.s
⎜ 0 ⎞⎟
data.s = ⎜ ⎟
⎜⎜ ⎟
⎝ 0 dataN .s ⎟⎠
See Also
The following operations also create idfrd objects:
2-76
Representing Frequency-Response Data Using idfrd Objects
• Converting the Control System Toolbox frd object. For more information,
see “Using Models with Control System Toolbox Software” on page 9-2.
2-77
2 Data Import and Processing
Tip You can infer time delays from time plots, which are required inputs
to most parametric models. A time delay is the time interval between the
change in input and the corresponding change in output.
See Also
“How to Analyze Data Using the advice Command” on page 2-87
2-78
Analyzing Data Quality
The plots you create using the plot commands, such as plot, bode, and
ffplot, are displayed in the standard MATLAB Figure window, which
provides options for formatting, saving, printing, and exporting plots to a
variety of file formats. To learn about plotting at the command line, see “How
to Plot Data at the Command Line” on page 2-85. For more information about
working with Figure window, see the MATLAB Graphics documentation.
To create one or more plots, select the corresponding check box in the Data
Views area of the System Identification Tool GUI.
An active data icon has a thick line in the icon, while an inactive data set
has a thin line. Only active data sets appear on the selected plots. To toggle
including and excluding data on a plot, click the corresponding icon in the
System Identification Tool GUI. Clicking the data icon updates any plots
that are currently open.
2-79
2 Data Import and Processing
When you have several data sets, you can view different input-output channel
pair by selecting that pair from the Channel menu. For more information
about selecting different input and output pairs, see “Selecting Measured and
Noise Channels in Plots” on page 11-18.
In this example, data and dataff are active and appear on the three selected
plots.
To close a plot, clear the corresponding check box in the System Identification
Tool GUI.
Tip To get information about working with a specific plot, select a help topic
from the Help menu in the plot window.
2-80
Analyzing Data Quality
The following table summarizes options that are specific to time plots, which
you can select from the plot window menus. For general information about
working with System Identification Toolbox plots, see “Working with Plots in
the System Identification Tool GUI” on page 11-15.
2-81
2 Data Import and Processing
Action Command
Toggle input display between Select Style > Staircase input for
piece-wise continuous (zero-order zero-order hold or Style > Regular
hold) and linear interpolation input for first-order hold.
(first-order hold) between samples.
The top axes show the input and the bottom axes show the output. The
vertical axis of each plot is labeled with the corresponding channel name.
2-82
Analyzing Data Quality
Action Command
Toggle display between periodogram Select Options > Periodogram or
and spectral estimate. Options > Spectral analysis.
Change frequency units. Select Style > Frequency (rad/s)
or Style > Frequency (Hz).
Toggle frequency scale between Select Style > Linear frequency
linear and logarithmic. scale or Style > Log frequency
scale.
Toggle amplitude scale between Select Style > Linear amplitude
linear and logarithmic. scale or Style > Log amplitude
scale.
2-83
2 Data Import and Processing
2-84
Analyzing Data Quality
Action Command
Change frequency units. Select Style > Frequency (rad/s)
or Style > Frequency (Hz).
Toggle frequency scale between Select Style > Linear frequency
linear and logarithmic. scale or Style > Log frequency
scale.
Toggle amplitude scale between Select Style > Linear amplitude
linear and logarithmic. scale or Style > Log amplitude
scale.
2-85
2 Data Import and Processing
frequency-response
data generates a
frequency-response plot. Note For idfrd data, this
When plotting time- or command is equivalent to
frequency-domain inputs ffplot(data).
and outputs, the top axes
show the output and the
bottom axes show the input.
All plot commands display the data in the standard MATLAB Figure window.
For more information about working with the Figure window, see the
MATLAB Graphics documentation.
To plot portions of the data, you can subreference specific samples (see
“Subreferencing iddata Objects” on page 2-57 and “Subreferencing idfrd
Objects” on page 2-72. For example:
plot(data(1:300))
For time-domain data, to plot only the input data as a function of time, use
the following syntax:
plot(data(:,[],:)
You can generate plots of the input data in the time domain using:
plot(data.sa,data.u)
semilogx(data.fr,abs(data.u))
2-86
Analyzing Data Quality
Before applying the advice command to your data, you must have represented
your data as an iddata object. For more information, see “Representing Time-
and Frequency-Domain Data Using iddata Objects” on page 2-49.
2-87
2 Data Import and Processing
If you are using the System Identification Tool GUI, you must export your
data to the MATLAB workspace before you can use the advice command on
this data. For more information about exporting data, see “Exporting Models
from the GUI to the MATLAB Workspace” on page 11-13.
Use the following syntax to get advice about an iddata object data:
advice(data)
For more information about the advice syntax, see the advice reference page.
• Does it make sense to remove constant offsets and linear trends from the
data?
• What are the excitation levels of the signals and how does this affects the
model orders?
• Is there an indication of output feedback in the data? When feedback
is present in the system, only prediction-error methods work well for
estimating closed-loop data.
• What is the estimated input-output delay in the system (dead time)?
See Also
advice
delayest
detrend
feedback
pexcit
2-88
Selecting Subsets of Data
You can also use data selection as a way to clean the data and exclude parts
with noisy or missing information. For example, when your data contains
missing values, outliers, level changes, and disturbances, you can select one
or more portions of the data that are suitable for identification and exclude
the rest.
If you only have one data set and you want to estimate linear models, you
should split the data into two portions to create two independent data sets for
estimation and validation, respectively. Splitting the data is selecting parts of
the data set and saving each part independently.
You can merge several data segments into a single multiexperiment data set
and identify an average model. For more information, see “Importing Data
into the GUI” on page 2-14 or “Representing Time- and Frequency-Domain
Data Using iddata Objects” on page 2-49.
Note Subsets of the data set must contain enough samples to adequately
represent the system, and the inputs must provide suitable excitation to the
system.
2-89
2 Data Import and Processing
After you select portions of the data, you can specify to use one data segment
for estimating models and use the other data segment for validating models.
For more information, see “Specifying Estimation and Validation Data” on
page 2-31.
Note Selecting <--Preprocess > Quick start performs the following actions
simultaneously:
Note Selecting data does not extract experiments from a data set containing
multiple experiments. For more information about multiexperiment data, see
“Creating Multiexperiment Data Sets in the GUI” on page 2-35.
2-90
Selecting Subsets of Data
2 Drag the data set you want to subset to the Working Data area.
3 If your data contains multiple I/O channels, in the Channel menu, select
the channel pair you want to view. The upper plot corresponds to the input
signal, and the lower plot corresponds to the output signal.
Although you view only one I/O channel pair at a time, your data selection
is applied to all channels in this data set.
5 In the Data name field, enter the name of the data set containing the
selected data.
6 Click Insert. This action saves the selection as a new data set and adds
it to the Data Board.
2-91
2 Data Import and Processing
2-92
Handling Missing Data and Outliers
You can use misdata to estimate missing values. This command linearly
interpolates missing values to estimate the first model. Then, it uses this
model to estimate the missing data as parameters by minimizing the output
prediction errors obtained from the reconstructed data. You can specify the
model structure you want to use in the misdata argument or estimate a
default-order model using the n4sid method. For more information, see the
misdata reference page.
Note You can only use misdata on time-domain data stored in an iddata
object. For more information about creating iddata objects, see “Representing
Time- and Frequency-Domain Data Using iddata Objects” on page 2-49.
For example, suppose y and u are output and input signals that contain NaNs.
This data is sampled at 0.2 s. The following syntax creates a new iddata
object with these input and output signals.
2-93
2 Data Import and Processing
Apply the misdata command to the new data object. For example:
dat1 = misdata(dat);
plot(dat,dat1) % Check how the missing data
% was estimated on a time plot
Handling Outliers
Malfunctions can produce errors in measured values, called outliers. Such
outliers might be caused by signal spikes or by measurement malfunctions.
If you do not remove outliers from your data, this can adversely affect the
estimated models.
• Before estimating a model, plot the data on a time plot and identify values
that appear out of range.
• After estimating a model, plot the residuals and identify unusually large
values. For more information about plotting residuals, see “Residual
Analysis” on page 8-21. Evaluate the original data that is responsible for
large residuals. For example, for the model Model and validation data
Data, you can use the following commands to plot the residuals:
Next, try these techniques for removing or minimizing the effects of outliers:
• Extract the informative data portions into segments and merge them into
one multiexperiment data set (see “Example – Extracting and Modeling
Specific Data Segments” on page 2-95). For more information about
selecting and extracting data segments, see “Selecting Subsets of Data”
on page 2-89.
2-94
Handling Missing Data and Outliers
Tip The inputs in each of the data segments must be consistently exciting
the system. Splitting data into meaningful segments for steady-state
data results in minimum information loss. Avoid making data segments
too small.
• Manually replace outliers with NaNs and then use the misdata command
to reconstruct flagged data. This approach treats outliers as missing data
and is described in “Handling Missing Data” on page 2-93. Use this method
when your data contains several inputs and outputs, and when you have
difficulty finding reliable data segments in all variables.
• Remove outliers by prefiltering the data for high-frequency content because
outliers often result from abrupt changes. For more information about
filtering, see “Filtering Data” on page 2-109.
You cannot simply concatenate the good data segments because the transients
at the connection points compromise the model. Instead, you must create a
multiexperiment iddata object, where each experiment corresponds to a good
segment of data, as follows:
2-95
2 Data Import and Processing
See Also
To learn more about the theory of handling missing data and outliers, see the
chapter on preprocessing data in System Identification: Theory for the User,
Second Edition, by Lennart Ljung, Prentice Hall PTR, 1999.
2-96
Handling Offsets and Trends in Data
For steady-state data, you should remove mean values and linear trends
from both input and output signals.
Remove one linear trend or several piecewise linear trends when the levels
drift during the experiment. Signal drift is considered a low-frequency
disturbance and can result in unstable models.
You should not detrend data before model estimation when you want:
2-97
2 Data Import and Processing
Tip When signals vary around a large signal level, you can improve
computational accuracy of nonlinear models by detrending the signal
means.
For more information about handling drifts in the data, see the chapter on
preprocessing data in System Identification: Theory for the User, Second
Edition, by Lennart Ljung, Prentice Hall PTR, 1999.
Both the GUI and the command line let you subtract the mean values and one
linear trend from steady-state time-domain signals.
2-98
Handling Offsets and Trends in Data
Tip You can use the shortcut Preprocess > Quick start to perform several
operations: remove the mean value from each signal, split data into two
halves, specify the first half as model estimation data (or Working Data),
and specify the second half as model Validation Data.
1 In the System Identification Tool, drag the data set you want to detrend to
the Working Data rectangle.
2-99
2 Data Import and Processing
Note If you plan to estimate models from this data, your data must be
regularly sampled.
Use the detrend command to remove the signal means or linear trends:
[data_d,T]=detrend(data,Type)
Note If you plan to estimate models from this data, your data must be
regularly sampled.
• Values of the offsets you want to remove from the input and output data.
If you do not know these values, visually inspect a time plot of your data.
For more information, see “How to Plot Data at the Command Line” on
page 2-85.
1 Create a default object for storing input-output offsets that you want to
remove from the data.
T = getTrend(data)
T.InputOffset=I_value;
2-100
Handling Offsets and Trends in Data
T.OutputOffset=O_value;
where I_value is the input offset value, and O_value is the input offset
value.
data_d = detrend(data,T)
where the second input argument T stores the offset values as its properties.
See Also
detrend
TrendInfo
2-101
2 Data Import and Processing
Resampling Data
In this section...
“What Is Resampling?” on page 2-102
“Resampling Data Using the GUI” on page 2-103
“Resampling Data at the Command Line” on page 2-103
“Resampling Data Without Aliasing Effects” on page 2-105
“See Also” on page 2-108
What Is Resampling?
Resampling data signals in the System Identification Toolbox product applies
an antialiasing (lowpass) FIR filter to the data and changes the sampling rate
of the signal by decimation or interpolation.
If your data is sampled faster than needed during the experiment, you can
decimate it without information loss. If your data is sampled more slowly
than needed, there is a possibility that you miss important information
about the dynamics at higher frequencies. Although you can resample the
data at a higher rate, the resampled values occurring between measured
samples do not represent measured information about your system. Instead
of resampling, repeat the experiment using a higher sampling rate.
Tip You should decimate your data when it contains high-frequency noise
outside the frequency range of the system dynamics.
Resampling takes into account how the data behaves between samples, which
you specify when you import the data into the System Identification Tool
GUI (zero-order or first-order hold). For more information about the data
properties you specify before importing the data, see “Importing Data into
the GUI” on page 2-14.
You can resample data using the System Identification Tool GUI or the
resample command. You can only resample time-domain data at uniform
time intervals.
2-102
Resampling Data
To create a new data set by resampling the input and output signals:
2 Drag the data set you want to resample to the Working Data area.
3 In the Resampling factor field, enter the factor by which to multiply the
current sampling interval:
• For decimation (fewer samples), enter a factor greater than 1 to increase
the sampling interval by this factor.
• For interpolation (more samples), enter a factor less than 1 to decrease
the sampling interval by this factor.
Default = 1.
4 In the Data name field, type the name of the new data set. Choose a name
that is unique in the Data Board.
5 Click Insert to add the new data set to the Data Board in the System
Identification Toolbox window.
2-103
2 Data Import and Processing
Note resample uses the Signal Processing Toolbox™ command, when this
toolbox is installed on your computer. If this toolbox is not installed, use
idresamp instead. idresamp only lets you specify the filter order, whereas
resample also lets you specify filter coefficients and the design parameters
of the Kaiser window.
To create a new iddata object datar by resampling data, use the following
syntax:
datar = resample(data,P,Q,filter_order)
In this case, P and Q are integers that specify the new sampling interval: the
new sampling interval is Q/P times the original one. You can also specify the
order of the resampling filter as a fourth argument filter_order, which is
an integer (default is 10). For detailed information about resample, see the
corresponding reference page.
The next example shows how you can increase the sampling rate by a factor of
1.5 and compare the signals:
plot(u)
ur = resample(u,3,2);
plot(u,ur)
When the Signal Processing Toolbox product is not installed, using resample
calls idresamp instead.
datar = idresamp(data,R,filter_order)
In this case, R=Q/P, which means that data is interpolated by a factor P and
then decimated by a factor Q. To learn more about idresamp, type help
idresamp.
2-104
Resampling Data
2-105
2 Data Import and Processing
2-106
Resampling Data
2-107
2 Data Import and Processing
Use resample to decimate the signal before estimating the spectrum and plot
the frequency response, as follows:
g3 = spa(resample(y,1,4));
figure
ffplot(g1,g3)
The following figure shows that the estimated spectrum of the resampled
signal has the same amplitude as the original spectrum. Thus, there is no
indication of folding effects when you use resample to eliminate aliasing.
See Also
For a detailed discussion about handling disturbances, see the chapter on
preprocessing data in System Identification: Theory for the User, Second
Edition, by Lennart Ljung, Prentice Hall PTR, 1999.
2-108
Filtering Data
Filtering Data
In this section...
“Supported Filters” on page 2-109
“Choosing to Prefilter Your Data” on page 2-109
“How to Filter Data Using the GUI” on page 2-110
“How to Filter Data at the Command Line” on page 2-113
“See Also” on page 2-116
Supported Filters
You can filter the input and output signals through a linear filter before
estimating a model in the System Identification Tool GUI or at the command
line. How you want to handle the noise in the system determines whether it
is appropriate to prefilter the data.
Prefiltering the input and output data through the same filter does not change
the input-output relationship for a linear system. However, prefiltering does
change the noise characteristics and affects the estimated model of the system.
2-109
2 Data Import and Processing
To get a reliable noise model, avoid prefiltering the data. Instead, set
the Focus property of the estimation algorithm to Simulation. For more
information about the Focus property, see the Algorithm Properties
reference page.
Note When you prefilter during model estimation, the filtered data is used to
only model the input-to-output dynamics. However, the disturbance model is
calculated from the unfiltered data.
2 Drag the data set you want you want to filter to the Working Data area.
2-110
Filtering Data
7 Click Filter to preview the filtered results. If you are satisfied, go to step 8.
Otherwise, return to step 5.
8 In the Data name field, enter the name of the data set containing the
selected data.
9 Click Insert to save the selection as a new data set and add it to the Data
Board.
2-111
2 Data Import and Processing
2 Drag the data set you want you want to filter to the Working Data area.
3 Select <--Preprocess > Select range. This selection displays one of the
following plots:
• Frequency-domain data — Plot shows the absolute of the squares of the
input and output spectra.
• Frequency-response data — Top axes show the frequency response
magnitude equivalent to the ratio of the output to the input, and the
bottom axes show the ratio of the input signal to itself, which has the
value of 1 at all frequencies.
2-112
Filtering Data
Tip If you need to change the frequency units from rad/s to Hz, select
Style > Frequency (Hz). To change the frequency units from Hz to
rad/s, select Style > Frequency (rad/s).
7 In the Data name field, enter the name of the data set containing the
selected data.
8 Click Insert. This action saves the selection as a new data set and adds
it to the Data Board.
In general, you can specify any custom filter. Use this syntax to filter an
iddata object data using the filter called filter:
fdata = idfilt(data,filter)
In the simplest case, you can specify a passband filter for time-domain data
using the following syntax:
2-113
2 Data Import and Processing
In this case, w1 and wh represent the low and high frequencies of the passband,
respectively.
The filter is an n-by-2 matrix, where each row defines a passband in radians
per second.
In general, you can specify any custom filter. Use this syntax to filter an
iddata object data using the filter called filter:
fdata = idfilt(data,filter)
You use this syntax to filter an iddata object data using a custom filter
specified by filter:
fdata = idfilt(data,filter)
2-114
Filtering Data
filter = idm
filter = {num,den}
filter = {A,B,C,D}
idm is a SISO idmodel or LTI object. For more information about LTI objects,
see the Control System Toolbox documentation.
filter = Wf
When data contains several experiments, Wf is a cell array with the length
equal to the number of experiments in data.
fdata = idfilt(data,filter,'noncausal')
2-115
2 Data Import and Processing
When you apply idfilt to an idfrd data object, the data is first converted
to a frequency-domain iddata object (see “Transforming Between
Frequency-Domain and Frequency-Response Data” on page 2-130). The result
is an iddata object.
See Also
To learn how to filter data during linear model estimation instead, you can
set the Focus property of the estimation algorithm to Filter and specify the
filter characteristics. For more information about model properties, see the
Algorithm Properties reference page.
For more information about prefiltering data, see the chapter on preprocessing
data in System Identification: Theory for the User, Second Edition, by Lennart
Ljung, Prentice Hall PTR, 1999.
2-116
Generating Data Using Simulation
Simulating output data requires that you have a parametric model. For more
information about commands for constructing models, see “Commands for
Constructing Model Structures” on page 1-16.
To generate input data, use idinput to construct a signal with the desired
characteristics, such as a random Gaussian or binary signal or a sinusoid.
idinput returns a matrix of input values.
The following table lists the commands you can use to simulate output data.
For more information about these commands, see the corresponding reference
pages.
2-117
2 Data Import and Processing
2 Create an iddata object using the periodic input and leaving the output
empty.
u = iddata([],per_u,'Period',...
[300; 300]);
You can use the periodic input to simulate the output, and the use etfe to
compute the estimated response of the model.
2-118
Generating Data Using Simulation
For periodic input, etfe honors the period and computes the frequency
response using an appropriate frequency grid. In this case, the Bode plot
shows a good fit at the five excited frequencies.
load iddata8
A = [1 -1.2 0.7];
B(1,:) = [0 1 0.5 0.1]; % first input
B(2,:) = [0 1.5 -0.5 0]; % second input
B(3,:) = [0 -0.1 0.5 -0.1]; % third input
C = [1 0 0 0 0];
Ts = 1;
m = idpoly(A,B,C,'Ts',1);
In this example, the leading zeros in the B matrix indicate the input delay
(nk), which is 1 for each input channel. The trailing zero in B(2,:) makes
the number of coefficients equal for all channels.
u = idinput([200,3],'prbs');
2-119
2 Data Import and Processing
sim(m,u)
5 Compare model output to measured data to see how well the models
captures the underlying dynamics.
compare(z8,m)
2-120
Transforming Between Time- and Frequency-Domain Data
2-121
2 Data Import and Processing
1 In the System Identification Tool GUI, drag the icon of the data you want to
transform to the Working Data rectangle, as shown in the following figure.
2-122
Transforming Between Time- and Frequency-Domain Data
2-123
2 Data Import and Processing
• Frequency Domain Data — Create a new iddata object using the fft
method. Go to step 6.
6 In the Name of new data field, type the name of the new data set. This
name must be unique in the Data Board.
7 Click Transform to add the new data set to the Data Board in the System
Identification Tool GUI.
2-124
Transforming Between Time- and Frequency-Domain Data
1 In the System Identification Tool GUI, drag the icon of the data you want
to transform to the Working Data rectangle.
6 In the Name of new data field, type the name of the new data set. This
name must be unique in the Data Board.
7 Click Transform to add the new data set to the Data Board in the System
Identification Tool GUI.
2-125
2 Data Import and Processing
⎡1 0 0⎤
⎢1 0 0 ⎥⎥
⎢
⎢0 1 0⎥
⎢ ⎥
⎢0 1 0⎥
⎢0 0 1⎥
⎢ ⎥
⎢⎣0 0 1 ⎥⎦
Note To create a separate experiment for the response from each input,
see “Transforming Between Frequency-Domain and Frequency-Response
Data” on page 2-130.
2-126
Transforming Between Time- and Frequency-Domain Data
frequencies, and also make the frequency vector coarser in the region outside
the system dynamics. Typically, high-frequency noise dominates away
from frequencies where interesting system dynamics occur. The System
Identification Tool GUI lets you specify logarithmic frequency spacing, which
results in a variable frequency resolution.
Note The spafdr command lets you lets you specify any variable frequency
resolution.
1 In the System Identification Tool GUI, drag the icon of the data you want
to transform to the Working Data rectangle.
6 In the Name of new data field, type the name of the new data set. This
name must be unique in the Data Board.
7 Click Transform to add the new data set to the Data Board in the System
Identification Tool GUI.
2-127
2 Data Import and Processing
See Also
For a description of time-domain, frequency-domain, and frequency-response
data, see “Importing Data into the MATLAB Workspace” on page 2-7.
To learn how to transform data at the command line instead of the GUI, see
“Transforming Data Domain at the Command Line” on page 2-128.
2-128
Transforming Between Time- and Frequency-Domain Data
t_data =
ifft(f_data)
2-129
2 Data Import and Processing
dataf = iddata(idfrdobj)
2-130
Transforming Between Time- and Frequency-Domain Data
⎡1 0 0⎤
⎢1 0 0 ⎥⎥
⎢
⎢0 1 0⎥
⎢ ⎥
⎢0 1 0⎥
⎢0 0 1⎥
⎢ ⎥
⎢⎣0 0 1 ⎥⎦
In general, for nu inputs and ns samples, the input matrix has nu columns
and (ns ⋅ nu) rows.
If you are working with multiple inputs, you also have the option of
storing the contribution by each input as an independent experiment in a
multiexperiment data set. To transform an idfrd object with the name
idfrdobj to a multiexperiment data set datf, where each experiment
corresponds to each of the inputs in idfrdobj
datf = iddata(idfrdobj,'me')
See Also
Transforming from time-domain or frequency-domain data to
frequency-response data is equivalent to creating a frequency-response model
2-131
2 Data Import and Processing
2-132
Manipulating Complex-Valued Data
The display commands compare and plot also work with complex-valued
data and models, but only show the absolute values of the signals. To plot
the real and imaginary parts of the data separately, use plot(real(data))
and plot(imag(data)), respectively.
Command Description
abs(data) Absolute value of complex signals in iddata object.
angle(data) Phase angle (in radians) of each complex signals in
iddata object.
2-133
2 Data Import and Processing
Command Description
complex(data) For time-domain data, this command makes the iddata
object complex—even when the imaginary parts are
zero. For frequency-domain data that only stores
the values for nonnegative frequencies, such that
realdata(data)=1, it adds signal values for negative
frequencies using complex conjugation.
imag(data) Selects the imaginary parts of each signal in iddata
object.
isreal(data) 1 when data (time-domain or frequency-domain)
contains only real input and output signals, and returns
0 when data (time-domain or frequency-domain)
contains complex signals.
real(data) Real part of complex signals in iddata object.
realdata(data) Returns a value of 1 when data is a real-valued,
time-domain signal, and returns 0 otherwise.
For example, suppose that you create a frequency-domain iddata object Datf
by applying fft to a real-valued time-domain signal to take the Fourier
transform of the signal. The following is true for Datf:
isreal(Datf) = 0
realdata(Datf) = 1
2-134
3
Y ( z) = G( z)U ( z)
3-2
Identifying Frequency-Response Models
2 In the Method list, select the spectral analysis method you want to use.
For information about each method, see “Options for Computing Spectral
Models” on page 3-5.
3-3
3 Linear Model Identification
5 In the Model Name field, enter the name of the correlation analysis model.
The model name should be unique in the Model Board.
6 Click Estimate to add this model to the Model Board in the System
Identification Tool GUI.
8 To view the frequency-response plot, select the Frequency resp check box
in the System Identification Tool GUI. For more information about working
with this plot, see “Frequency Response Plots” on page 8-38.
3-4
Identifying Frequency-Response Models
The resulting models are stored as idfrd model objects. For detailed
information about the commands and their arguments, see the corresponding
reference page.
After estimating the model, see Chapter 8, “Model Analysis” to validate the
model.
3-5
3 Linear Model Identification
3-6
Identifying Frequency-Response Models
Specifying the frequency resolution for etfe and spa is different than for
spafdr.
2π ⎛ radians ⎞
⎜ ⎟
M ⎝ sampling interval ⎠
M is a scalar integer that sets the size of the lag window. The value of M
controls the trade-off between bias and variance in the spectral estimate.
The default value of M for spa is good for systems without sharp resonances.
For etfe, the default value of M gives the maximum resolution.
3-7
3 Linear Model Identification
For spafdr, the frequency resolution around the frequency k is the value R(k).
You can enter R(k) in any one of the following ways:
Note The scalar R is inversely related to the M value used for etfe and
spa.
The default value of the resolution for spafdr is twice the difference between
neighboring frequencies in the frequency vector.
frequencies T
2πk
( Period
k
) where k = 1, 2,..., Period
.
Spectrum Normalization
The spectrum of a signal is the square of the Fourier transform of the
signal. The spectral estimate using the commands spa, spafdr, and etfe is
normalized by the sampling interval T:
M
Φ y (ω) = T ∑ Ry (kT ) e−iwT WM (k)
k=− M
3-8
Identifying Frequency-Response Models
where WM(k) is the lag window, and M is the width of the lag window. The
output covariance Ry(kT) is given by the following discrete representation:
N
ˆ (kT ) = 1
R y
N
∑ y(lT − kT ) y(lT )
l =1
By Parseval’s theorem, the average energy of the signal must equal the
average energy in the estimated spectrum, as follows:
1 π/T
2π ∫− π / T
Ey2 (t) = Φ y (ω) dω
S1 ≡ Ey2 (t)
1 π/T
2π ∫− π / T
S2 ≡ Φ y (ω) dω
To compare the left side of the equation (S1) to the right side (S2), enter the
following commands in the MATLAB Command Window:
load iddata1
% Create time-series iddata object
y = z1(:,1,[]);
% Define sample interval from the data
T = y.Ts;
% Estimate frequency response
sp = spa(y);
% Remove spurious dimensions
phiy = squeeze(sp.spec);
% Compute average energy from the estimated
3-9
3 Linear Model Identification
⎛ π ⎞
⎜ ⎟
⎝ T ⋅ length(phiy) ⎠
S1 =
19.2076
S2 =
19.4646
Thus, the average energy of the signal approximately equals the average
energy in the estimated spectrum.
3-10
Identifying Impulse-Response Models
• Impulse response
Impulse response is the output signal that results when the input is an
impulse and has the following definition for a discrete model:
u(t) = 0 t>0
u(t) = 1 t=0
• Step response
3-11
3 Linear Model Identification
Step response is the output signal that results from a step input, defined as
follows:
u(t) = 0 t<0
u(t) = 1 t≥0
t
y(t) = ∫0 h ( t − z) ⋅ u( z)dz
3-12
Identifying Impulse-Response Models
2 In the Time span (s) field, specify a scalar value as the time interval over
which the impulse or step response is calculated. For a scalar time span T,
the resulting response is plotted from -T/4 to T.
Tip You can also enter a 2-D vector in the format [min_value max_value].
The order of the prewhitening filter, N, is the order of the A filter. N equals
the number of lags. The default value of N is 10, which you can also specify
as [].
4 In the Model Name field, enter the name of the correlation analysis model.
The name of the model should be unique in the Model Board.
5 Click Estimate to add this model to the Model Board in the System
Identification Tool GUI.
Next Steps
3-13
3 Linear Model Identification
working with this plot and selecting to view impulse- versus step-response,
see “Impulse and Step Response Plots” on page 8-30.
The following tables summarize the commands for computing impulse- and
step-response models. Both impulse and step produce the same FIR model,
but generate different plots. The resulting models are stored as idarx model
objects and contain impulse-response coefficients in the model parameter
B. For detailed information about these commands, see the corresponding
reference page.
3-14
Identifying Impulse-Response Models
Next Steps
3-15
3 Linear Model Identification
where y is the response data, t is the time vector, and ysd is the standard
deviations of the response.
At the command line. You can use the impulse command to plot the
impulse response. The time delay is equal to the first positive peak in the
3-16
Identifying Impulse-Response Models
transient response magnitude that is greater than the confidence region for
positive time values.
The resulting figure shows that the first positive peak of the response
magnitude, which is greater than the confidence region for positive time
values, occurs at 0.24 s.
3-17
3 Linear Model Identification
where u(t) and y(t) are the input and output signals, respectively. v(t) is the
additive noise term. G(q) is the transfer function of the system. The G(q)u(t)
notation represents the following operation:
∞
G(q)u(t) = ∑ g(k)u(t − k)
k=1
3-18
Identifying Impulse-Response Models
∞
G(q) = ∑ g(k)q−k q−1u(t) = u(t − 1)
k=1
The estimation algorithm prefilters the data such that the input is as white
as possible. It then computes the correlations from the prefiltered data to
obtain the FIR coefficients.
g is also estimated for negative lags, which takes into account any noncausal
effects from input to output. Noncausal effects can result from feedback. The
coefficients are computed using the least-squares method.
3-19
3 Linear Model Identification
3-20
Identifying Low-Order Transfer Functions (Process Models)
You can create different model structures by varying the number of poles,
adding an integrator, or adding or removing a time delay or a zero. You can
specify a first-, second-, or third-order model, and the poles can be real or
complex (underdamped modes).
Note Continuous-time process models let you estimate the input delay.
K
G(s) = e− sTd
1 + sTp1
You must import your data into the MATLAB workspace, as described in
Chapter 2, “Data Import and Processing”.
3-21
3 Linear Model Identification
• Imported data into the System Identification Tool GUI. See “Importing
Time-Domain Data into the GUI” on page 2-16. For supported data
formats, see “Data Supported by a Process Model” on page 3-21.
• Performed any required data preprocessing operations. If you need to
model nonzero offsets, such as when model contains integration behavior,
do not detrend your data. In other cases, to improve the accuracy of your
model, you should detrend your data. See “Ways to Process Data for
System Identification” on page 2-4.
1 In the System Identification Tool GUI, select Estimate > Process models
to open the Process Models dialog box.
2 If your model contains multiple inputs, select the input channel in the
Input list. This list only appears when you have multiple inputs. For more
information, see “Options for Multiple-Input Models” on page 3-34.
3-22
Identifying Low-Order Transfer Functions (Process Models)
3 In the Model Transfer Function area, specify the model structure using
the following options:
• Under Poles, select the number of poles, and then select All real or
Underdamped.
• Select the Zero check box to include a zero, which is a numerator term
other than a constant, or clear the check box to exclude the zero.
• Select the Delay check box to include a delay, or clear the check box
to exclude the delay.
• Select the Integrator check box to include an integrator (self-regulating
process), or clear the check box to exclude the integrator.
Note By default, the model Name is set to the acronym that reflects the
model structure, as described in “Options for Specifying the Process-Model
Structure” on page 3-33.
3-23
3 Linear Model Identification
Parameter table displays Auto. If you do not have a good guess for the
parameter values, Auto works better than entering an ad hoc value.
If you know the range of possible values for a parameter, enter these values
into the corresponding Bounds field to help the estimation algorithm.
For example, the following figure shows that the delay value Td is fixed
at 2 s and is not estimated.
3-24
Identifying Low-Order Transfer Functions (Process Models)
6 In the Disturbance Model list, select one of the available options. For
more information about each option, see “Options for the Disturbance
Model Structure” on page 3-35.
7 In the Focus list, select how to weigh the relative importance of the fit at
different frequencies. For more information about each option, see “Options
for Frequency-Weighing Focus” on page 3-36.
8 In the Initial state list, specify how you want the algorithm to treat initial
states. For more information about the available options, see “Options for
Initial States” on page 3-37.
Tip If you get a bad fit, you might try setting a specific method for handling
initial states, rather than choosing it automatically.
3-25
3 Linear Model Identification
10 In the Model Name field, edit the name of the model or keep the default.
The name of the model should be unique in the Model Board.
12 Click Estimate to add this model to the Model Board in the System
Identification Tool GUI.
13 To stop the search and save the results after the current iteration has been
completed, click Stop Iterations. To continue iterations from the current
model, click the Continue iter button to assign current parameter values
as initial guesses for the next search.
Next Steps
• Validate the model by selecting the appropriate check box in the Model
Views area of the System Identification Tool GUI. For more information
about validating models, see “Overview of Model Validation and Plots”
on page 8-2.
• Refine the model by clicking the Value —> Initial Guess button to assign
current parameter values as initial guesses for the next search, edit the
Model Name field, and click Estimate.
3-26
Identifying Low-Order Transfer Functions (Process Models)
Prerequisites
Before you can perform this task, you must have
You can use the following general syntax to both configure and estimate
process models:
m = pem(data,mod_struc,'Property1',Value1,...,
'PropertyN',ValueN)
3-27
3 Linear Model Identification
Tip You do not need to construct the model object using idproc before
estimation unless you want to specify initial parameter guesses or fixed
parameter values, as described in “Example – Estimating Process Models
with Fixed Parameters at the Command Line” on page 3-30.
The property-value pairs specify any model properties that configure the
estimation algorithm and the initial conditions. For more information about
accessing and setting model properties, see “Model Properties” on page 1-17.
You can use pem to refine parameter estimates of an existing process model,
as described in “Refining Linear Parametric Models” on page 3-104.
For detailed information about pem and idproc, see the corresponding
reference page.
3-28
Identifying Low-Order Transfer Functions (Process Models)
K
G(s) = e− sTd
1 + sTp1
This process has two inputs and the response from each input is estimated by
a first-order process model. All parameters are free to vary.
3-29
3 Linear Model Identification
with K = -3.2168
Tp1 = 23.033
Td = 10.101
K
G_2(s) = ---------- * exp(-Td*s)
1+Tp1*s
with K = 9.9877
Tp1 = 2.0314
Td = 4.8368
Use dot notation to get the value of any model parameter. For example, to get
the Value field in the K structure, type the following command:
m.K.value
3-30
Identifying Low-Order Transfer Functions (Process Models)
Use the following commands to prepare the data and construct a process
model with one pole and a delay:
with K = NaN
Tp1 = NaN
Td = NaN
The model parameters K, Tp1, and Td are assigned NaN values, which means
that the parameters have not yet been estimated from the data.
3-31
3 Linear Model Identification
To set the value of K to 12 and keep it fixed, use the following commands:
mod.K.value=12;
mod.K.status='fixed';
Note mod is defined for one input. This model is automatically adjusted
to have a duplicate for each input.
mod_proc=pem(ze,mod)
with K = 12
Tp1 = 7.0998e+007
Td = 15
K
G_2(s) = ---------- * exp(-Td*s)
1+Tp1*s
with K = 12
Tp1 = 3.6962
Td = 3.817
In this case, the value of K is fixed at 12, but Tp1 and Td are estimated.
3-32
Identifying Low-Order Transfer Functions (Process Models)
Action Example
Fix the value of K to 12.
m=pem(ze,'p1d','k','fix','k',12)
At the command line. Specify the model structure using an acronym that
includes the following letters and numbers:
3-33
3 Linear Model Identification
K
G(s) = e− sTd
1 + sTp1
K p (1 + sTz )
G(s) =
1 + 2sζTw + s2 Tw2
Kp
G(s) = e− sTd
s
K p (1 + sTz )
G(s) =
(1 + sTp1 ) (1 + sTp2 ) (1 + sTp3 )
For more information about estimating models , see “How to Estimate Process
Models at the Command Line” on page 3-27.
In the System Identification Tool GUI. To fit a data set with multiple
inputs in the Process Models dialog box, configure the process model settings
for one input at a time. When you finish configuring the model and the
3-34
Identifying Low-Order Transfer Functions (Process Models)
estimation settings for one input, select a different input in the Input
Number list.
If you want the same transfer function to apply to all inputs, select the Same
structure for all channels check box. To apply a different structure to each
channel, leave this check box clear, and create a different transfer function for
each input.
At the command line. Specify the model structure as a cell array of acronym
strings in the estimation command pem. For example, use this command to
specify the first-order transfer function for the first input, and a second-order
model with a zero and an integrator for the second input:
m = idproc({'P1','P2ZI'})
m = pem(data,m)
To apply the same structure to all inputs, define a single structure in idproc.
y = Gu + He
You can estimate only the dynamic model G, or estimate both the dynamic
model and the disturbance model H. For process models, H is a rational
transfer function C/D, where the C and D polynomials for a first- or
second-order ARMA model.
3-35
3 Linear Model Identification
• None — The algorithm does not estimate a noise model (C=D=1). This
option also sets Focus to Simulation.
• Order 1 — Estimates a noise model as a continuous-time, first-order
ARMA model.
• Order 2 — Estimates a noise model as a continuous-time, second-order
ARMA model.
pem(data,'P1D','DisturbanceModel','ARMA1')
For a complete list of values for the DisturbanceModel model property, see
the idproc reference page.
In the System Identification Tool GUI. Set Focus to one of the following
options:
• Prediction — Uses the inverse of the noise model H to weigh the relative
importance of how closely to fit the data in various frequency ranges.
Corresponds to minimizing one-step-ahead prediction, which typically
favors the fit over a short time interval. Optimized for output prediction
applications.
• Simulation — Uses the input spectrum to weigh the relative importance of
the fit in a specific frequency range. Does not use the noise model to weigh
the relative importance of how closely to fit the data in various frequency
ranges. Optimized for output simulation applications.
3-36
Identifying Low-Order Transfer Functions (Process Models)
• Stability — Behaves the same way as the Prediction option, but also
forces the model to be stable. For more information about model stability,
see “Unstable Models” on page 8-66.
• Filter — Specify a custom filter to open the Estimation Focus dialog box,
where you can enter a filter, as described in “Simple Passband Filter” on
page 2-113 or “Defining a Custom Filter” on page 2-114. This prefiltering
applies only for estimating the dynamics from input to output. The
disturbance model is determined from the estimation data.
pem(data,'P1D','dist','arma2','Focus','Simulation')
In the System Identification Tool GUI. Set Initial state to one of the
following options:
3-37
3 Linear Model Identification
m=pem(data,'P1D','InitialState','zero')
For a complete list of values for the InitialState model property, see the
idproc reference page.
3-38
Identifying Input-Output Polynomial Models
3-39
3 Linear Model Identification
nu
Bi (q) C(q)
A(q) y(t) = ∑ ui ( t − nki ) + e(t)
F
i=1 i
( q) D(q)
To estimate polynomial models, you must specify the model order as a set of
integers that represent the number of coefficients for each polynomial you
include in your selected structure—na for A, nb for B, nc for C, nd for D,
and nf for F. You must also specify the number of samples nk corresponding
to the input delay—dead time—given by the number of samples before the
output responds to the input.
For more information about the family of transfer-function models, see the
corresponding section in System Identification: Theory for the User, Second
Edition, by Lennart Ljung, Prentice Hall PTR, 1999.
3-40
Identifying Input-Output Polynomial Models
where y(t) is the output, u(t) is the input, and T is the sampling interval. q-1
is a time-shift operator that compactly represents such difference equations
nu
Bi (q) C(q)
A(q) y(t) = ∑ ui ( t − nki ) + e(t)
F (q)
i=1 i
D(q)
The model structures differ by how many of these polynomials are included
in the structure. Thus, different model structures provide varying levels of
flexibility for modeling the dynamics and noise characteristics. For more
3-41
3 Linear Model Identification
3-42
Identifying Input-Output Polynomial Models
The input-output polynomial models for single output systems are represented
by the idpoly object. Multi-output polynomial ARX models are represented
by the idarx object.
The System Identification Tool GUI supports only the polynomial models
listed in the table. However, you can use pem to estimate all five polynomial
or any subset of polynomials in the general equation. For more information
about working with pem, see “Using pem to Estimate Polynomial Models”
on page 3-61.
3-43
3 Linear Model Identification
B(s) C(s)
A(s)Y (s) = U (s) + E(s)
F (s) D(s)
A(s) = s4 + a1 s3 + a2 s2 + a3
B(s) = b1 s + b2
3-44
Identifying Input-Output Polynomial Models
For a system with nu inputs and ny outputs, A(q) is an ny-by-ny matrix. A(q)
can be represented as a polynomial in the shift operator q-1:
For more information about the time-shift operator, see “Understanding the
Time-Shift Operator q” on page 3-41.
where the matrix element akj is a polynomial in the shift operator q-1:
− nakj
akj (q) = δkj + a1kj q−1 + … + akj kj q
na
δkj represents the Kronecker delta, which equals 1 for k=j and equals 0
for k≠j. This polynomial describes how the old values of the jth output are
affected by the kth output. The ith row of A(q) represents the contribution of
the past output values for predict the current value of the ith output.
3-45
3 Linear Model Identification
where the matrix element bkj is a polynomial in the shift operator q-1:
nkkj is the delay from the jth input to the kth output. B(q) represents the
contributions of inputs to predicting all output values.
Note For frequency-domain data, you can only estimate ARX and OE
models.
3-46
Identifying Input-Output Polynomial Models
You must import your data into the MATLAB workspace, as described in
Chapter 2, “Data Import and Processing”.
Tip You can set the sampling interval when you import data into the GUI or
set the Ts property of the data object at the command line.
3-47
3 Linear Model Identification
In most cases, you do not know the model orders in advance. To get initial
model orders and delays for your system, you can estimate several ARX
models with a range of orders and delays and compare the performance of
these models. You choose the model orders that correspond to the best model
performance and use these orders as an initial guess for further modeling.
Because this estimation procedure uses the ARX model structure, which
includes the A and B polynomials, you only get estimates for the na, nb, and
nk parameters. However, you can use these results as initial guesses for the
corresponding polynomial orders and input delays in other model structures,
such as ARMAX, OE, and BJ.
If the estimated nk is too small, the leading nb coefficients are much smaller
than their standard deviations. Conversely, if the estimated nk is too large,
there is a significant correlation between the residuals and the input for lags
that correspond to the missing B terms. For information about residual
analysis plots, see “Residual Analysis” on page 8-21.
3-48
Identifying Input-Output Polynomial Models
To estimate model orders and input delays in the System Identification Tool
GUI:
2 Edit the Orders field to specify a range of poles, zeros, and delays. For
example, enter the following values for na, nb, and nk:
Tip As a shortcut for entering 1:10 for each required model order, click
Order Selection.
3-49
3 Linear Model Identification
3-50
Identifying Input-Output Polynomial Models
3 Click Estimate to open the ARX Model Structure Selection window, which
displays the model performance for each combination of model parameters.
The following figure shows an example plot.
This action adds a new model to the Model Board in the System
Identification Tool GUI. 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.
After estimating model orders and delays, use these values as initial guesses
for estimating other model structures, as described in “How to Estimate
Polynomial Models in the GUI” on page 3-56.
3-51
3 Linear Model Identification
If you are working with a multiple-output system, you must use struc,
arxstruc, and selstruc commands for each output. In this case, you must
subreference the correct output channel in your estimation and validation
data sets.
For each estimation, you use two independent data sets—an estimation
data set and a validation data set. These independent data set can be from
different experiments, or data subsets from a single experiment. For more
information about subreferencing data, see “Subreferencing iddata Objects”
on page 2-57 and “Subreferencing idfrd Objects” on page 2-72.
For example, the following command defines the range of model orders and
delays na=2:5, nb=1:5, and nk=1:5:
NN = struc(2:5,1:5,1:5))
arxstruc. The arxstruc command takes the output from struc, estimates
an ARX model for each model order, and compares the model output to the
measured output. arxstruc returns the loss for each model, which is the
normalized sum of squared prediction errors.
For example, the following command uses the range of specified orders NN
to compute the loss function for single-input/single-output estimation data
data_e and validation data data_v:
V = arxstruc(data_e,data_v,NN)
[na nb nk]
3-52
Identifying Input-Output Polynomial Models
selstruc. The selstruc command takes the output from arxstruc and opens
the ARX Model Structure Selection window to guide your choice of the model
order with the best performance.
For example, to open the ARX Model Structure Selection window and
interactively choose the optimum parameter combination, use the following
command:
selstruc(V)
For more information about working with the ARX Model Structure Selection
window, see “Selecting Model Orders from the Best ARX Structure” on page
3-54.
nn = selstruc(V,'AIC')
nn = selstruc(V,'MDL')
To select the structure with the smallest loss function, use the following
command:
nn = selstruc(V,0)
After estimating model orders and delays, use these values as initial guesses
for estimating other model structures, as described in “Using pem to Estimate
Polynomial Models” on page 3-61.
3-53
3 Linear Model Identification
To estimate the delay for a data set data, type the following at the prompt:
delayest(data)
If your data has a single input, MATLAB computes a scalar value for the
input delay—equal to the number of data samples. If your data has multiple
inputs, MATLAB returns a vector, where each value is the delay for the
corresponding input signal.
To compute the actual delay time, you must multiply the input delay by the
sampling interval of the data.
You can also use the ARX Model Structure Selection window to estimate input
delays and model order together, as described in “Estimating Model Orders at
the Command Line” on page 3-52.
For a procedure on generating this plot in the System Identification Tool GUI,
see “Estimating Orders and Delays in the GUI” on page 3-48. To open this
plot at the command line, see “Estimating Model Orders at the Command
Line” on page 3-52.
The following figure shows a sample plot in the ARX Model Structure
Selection window.
3-54
Identifying Input-Output Polynomial Models
The horizontal axis in the ARX Model Structure Selection window is the total
number of ARX parameters:
Number of parameters = na + nb
The vertical axis, called Unexplained output variance (in %), is the ARX
model prediction error for a specific number of parameters. The prediction
error is the sum of the squares of the differences between the validation
data output and the model output. In other words, Unexplained output
variance (in %) is the portion of the output not explained by the model.
Three rectangles are highlighted on the plot—green, blue, and red. Each color
indicates a type of best-fit criterion, as follows:
• Red minimizes the sum of the squares of the difference between the
validation data output and the model output. This option is considered the
overall best fit.
• Green minimizes Rissanen MDL criterion.
3-55
3 Linear Model Identification
In the ARX Model Structure Selection window, click any bar to view the
orders that give the best fit. The area on the right is dynamically updated to
show the orders and delays that give the best fit.
For more information about the AIC criterion, see “Akaike’s Criteria for
Model Validation” on page 8-58.
• Imported data into the System Identification Tool GUI. See “Importing
Time-Domain Data into the GUI” on page 2-16. For supported data
formats, see “Data Supported by Polynomial Models” on page 3-46.
• Performed any required data preprocessing operations. To improve the
accuracy of your model, you should detrend your data. Removing offsets
and trends is especially important for Output-Error (OE) models and has
less impact on the accuracy of models that include a flexible noise model
structure, such as ARMAX and Box-Jenkins. See “Ways to Process Data for
System Identification” on page 2-4.
• Select a model structure, model orders, and delays. For a list of available
structures, see “What Are Black-Box Polynomial Models?” on page
3-39 For more information about how to estimate model orders and
delays, see “Estimating Orders and Delays in the GUI” on page 3-48.
For multiple-output ARX model, you must specify order matrices in the
MATLAB workspace, as described in “Options for Multiple-Input and
Multiple-Output ARX Orders” on page 3-64.
3-56
Identifying Input-Output Polynomial Models
2 In the Structure list, select the polynomial model structure you want to
estimate from the following options:
• ARX:[na nb nk]
• ARMAX:[na nb nc nk]
• OE:[nb nf nk]
• BJ:[nb nc nd nf nk]
This action updates the options in the Linear Parametric Models dialog box
to correspond with this model structure. For information about each model
structure, see “What Are Black-Box Polynomial Models?” on page 3-39.
Note For time-series data, only AR and ARMA models are available. For
more information about estimating time-series models, see Chapter 6,
“Time Series Identification”.
3 In the Orders field, specify the model orders and delays, as follows:
Tip To enter model orders and delays using the Order Editor dialog box,
click Order Editor.
3-57
3 Linear Model Identification
5 In the Name field, edit the name of the model or keep the default.
6 In the Focus list, select how to weigh the relative importance of the fit at
different frequencies. For more information about each option, see “Option
for Frequency-Weighing Focus” on page 3-65.
7 In the Initial state list, specify how you want the algorithm to treat initial
states. For more information about the available options, see “Options for
Initial States” on page 3-37.
Tip If you get an inaccurate fit, try setting a specific method for handling
initial states rather than choosing it automatically.
10 Click Estimate to add this model to the Model Board in the System
Identification Tool GUI.
3-58
Identifying Input-Output Polynomial Models
11 (Prediction-error method only) To stop the search and save the results
after the current iteration has been completed, click Stop Iterations. To
continue iterations from the current model, click the Continue iter button
to assign current parameter values as initial guesses for the next search.
Next Steps
• Validate the model by selecting the appropriate check box in the Model
Views area of the System Identification Tool GUI. For more information
about validating models, see “Overview of Model Validation and Plots”
on page 8-2.
• Export the model to the MATLAB workspace for further analysis by
dragging it to the To Workspace rectangle in the System Identification
Tool GUI.
Tip For ARX and OE models, you can use the exported model for
initializing a nonlinear estimation at the command line. This initialization
may improve the fit of the model. See “Using Linear Model for
Nonlinear ARX Estimation” on page 4-28, and “Using Linear Model for
Hammerstein-Wiener Estimation” on page 4-64.
Prerequisites
3-59
3 Linear Model Identification
If you are estimating a multiple-output ARX model, you must specify order
matrices in the MATLAB workspace before estimation, as described in
“Options for Multiple-Input and Multiple-Output ARX Orders” on page 3-64.
For single-output data, the arx and iv4 commands produce an idpoly model
object, and for multiple-output data these commands produce an idarx model
object.
You can use the following general syntax to both configure and estimate ARX
models:
3-60
Identifying Input-Output Polynomial Models
data is the estimation data and [na nb nk] specifies the model orders, as
discussed in “What Are Black-Box Polynomial Models?” on page 3-39.
The property-value pairs specify any model properties that configure the
estimation algorithm and the initial conditions. For more information about
accessing and setting model properties, see “Model Properties” on page 1-17.
To get discrete-time models, use the time-domain data (iddata object). To get
a single-output continuous-time model, apply d2c to a discrete-time model
or use continuous-time frequency-domain data—either idfrd object, or
frequency-domain iddata with Ts=0.
For more information about validating you model, see “Overview of Model
Validation and Plots” on page 8-2.
Tip You can use the estimated ARX model for initializing a nonlinear
estimation at the command line, which improves the fit of the model. See
“Using Linear Model for Nonlinear ARX Estimation” on page 4-28.
3-61
3 Linear Model Identification
method gives the maximum likelihood estimate. that minimizes the prediction
errors to obtain maximum-likelihood values. The resulting models are stored
as idpoly model objects.
Use the following general syntax to both configure and estimate polynomial
models:
m = pem(data,'na',na,
'nb',nb,
'nc',nc,
'nd',nb,
'nf',nc,
'nk',nk,
'Property1',Value1,...,
'PropertyN',ValueN)
where data is the estimation data. na, nb, nc, nd, nf are integers that specify
the model orders, and nk specifies the input delays for each input. If you
skip any property-value pair, the corresponding parameter value is set to
zero—except nk, which has the default value 1. For more information about
model orders, see “What Are Black-Box Polynomial Models?” on page 3-39.
Tip You do not need to construct the model object using idoly before
estimation.
Note To get faster estimation of ARX models, use arx or iv4 instead of pem.
3-62
Identifying Input-Output Polynomial Models
You can also model the ARARMAX structure—called the extended matrix
model—by setting nf=0.
For multiple inputs, nb, nf, and nk are row vectors of the same lengths as the
number of input channels:
m = armax(Data,[na nb nc nk])
m = oe(Data,[nb nf nk])
m = bj(Data,[nb nc nd nf nk])
Tip If your data is sampled fast, it might help to apply a lowpass filter to the
data before estimating the model, or specify a frequency range for the Focus
property during estimation. For example, to model only data in the frequency
range 0-10 rad/s, use the Focus property, as follows:
For more information about validating your model, see “Overview of Model
Validation and Plots” on page 8-2.
3-63
3 Linear Model Identification
Tip For ARX and OE models, you can use the model for initializing a
nonlinear estimation at the command line, which may improve the fit of the
model. See “Using Linear Model for Nonlinear ARX Estimation” on page 4-28,
and “Using Linear Model for Hammerstein-Wiener Estimation” on page 4-64.
For detailed information about pem and idpoly, see the corresponding
reference page.
In the System Identification Tool GUI. You can enter the matrices
directly in the Orders field.
At the command line. Define variables that store the model order matrices
and specify these variables in the model-estimation command. You can use
the following syntax to estimate a model with these orders:
3-64
Identifying Input-Output Polynomial Models
arx(data,'na',NA,'nb',NB,'nk',NK)
In the System Identification Tool GUI. Set Focus to one of the following
options:
• Prediction — Uses the inverse of the noise model H to weigh the relative
importance of how closely to fit the data in various frequency ranges.
Corresponds to minimizing one-step-ahead prediction, which typically
favors the fit over a short time interval. Optimized for output prediction
applications.
• Simulation — Uses the input spectrum to weigh the relative importance of
the fit in a specific frequency range. Does not use the noise model to weigh
the relative importance of how closely to fit the data in various frequency
ranges. Optimized for output simulation applications.
• Stability — Estimates the best stable model. For more information about
model stability, see “Unstable Models” on page 8-66.
• Filter — Specify a custom filter to open the Estimation Focus dialog box,
where you can enter a filter, as described in “Simple Passband Filter” on
page 2-113 or “Defining a Custom Filter” on page 2-114. This prefiltering
applies only for estimating the dynamics from input to output. The
disturbance model is determined from the unfiltered estimation data.
3-65
3 Linear Model Identification
m=arx(data,[2 2 3],'Focus','Simulation')
In the System Identification Tool GUI. For ARMAX, OE, and BJ models,
set Initial state to one of the following options:
m=armax(data,[2 2 2 3],'InitialState','zero')
For a complete list of values for the InitialState model property, see the
idpoly reference page.
3-66
Identifying Input-Output Polynomial Models
variable method. For more information about IV, see the section on
variance-optimal instruments in System Identification: Theory for the User,
Second Edition, by Lennart Ljung, Prentice Hall PTR, 1999.
The ARX and IV algorithms treat noise differently. ARX assumes white noise.
However, the instrumental variable algorithm, IV, is not sensitive to noise
color. Thus, use IV when the noise in your system is not completely white and
it is incorrect to assume white noise. If the models you obtained using ARX
are inaccurate, try using IV.
1 Load a sample data set z8 with three inputs and one output, measured at
1-second intervals and containing 500 data samples:
load iddata8
2 Use armax to both construct the idpoly model object, and estimate the
parameters:
nu
A(q) y(t) = ∑ Bi (q)ui ( t − nki ) + C(q) e(t)
i=1
3-67
3 Linear Model Identification
Typically you try different model orders and compare results, ultimately
choosing the simplest model that best describes the system dynamics. The
following command specifies the estimation data set, z8, and the orders of
the A, B, and C polynomials as na, nb, and nc, respectively. nk of [0 0 0]
specifies that there is no input delay for all three input channels.
m_armax=armax(z8,'na',4,...
'nb',[3 2 3],...
'nc',4,...
'nk',[0 0 0],...
'focus', 'simulation',...
'tolerance',1e-5,...
'maxiter',50);
armax is a version of pem with simplified syntax for the ARMAX model
structure. The armax method both constructs the idpoly model object
and estimates its parameters.
m_armax=armax(z8,[4 3 2 3 4 0 0 0],...
'focus', 'simulation',...
'tolerance',1e-5,...
'maxiter',50);
3-68
Identifying Input-Output Polynomial Models
3 To view information about the resulting model object, type the following at
the prompt:
m_armax
4 To view all property values for this model, type the following command:
get(m_armax)
ans =
3-69
3 Linear Model Identification
d: 1
f: [3x1 double]
da: [0 0.1012 0.1804 0.1210 0.0303]
db: [3x3 double]
dc: [0 0.1111 0.0767 0.0484 0.0460]
dd: 0
df: [3x1 double]
na: 4
nb: [3 2 3]
nc: 4
nd: 0
nf: [0 0 0]
nk: [0 0 0]
InitialState: 'Auto'
Name: ''
Ts: 1
InputName: {3x1 cell}
InputUnit: {3x1 cell}
OutputName: {'y1'}
OutputUnit: {''}
TimeUnit: ''
ParameterVector: [16x1 double]
PName: {}
CovarianceMatrix: [16x16 double]
NoiseVariance: 0.9899
InputDelay: [3x1 double]
Algorithm: [1x1 struct]
EstimationInfo: [1x1 struct]
Notes: {}
UserData: []
3-70
Identifying Input-Output Polynomial Models
m_armax.Algorithm
This action displays the complete list of Algorithm properties and values
that specify the iterative computational algorithm:
ans =
Focus: 'Simulation'
MaxIter: 50
Tolerance: 1.0000e-005
LimitError: 0
MaxSize: 'Auto'
SearchMethod: 'Auto'
Criterion: 'det'
Weighting: 1
FixedParameter: []
Display: 'Off'
N4Weight: 'Auto'
N4Horizon: 'Auto'
Advanced: [1x1 struct]
3-71
3 Linear Model Identification
m_armax.EstimationInfo
ans =
6 If you want to repeat the model estimation using different model orders,
but keep the algorithm properties the same, you can store the model
properties used for m_armax in a variable, as follows:
myAlg=m_armax.Algorithm;
This action stores the specified focus, tolerance, and maxiter, and the
default algorithm.
m_armax2=armax(z8,[4 3 2 3 3 1 1 1],...
'algorithm',myAlg);
3-72
Identifying State-Space Models
3-73
3 Linear Model Identification
The state-space model structure is a good choice for quick estimation because
it requires only two parameters:
The model order for state-space models is an integer equal to the dimension
of x(t) and relates to the number of delayed inputs and outputs used in the
corresponding linear difference equation.
Continuous-Time Representation
In continuous-time, the state-space description has the following form:
(t)
x (t) = Fx(t) + Gu(t) + Kw
y(t) = Hx(t) + Du(t) + w(t)
x(0) = x0
3-74
Identifying State-Space Models
Discrete-Time Representation
Discrete-time state-space models provide the same type of linear difference
relationship between the inputs and the outputs as the linear ARX model, but
are rearranged such that there is only one delay in the expressions. The
discrete-time state-space model structure is often written in the innovations
form that describes noise:
where T is the sampling interval, u(kT) is the input at time instant kT, and
y(kT) is the output at time instant kT.
A = e FT
T
Fτ
B= ∫e Gdτ
0
C=H
3-75
3 Linear Model Identification
T
Fτ τ
K= ∫e Kd
0
y = Gu + He
where T is the sampling interval, u(kT) is the input at time instant kT, and
y(kT) is the output at time instant kT.
where Inx is the nx-by-nx identity matrix, Iny is the nx-by-nx identity matrix,
and ny is the dimension of y and e.
3-76
Identifying State-Space Models
You must first import your data into the MATLAB workspace, as described in
Chapter 2, “Data Import and Processing”.
3-77
3 Linear Model Identification
You must specify your data to have the sampling interval equal to the
experimental data sampling interval.
You can set the sampling interval when you import data into the GUI or set
the Ts property of the data object at the command line.
3-78
Identifying State-Space Models
To get an initial model order for your system, you can estimate a group of
state-space models with a range of orders for a specific delay and compare the
performance of these models. You choose the model order that include states
with the highest contribution to the input-output behavior of the model and
use this order as an initial guess for further modeling.
3-79
3 Linear Model Identification
3 Edit the Orders field to specify a range of orders for a specific delay. For
example, enter the following values for n and nk:
1:10 [1]
3-80
Identifying State-Space Models
6 Select the rectangle that represents the cutoff for the states on the left that
provide a significant contribution to the input-output behavior, and click
Insert to estimate a model with this order. Red indicates the recommended
choice. States 1 and 2 provide the most significant contribution. The
contributions to the right of state 2 drop significantly. For information
about using the Model Order Selection window, see “Using the Model Order
Selection Window” on page 3-83.
This action adds a new model to the Model Board in the System
Identification Tool GUI. The default name of the parametric model
combines the string n4s and the selected model order.
3-81
3 Linear Model Identification
After estimating model orders, use this value as an initial guess for estimating
other state-space models, as described in “How to Estimate State-Space
Models in the GUI” on page 3-84.
Use following syntax to specify the range of model orders to try for a specific
input delay.
m = n4sid(data,n1:n2,'nk',nk);
where data is the estimation data set, n1 and n2 specify the range of orders,
and nk specifies the input delay. For multiple-input systems, nk is a vector
of input delays.
This command opens the Model Order Selection window. For information
about using this plot, see “Using the Model Order Selection Window” on page
3-83.
Alternatively, you can use the pem command to open the Model Order
Selection window, as follows:
m = pem(Data,'nx',nn)
To omit opening the Model Order Selection window and automatically select
the best order, use the following syntax:
m = pem(Data,'best')
3-82
Identifying State-Space Models
The horizontal axis corresponds to the model order n. The vertical axis, called
Log of Singular values, shows the singular values of a covariance matrix
constructed from the observed data.
You use this plot to decide which states provide a significant relative
contribution to the input-output behavior, and which states provide the
3-83
3 Linear Model Identification
smallest contribution. Based on this plot, select the rectangle that represents
the cutoff for the states on the left that provide a significant contribution to
the input-output behavior. The recommended choice is red.
For example, in the previous figure, states 1 and 2 provide the most significant
contribution. However, the contributions of the states to the right of state 2
drop significantly. This sharp decrease in the log of the singular values after
n=2 indicates that using two states is sufficient to get an accurate model.
Prerequisites
Before you can perform this task, you must have
• Imported data into the System Identification Tool GUI. See “Importing
Time-Domain Data into the GUI” on page 2-16. For supported data
formats, see “Data Supported by State-Space Models” on page 3-77.
• Performed any required data preprocessing operations. To improve the
accuracy of your model, you should detrend your data. See “Ways to
Process Data for System Identification” on page 2-4.
3-84
Identifying State-Space Models
• Select a model order. For more information about how to estimate model
orders, see “Preliminary Step – Estimating State-Space Model Orders”
on page 3-79.
This action updates the options in the Linear Parametric Models dialog box
to correspond with this model structure. For information about each model
structure, see “What Are State-Space Models?” on page 3-73.
3 In the Orders field, specify the model order and delay, as follows:
• For single-input models. Enter the model order integer and the input
delay in terms of the number of samples. Omitting nk uses the default
value nk=1.
For example, enter 4 [2] for a fourth-order model and nk=2.
• For multiple-input models. Enter the model order integer and the
input delay vector—which is a 1-by-nu vector whose ith entry is the
delay for the ith input.
For example, for a two-input system, enter 4 [1 1] for a fourth-order
model and a delay of 1 for each input.
• For multiple-output models. Enter the model order integer the same
way as for single-input models.
Tip To enter model order and any delays using the Order Editor dialog
box, click Order Editor.
3-85
3 Linear Model Identification
5 In the Name field, edit the name of the model or keep the default. The
name of the model should be unique in the Model Board.
6 In the Focus list, select how to weigh the relative importance of the fit at
different frequencies. For more information about each option, see “Options
for Frequency-Weighing Focus” on page 3-101.
7 (PEM only) In the Initial state list, specify how you want the algorithm to
treat initial states. For more information about the available options, see
“Options for Initial States” on page 3-102.
Tip If you get an inaccurate fit, try setting a specific method for handling
initial states rather than choosing it automatically.
3-86
Identifying State-Space Models
10 Click Estimate to add this model to the System Identification Tool GUI.
11 (PEM only) To stop the search and save the results after the current
iteration has been completed, click Stop Iterations. To continue iterations
from the current model, click the Continue iter button to assign current
parameter values as initial guesses for the next search.
Next Steps
• Validate the model by selecting the appropriate check box in the Model
Views area of the System Identification Tool GUI. For more information
about validating models, see “Overview of Model Validation and Plots”
on page 8-2.
• Export the model to the MATLAB workspace for further analysis by
dragging it to the To Workspace rectangle in the System Identification
Tool GUI.
Prerequisites
Before you can perform this task, you must have
3-87
3 Linear Model Identification
Use the following general syntax to both configure and estimate state-space
models:
m = pem(data,n,
'nk',nk,
'Property1',Value1,...,
'PropertyN',ValueN)
where data is the estimation data, n is the model order, and nk specifies the
input delays for each input.
m = n4sid(data,n,
'nk',nk,
'Property1',Value1,...,
'PropertyN',ValueN)
Note pem uses n4sid to initialize the state-space matrices, and takes longer
than n4sid to estimate a model but typically provides better fit to data.
3-88
Identifying State-Space Models
For more information about the most common property-value pairs you can
specify, see “Common Properties to Specify Model Estimation” on page 3-89.
For detailed information about the syntax, see the corresponding reference
page.
For more information about estimating model order, see “Estimating the
Model Order at the Command Line” on page 3-82.
For more information about these properties, see the idss reference page.
3-89
3 Linear Model Identification
For state-space models with structured parameterization, you can also specify
to estimate the D matrix. However, for free and canonical forms, the structure
of the D matrix is set based on your choice of nk.
For more information about state-space structure, see “What Are State-Space
Models?” on page 3-73.
D Matrix. By default, the D matrix is not estimated. Set the model property
nk to estimate the D matrix, as follows:
m = pem(Data,n,'nk',[0 0])
To modify whether K is estimated for time-domain data, you can specify the
DisturbanceModel property in the estimator syntax.
3-90
Identifying State-Space Models
m = pem(Data,md,'DisturbanceModel','Estimate')
m = pem(Data,n,'DisturbanceModel','None')
To specify how to handle the initial states, set the value of the InitialStates
model property. For example, to set the initial states to zero, set the
InitialStates property to 'zero', as follows:
m = pem(Data,n,'InitialStates','zero')
For a complete list of values for the InitialStates property, see “Options for
Initial States” on page 3-102.
3-91
3 Linear Model Identification
To estimate the disturbance model K, you must use time domain data.
Suppose that you have no knowledge about the internal structure of the
discrete-time state-space model. To quickly get started, use the following
syntax:
m = pem(data)
m = pem(Data,n)
The iterative algorithm pem is initialized by the subspace method n4sid. You
can use n4sid directly, as an alternative to pem:
m = n4sid(Data,n)
3-92
Identifying State-Space Models
m = pem(data,n,'SSparameterization','canonical')
Note When you estimate the D matrix in canonical form, you must set the nk
property. See “Choosing to Estimate D, K, and X0 Matrices” on page 3-90.
m = pem(data,n,'SSparameterization','canonical',
'nk',0)
3-93
3 Linear Model Identification
2 Using the pem estimation command to estimate the free model parameters
This approach differs from estimating models with free and canonical
parameterizations, where it is not necessary to specify initial parameter
values before the estimation. For free parameterization, there is no
structure to specify because it is assumed to be unknown. For canonical
parameterization, the structure is fixed to a specific form.
3-94
Identifying State-Space Models
m = idss(A,B,C,D,K,X0,...
'Ts',T,...
'SSparameterization','structured')
where A, B, C, D, and K specify both the fixed parameter values and the
initial values for the free parameters. T is the sampling interval. Setting
SSparameterization to 'structured' flags that you want to estimate a
partial structure for this state-space model.
m = idss(A,B,C,D,K,X0,...
'Ts',0,...
'SSparameterization','structured')
In the continuous-time case, you must set the sampling interval property Ts
to zero.
After you create the nominal model structure, you must specify which
parameters to estimate and which to set to specific values. To accomplish this,
you must edit the structures of the following model properties: As, Bs, Cs, Ds,
Ks, and x0s. These structure matrices are properties of the nominal model
you constructed and have the same sizes as A, B, C, D, K, and x0, respectively.
Initially, the structure matrices contain NaN values.
3-95
3 Linear Model Identification
A = [2 0; 0 3]
The iterative search computes gradients of the prediction errors with respect
to the parameters using numerical differentiation. The step size is specified
by the nuderst command. The default step size is equal to 10–4 times the
absolute value of a parameter or equal to 10–7, whichever is larger. To specify
a different step size, edit the nuderst code file.
3-96
Identifying State-Space Models
⎡1 θ1 ⎤ ⎡ θ2 ⎤ ⎡ θ4 ⎤
x(t + 1) = ⎢ ⎥ x(t) + ⎢ ⎥ u(t) + ⎢ ⎥ e(t)
⎣0 1 ⎦ ⎣ θ3 ⎦ ⎣ θ5 ⎦
y(t) = [1 0] x(t) + e(t)
⎡0 ⎤
x(0) = ⎢ ⎥
⎣0 ⎦
A = [1,-1;0,1];
B = [2;3];
C = [1,0];
D = 0;
K = [4;5];
m = idss(A,B,C,D,K);
3-97
3 Linear Model Identification
3 Specify the parameter values in the structure matrices that you do not
want to estimate:
m = pem(data,m)
⎡0 1 ⎤ ⎡0⎤
x (t) = ⎢ ⎥ x(t) + ⎢θ ⎥ u(t)
⎣ 0 θ 1⎦ ⎣ 2⎦
⎡1 0 ⎤
y(t) = ⎢ ⎥ x(t) + e(t)
⎣0 1 ⎦
⎡ θ3 ⎤
x(0) = ⎢ ⎥
⎣0⎦
The parameter −θ1 is the inverse time constant of the motor, and − θ2 θ is the
1
static gain from the input to the angular velocity.
3-98
Identifying State-Space Models
The motor is at rest at t=0, but its angular position θ3 is unknown. Suppose
that the approximate nominal values of the unknown parameters are θ1 = −1
and θ2 = 0.25 . The variance of the errors in the position measurement is
0.01, and the variance in the angular velocity measurements is 0.1. For
more information about this example, see the section on state-space models
in System Identification: Theory for the User, Second Edition, by Lennart
Ljung, Prentice Hall PTR, 1999.
(t)
x (t) = Fx(t) + Gu(t) + Kw
y(t) = Hx(t) + Du(t) + w(t)
x(0) = x0
A = [0 1;0 -1];
B = [0;0.25];
C = eye(2);
D = [0;0];
K = zeros(2,2);
x0 = [0;0];
m = idss(A,B,C,D,K,x0,'Ts',0);
3-99
3 Linear Model Identification
3 Specify the parameter values in the structure matrices that you do not
want to estimate:
m = pem(data,m)
5 To simulate this system using the sampling interval T = 0.1 for input u
and the noise realization e, use the following commands:
e = randn(300,2);
u = idinput(300);
simdat = iddata([],[u e],'Ts',0.1);
y = sim(m,simdat)
If you discover that the motor was not initially at rest, you can estimate x2(0)
by setting the second element of the x0s structure matrix to NaN, as follows:
m_new = pem(data,m,'x0s',[NaN;NaN])
3-100
Identifying State-Space Models
case, specify to estimate the K matrix for the state-space model. For the OE
case, set K = 0.
Tip You can use a state-space model with K = 0 (Output-Error (OE) form)
for initializing a Hammerstein-Wiener estimation at the command line. This
initialization may improve the fit of the model. See “Using Linear Model for
Hammerstein-Wiener Estimation” on page 4-64.
In the System Identification Tool GUI. Set Focus to one of the following
options:
• Prediction — Uses the inverse of the noise model H to weigh the relative
importance of how closely to fit the data in various frequency ranges.
Corresponds to minimizing one-step-ahead prediction, which typically
favors the fit over a short time interval. Optimized for output prediction
applications.
• Simulation — Uses the input spectrum to weigh the relative importance of
the fit in a specific frequency range. Does not use the noise model to weigh
the relative importance of how closely to fit the data in various frequency
ranges. Optimized for output simulation applications.
• Stability — Estimates the best stable model. For more information about
model stability, see “Unstable Models” on page 8-66.
• Filter — Specify a custom filter to open the Estimation Focus dialog box,
where you can enter a filter, as described in “Simple Passband Filter” on
page 2-113 or “Defining a Custom Filter” on page 2-114. This prefiltering
3-101
3 Linear Model Identification
applies only for estimating the dynamics from input to output. The
disturbance model is determined from the estimation data.
pem(data,4,'Focus',[5 8])
In the System Identification Tool GUI. Set Initial state to one of the
following options:
m=pem(data,4,'InitialState','estimate')
For a complete list of values for the InitialState model property, see the
idss reference page.
3-102
Identifying State-Space Models
N4SID is faster than PEM, but is typically less accurate and robust, and
requires additional arguments that might be difficult to specify.
3-103
3 Linear Model Identification
In the first situation, you have already estimated a parametric model and
wish to refine the model. However, if your model captures the essential
dynamics, it is usually not necessary to continue improving the fit—especially
when the improvement is a fraction of a percent.
In the second situation, you might have constructed a model using one of
the model constructors described in “Commands for Constructing Model
Structures” on page 1-16. In this case, you built initial parameter guesses into
the model structure and wish to refine these parameter values.
• Parametric model
• Data — You can either use the same data set for refining the model as the
one you originally used to estimate the model, or you can use a different
data set.
3-104
Refining Linear Parametric Models
1 In the System Identification Tool GUI, verify that you have the correct data
set in the Working Data area for refining your model.
If you are using a different data set than the one you used to estimate the
model, drag the correct data set into the Working Data area. For more
information about specifying estimation data, see “Specifying Estimation
and Validation Data” on page 2-31.
3 In the Linear Parametric Models dialog box, select By Initial Model from
the Structure list.
4 Enter the model name into the Initial model field, and press Enter.
The model name must be in the Model Board of the System Identification
Tool GUI or a variable in the MATLAB workspace.
Tip As a shortcut for specifying a model in the Model Board, you can drag
the model icon from the System Identification Tool GUI into the Initial
model field.
When you enter the model name, algorithm settings in the Linear
Parametric Models dialog box override the initial model settings.
3-105
3 Linear Model Identification
m = pem(data,init_model)
pem uses the properties of the initial model unless you specify different
properties. For more information about specifying model properties directly in
the estimator, see “Specifying Model Properties for Estimation” on page 1-19.
3-106
Refining Linear Parametric Models
load iddata8
3-107
3 Linear Model Identification
In this case, you must first create a model object and set the initial parameter
values in the model properties. Next, you provide this initial model as input
to pem, which refines the initial parameter guesses using the data.
load iddata8
% Define model parameters.
% Leading zeros in B indicate input delay (nk),
% which is 1 for each input channel.
A = [1 -1.2 0.7];
B{1} = [0 1 0.5 0.1]; % first input
B{2} = [0 1.5 -0.5]; % second input
B{3} = [0 -0.1 0.5 -0.1]; % third input
C = [1 0 0 0 0];
Ts = 1;
3-108
Extracting Parameter Values from Linear Models
You can operate on extracted model data as you would on any other MATLAB
vectors, matrices and cell arrays. You can also pass these numerical values to
Control System Toolbox commands, for example, or Simulink blocks.
You can use dot notation to access model properties. For example, m.A
displays the A polynomial coefficients from model m. Alternatively, you can
use the get command, as follows: get(m,'A').
[G,dG] = command(model)
3-109
3 Linear Model Identification
3-110
Extracting Dynamic Model and Noise Model Separately
For linear models, the general symbolic model description is given by:
y = Gu + He
G is an operator that takes the measured inputs u to the outputs and captures
the system dynamics. H is an operator that describes the properties of the
additive output disturbance and takes the hypothetical (unmeasured) noise
source inputs e to the outputs, also called the noise model. When you estimate
a noise model, the toolbox includes one noise channel e at the input for each
output in your system.
The following table summarizes the results of ssdata, tfdata, and zpkdata
commands for extracting the numerical values of the dynamic model and
noise model separately. fcn represents ssdata, tfdata, and zpkdata, and
m is a model object. L represents the covariance matrix e, as defined in
“Subreferencing Measured and Noise Models” on page 3-121.
Command Syntax
fcn(m) Returns the properties of G for ny outputs and nu inputs.
fcn(m('noise')) Returns the properties of H for ny outputs and ny inputs.
fcn(noisecnv(m)) Returns the properties of [G H] ny outputs and ny+nu
inputs.
3-111
3 Linear Model Identification
Command Syntax
fcn(noisecnv(m,'Norm')) Returns the properties of [G HL] ny outputs and ny+nu
inputs.
fcn(noisecnv(m('noise'),'Norm')) Returns the properties of HL ny outputs and ny inputs.
fcn(m) If m is a time-series model, returns the properties of H.
fcn(noisecnv(m,'Norm')) If m is a time-series model, returns the properties of HL.
3-112
Transforming Between Discrete-Time and Continuous-Time Representations
3-113
3 Linear Model Identification
Note c2d and d2d correctly approximate the transformation of the noise
model when the sampling interval T is small compared to the bandwidth
of the noise.
mod_d = c2d(mod_c,T)
mod_c = d2c(mod_d)
d2d Resample a linear To resample a discrete-time
discrete-time model mod_d1 to a discrete-time
model and produce form with a new sampling
an equivalent interval Ts, use the following
discrete-time model command:
with a new sampling
interval. mod_d2 = d2d(mod_d1,Ts)
You can use the
resampled model to
simulate or predict
output with a specified
time interval.
3-114
Transforming Between Discrete-Time and Continuous-Time Representations
By default, c2d and d2c use the intersample behavior you assigned to the
estimation data. To override this setting during transformation, add an extra
argument in the syntax. For example:
3-115
3 Linear Model Identification
( )
2
Φ v (ω) = λT H eiωT
where λ is the variance of the white noise e(t), and λT represents the spectral
density of e(t). Resampling the noise model preserves the spectral density λ T
. The spectral density λ T is invariant up to the Nyquist frequency. For more
information about spectrum normalization, see “Spectrum Normalization”
on page 3-8.
d2d resampling of the noise model affects simulations with noise using
sim. If you resample a model to a faster sampling rate, simulating this
model results in higher noise level. This higher noise level results from the
3-116
Transforming Between Discrete-Time and Continuous-Time Representations
the noise signal, scale the noise spectrum by TNew T , where Tnew is the new
Old
sampling interval and Told is the original sampling interval. before applying
sim.
length(C)-1 = (length(A)-1)+(length(D)-1)
3-117
3 Linear Model Identification
If you used the System Identification Tool GUI to estimate models, you must
export the models to the MATLAB workspace before converting models.
For detailed information about each command in the following table, see the
corresponding reference page.
m_f = idfrd(m,f)
m_f = idfrd(m(2,3))
idpoly Converts single-output To get an ARMAX model from state-space
idmodel object to ARMAX model m_ss, use the following command:
representation.
If you have the Control m_p = idpoly(m_ss)
System Toolbox product,
this command converts any
single-output LTI object
except frd.
3-118
Transforming Between Linear Model Representations
length(C)-1 = (length(A)-1)+(length(D)-1)
3-119
3 Linear Model Identification
What Is Subreferencing?
You can use subreferencing to create models with subsets of inputs and
outputs from existing multivariable models. Subreferencing is also useful
when you want to generate model plots for only certain channels, such as
when you are exploring multiple-output models for input channels that have
minimal effect on the output.
model(outputs,inputs)
In this syntax, outputs and inputs specify channel indexes or channel names.
3-120
Subreferencing Model Objects
To select all output or all input channels, use a colon (:). To select no
channels, specify an empty matrix ([]). If you need to reference several
channel names, use a cell array of strings.
For example, to create a new model m2 from m from inputs 1 ('power') and
4 ('speed') to output number 3 ('position'), use either of the following
equivalent commands:
m2 = m('position',{'power','speed'})
or
m2 = m(3,[1 4])
For a single-output model, you can use the following syntax to subreference
specific input channels without ambiguity:
m3 = m(inputs)
Similarly, for a single-input model, you can use the following syntax to
subreference specific output channels:
m4 = m(outputs)
y = Gu + He
G is an operator that takes the measured inputs u to the outputs and captures
the system dynamics.
3-121
3 Linear Model Identification
or
B(q) 1
y(t) = u(t) + e(t)
A(q) A(q)
In this case, the dynamic model is the relationship between the measured
Suppose that the model m contains both a dynamic model G and a noise model
H. To create a new model by subreferencing G due to measured inputs, use
the following syntax:
m_G = m('measured')
Tip Alternatively, you can use the following shorthand syntax: m_G = m('m')
3-122
Subreferencing Model Objects
m_H = m('noise')
Tip Alternatively, you can use the following shorthand syntax: m_H = m('n')
Λ = LLT
e = Lv
where v is white noise with an identity covariance matrix representing
independent noise sources with unit variances.
m_GH = noisecnv(m)
This operation creates a model m_GH that represents both measured inputs u
and noise inputs e, treating both sources as measured signals. m_GH is a model
from u and e to y, describing the transfer functions G and H.
3-123
3 Linear Model Identification
e = Lv
m_GH = noisecnv(m,'Norm')
⎡u ⎤
y(t) = Gu(t) + HLv = [ G HL] ⎢ ⎥
⎣v⎦
For example, the scaling by L causes the step responses from v to y to reflect
the size of the disturbance influence.
The converted noise sources are named in a way that relates the noise channel
to the corresponding output. Unnormalized noise sources e are assigned
names such as 'e@y1', 'e@y2', ..., 'e@yn', where 'e@yn' refers to the noise
input associated with the output yn. Similarly, normalized noise sources v,
are named 'v@y1', 'v@y2', ..., 'v@yn'.
Note When you plot models in the GUI that include noise sources, you
can select to view the response of the noise model corresponding to specific
outputs. For more information, see “Selecting Measured and Noise Channels
in Plots” on page 11-18.
3-124
Concatenating Model Objects
You can also concatenate nonparametric models, which contain the estimated
impulse-response (idarx object) and frequency-response (idfrd object) of a
system.
3-125
3 Linear Model Identification
The following syntax creates a new model object m that contains the horizontal
concatenation of m1,m2,...,mN:
m = [m1,m2,...,mN]
u1 y1 y1
Model 1 u3 Model 2
u2 y2 y2
u1 y1
Combined Horizonal Concatenation Same
Inputs u2 of Model 1 and Model 2 Outputs
y2
u3
3-126
Concatenating Model Objects
Note You cannot concatenate the single-output idproc and idpoly model
objects.
The following syntax creates a new model object m that contains the vertical
concatenation of m1,m2,...,mN:
m = [m1;m2;... ;mN]
m takes the same inputs in the original models to all of the output of
m1,m2,...,mN. The following diagram is a graphical representation of vertical
concatenation of frequency-response data.
u1 y1 u1
Model 1 Model 2 y3
u2 y2 u2
u1 y1
Same Vertical Concatenation y2 Combined
Inputs u2 of Model 1 and Model 2 Outputs
y3
However, when the idfrd objects are spectral models that you estimated, the
SpectrumData property is not empty and contains the power spectra and
cross spectra of the output noise in the system. For each output channel, this
toolbox estimates one noise channel to explain the difference between the
output of the model and the measured output.
3-127
3 Linear Model Identification
⎛ m1.s
⎜ 0 ⎞⎟
m.s = ⎜ ⎟
⎜⎜ ⎟
⎝ 0 mN .s ⎟⎠
See Also
If you have the Control System Toolbox product, see “Combining Model
Objects” on page 9-6 about additional functionality for combining models.
3-128
Merging Model Objects
You can perform the merge operation for the idarx, idgrey, idpoly, idproc,
and idss model objects.
Note Each merge operation merges the same type of model object.
When the experimental conditions are about the same, merge the data
instead of models. This approach is more efficient and typically involves
better-conditioned calculations. For more information about merging data
sets into a multiexperiment data set, see “Creating Multiexperiment Data at
the Command Line” on page 2-55.
For more information about merging models, see the merge reference page.
3-129
3 Linear Model Identification
3-130
4
Here are some scenarios when you might need the additional flexibility of
nonlinear models:
4-2
About Nonlinear Model Identification
If you know the nonlinear equations describing a system, you can represent
this system as a nonlinear grey-box model and estimate the coefficients from
experimental data. In this case, the coefficients are the parameters of the
model. For more information, see Chapter 5, “ODE Parameter Estimation
(Grey-Box Modeling)”.
4-3
4 Nonlinear Black-Box Model Identification
Before fitting a nonlinear model, try transforming your input and output
variables such that the relationship between the transformed variables is
linear. For example, you might be dealing with a system that has current and
voltage as inputs to an immersion heater, and the temperature of the heated
liquid as an output. In this case, the output depends on the inputs via the
power of the heater, which is equal to the product of current and voltage.
Instead of fitting a nonlinear model to two-input and one-output data, you can
create a new input variable by taking the product of current and voltage and
then fitting a linear model to the single-input/single-output data.
y(t) = f(y(t - 1), ..., y(t - na), u(t - nk), ..., u(t -nk -nb + 1))
4-4
About Nonlinear Model Identification
output. nk is the delay from the input to the output, specified as the number
of samples.
Hammerstein-Wiener Models
Hammerstein-Wiener models describe dynamic systems using one or two
static nonlinear blocks in series with a linear block. The linear block is a
discrete transfer function and represents the dynamic component of the model.
x ( t ) = F ( x ( t ) , u ( t ) )
y ( t ) = H ( x ( t ) , u ( t ))
4-5
4 Nonlinear Black-Box Model Identification
where F and H can have any parameterization. You use the idnlgrey object
to specify the structures of such models as nonlinear ODEs, based on physical
insight about your system. The parameters of such models typically have
physical interpretations.
4-6
Preparing Data for Nonlinear Identification
For time-series data, you can only fit nonlinear ARX models and nonlinear
state-space models.
Tip Whenever possible, use different data sets for model estimation and
validation.
Before estimating models, import your data into the MATLAB workspace
and do one of the following:
• In the System Identification Tool GUI. Import data into the GUI, as
described in “Importing Data into the GUI” on page 2-14.
• At the command line. Represent your data as an iddata object, as
described in the corresponding reference page.
You can analyze data quality and preprocess data by interpolating missing
values, filtering to emphasize a specific frequency range, or resampling using
a different time interval (see “Ways to Process Data for System Identification”
on page 2-4).
Data detrending can be useful in certain cases, such as before modeling the
relationship between the change in input and the change in output about an
operating point. However, most applications do not require you to remove
offsets and linear trends from the data before nonlinear modeling.
4-7
4 Nonlinear Black-Box Model Identification
This structure implies that the current output y(t) is predicted as a weighted
sum of past output values and current and past input values. Rewriting the
equation as a product:
[ y(t − 1), y(t − 2),..., y(t − na), u(t), u(t − 1),..., u(t − nb − 1)]T
4-8
Identifying Nonlinear ARX Models
where y(t − 1), y(t − 2),..., y(t − na), u(t), u(t − 1),..., u(t − nb − 1) are delayed input
and output variables, called regressors. The linear ARX model predicts the
current output yp as a weighted sum of its regressors.
y p (t) = f ( y(t − 1), y(t − 2), y(t − 3),..., u(t), u(t − 1), u(t − 2),..)
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.
4-9
4 Nonlinear Black-Box Model Identification
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
regressors, which are nonlinear functions of delayed inputs and outputs.
For example, tan(u(t-1)) or u(t-1)*y(t-3).
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-10
Identifying Nonlinear ARX Models
( )
−1
where (s) = es + 1 is the sigmoid
function. βk is a row vector such that
βk ( x − γ k ) is a scalar.
4-11
4 Nonlinear Black-Box Model Identification
4-12
Identifying Nonlinear ARX Models
• Specifying model order and delay, which creates the set of standard
regressors.
For a definition, see “Nonlinear ARX Order and Delay” on page 4-14.
• Creating custom regressors.
Custom regressors are arbitrary functions of past inputs and outputs, such
as products, powers, and other MATLAB expressions of input and output
variables. You can specify custom regressors in addition to or instead of
standard regressors for greater flexibility in modeling your data.
• Including a subset of regressors in the nonlinear function of the nonlinear
estimator block.
Selecting which regressors are inputs to the nonlinear function reduces
model complexity and keeps the estimation well-conditioned.
• Initializing using a linear ARX model.
You can perform this operation only at the command line. The initialization
configures the nonlinear ARX model to use standard regressors, which the
toolbox computes using the orders and delays of the linear model. See
“Using Linear Model for Nonlinear ARX Estimation” on page 4-28.
4-13
4 Nonlinear Black-Box Model Identification
Note You cannot exclude the linear function from tree partitions and
neural networks.
See these topics for detailed steps to change the model structure:
• Specifying only model order and input delay. Specifying the order
automatically creates standard regressors.
• Specifying a linear ARX model. The linear model sets the model orders and
linear function of the nonlinear model. You can perform this operation
only at the command line.
By default:
4-14
Identifying Nonlinear ARX Models
The meaning of na, nb, and nk is similar to linear ARX model parameters.
Orders are scalars for SISO data, and matrices for MIMO data. If you are not
sure how to specify the order and delay, you can estimate them as described
in “Preliminary Step – Estimating Model Orders and Input Delays” on page
3-48. Such an estimate is based on linear ARX models and only provides
initial guidance—the best orders for a linear ARX model might not be the best
orders for a nonlinear ARX model.
For example, if you specify this order and delay for a SISO model with input
u and output y:
the toolbox computes standard regressors y(t-2), y(t-1), u(t-5), u(t-6), and u(t-7).
4-15
4 Nonlinear Black-Box Model Identification
2 In the Configure tab, select Nonlinear ARX from the Model type list (if
it is not already selected).
3 (Optional) Edit the Model name by clicking the pencil icon. The name of
the model should be unique to all nonlinear ARX models in the System
Identification Tool GUI.
4-16
Identifying Nonlinear ARX Models
5 Keep the default settings in the Nonlinear Models dialog box that specify
the model structure and the algorithm, or modify these settings:
Note For more information about available options, click Help in the
Nonlinear Models dialog box to open the GUI help.
4-17
4 Nonlinear Black-Box Model Identification
6 Click Estimate to add this model to the System Identification Tool GUI.
7 Validate the model response by selecting the desired plot in the Model
Views area of the System Identification Tool GUI. For more information
about validating models, see “How to Plot Nonlinear ARX Plots Using the
GUI” on page 4-35.
If you get a poor fit, try changing the model structure or algorithm
configuration in step 5.
4-18
Identifying Nonlinear ARX Models
Use nlarx to both construct and estimate a nonlinear ARX model. After
each estimation, validate the model by comparing it to other models and
simulating or predicting the model response.
Basic Estimation
By default, the nonlinearity estimator is the wavelet network (see the wavenet
reference page), which takes all standard regressors as inputs to its linear
and nonlinear functions. m is an idnlarx object.
For MIMO systems, nb, nf, and nk are ny-by-nu matrices. See the nlarx
reference page for more information about MIMO estimation.
4-19
4 Nonlinear Black-Box Model Identification
M = nlarx(data,[2 2 1],'sigmoid')
Set the Focus property of the idnlarx object estimation to simulation error
minimization:
M = nlarx(data,[2 2 1],'sigmoid','Focus','simulation')
Standard Regressors
Change the model order to create a model structure with different model
regressors, which are delayed input and output variables that are inputs to
the nonlinearity estimator.
Custom Regressors
load iddata1
m = nlarx(z1,[2 2 1],'sigmoidnet');
getreg(m) % displays all regressors
% Generate polynomial regressors up to order 2:
reg = polyreg(m)
% Append polynomial regressors to CustomRegressors:
m = addreg(m,reg);
getreg(m) % now includes polynomial regressors
4-20
Identifying Nonlinear ARX Models
You can also specify arbitrary functions of input and output variables. For
example:
load iddata1
m = nlarx(z1,[2 2 1],'sigmoidnet',...
'CustomReg',{'y1(t-1)^2','y1(t-2)*u1(t-3)'});
getreg(m) % displays all regressors
% Append polynomial regressors to CustomRegressors:
m = addreg(m,reg);
getreg(m) % polynomial regressors
CReg1 = m.CustomReg(1).Function;
m.CustomReg(1).Display
You can exclude all standard regressors and use only custom regressors in the
model structure by setting na=nb=nk=0:
m = nlarx(data,[0 0 0],'CustomReg',{'y1(t-1)^2','y1(t-2)*u1(t-3)'})
By default, all model regressors enter as inputs to both linear and nonlinear
function blocks of the nonlinearity estimator. To reduce model complexity and
keep the estimation well-conditioned, use a subset of regressors as inputs to
the nonlinear function of the nonlinear estimator block.
4-21
4 Nonlinear Black-Box Model Identification
This example uses getreg to determine the index of each regressor from
the complete list of all model regressors. Only regressor numbers 5 through
8 are inputs to the nonlinear function—getreg shows that these regressors
are functions of the input variable u1. nlreg is an abbreviation for the
NonlinearRegressors property of the idnlarx class.
m = nlarx(data,[4 4 1],sigmoidnet,'nlreg','input')
When you are not sure which regressors to include as inputs to the nonlinear
function block, specify to search during estimation for the optimum regressor
combination:
m = nlarx(data,[4 4 1],sigmoidnet,'nlreg','search')
m = nlarx(data,[4 4 1],sigmoidnet,'nlreg','search',...
'Display', 'on')
m = nlarx(data, [2 2 1],'sigmoidnet')
or
• Nonlinearity object.
4-22
Identifying Nonlinear ARX Models
m = nlarx(data,[2 2 1],wavenet('num',5))
w = wavenet('num', 5);
m = nlarx(data,[2 2 1],w)
or
w = wavenet;
w.NumberOfUnits = 5;
m = nlarx(data,[2 2 1],w)
For MIMO systems, you can specify a different nonlinearity for each output.
For example, to specify sigmoidnet for the first output and wavenet for the
second output:
If you want the same nonlinearity for all output channels, specify one
nonlinearity.
4-23
4 Nonlinear Black-Box Model Identification
m = nlarx(data,[na nb nk],NNet)
where NNet is the neural network object you create using the Neural Network
Toolbox software. See the neuralnet reference page.
CNetw = cutomnet(@gaussunit);
m = nlarx(data,[na nb nk],CNetw)
Nonlinearity Estimator
u
Regressors Nonlinear y
u(t),u(t-1),y(t-1), ... Function
For example:
SNL = sigmoidnet('LinearTerm','off'')
m = nlarx(data,[2 2 1],SNL);
Note You cannot exclude the linear function from tree partition and neural
network nonlinearity estimators.
4-24
Identifying Nonlinear ARX Models
Configure the nonlinear ARX structure to include only the linear function in
the nonlinearity estimator by setting the nonlinearity to linear. In this case,
F(x)= LT ( x) + d is a weighted sum of model regressors plus an offset. Such
models provide a bridge between purely linear ARX models and fully flexible
nonlinear models.
Nonlinearity Estimator
u
Regressors Linear y
u(t),u(t-1),y(t-1), ... Function
In the simplest case, a model with only standard regressors is linear (affine).
For example, this structure:
m = nlarx(data,[na nb nk],'linear');
However, the nonlinear ARX model m is more flexible than the linear ARX
model lin_m because it contains the offset term, d. This offset term provides
the additional flexibility of capturing signal offsets, which is not available
in linear models.
For example, suppose that you know the output y(t) of a system to be a linear
combination of (y(t − 1))2 and y(t − 2)*u(t − 3). To model such as system, use:
4-25
4 Nonlinear Black-Box Model Identification
M = nlarx(data,[0 0 0],'linear',...
'CustomReg',{'y1(t-1)^2','y1(t-2)*u1(t-3)'})
m = nlarx(data,[2 2 1],'sigmoidnet')
m2 = pem(data,m)
m1 = nlarx(data, [2 2 1],'sigmoidnet','wavenet');
m2 = nlarx(data,m1) % can repeatedly run this command
4-26
Identifying Nonlinear ARX Models
You can display the progress of the iterative search in the MATLAB Command
Window using the Display property of the idnlarx class:
M2= pem(data,M1p,'Display','On')
If you do not get a satisfactory model after many trials with various model
structures and algorithm settings, it is possible that the data is poor. For
example, your data might be missing important input or output variables and
does not sufficiently cover all the operating points of the system.
load twotankdata
z = iddata(y, u, 0.2);
ze = z(1:1000); zv = z(1001:3000);
m1 = nlarx(ze,[2 2 1]);
m2 = nlarx(ze,[2 2 3]);
m3 = nlarx(ze,[2 2 3],wavenet('num',8));
m4 = nlarx(ze,[2 2 3],wavenet('num',8),...
'nlr', [1 2]);
4-27
4 Nonlinear Black-Box Model Identification
3 Compare the resulting models by plotting the model outputs with the
measured output:
compare(zv, m1,m2,m3,m4,m5)
4-28
Identifying Nonlinear ARX Models
Tip To learn more about when to use linear models, see “When to Fit
Nonlinear Models” on page 4-2.
Typically, you create a linear ARX model using the arx command. You can
provide the linear model only at the command line when constructing (see
idnlarx) or estimating (see nlarx) a nonlinear ARX model.
The software uses the linear model for initializing the nonlinear ARX
estimation:
• Assigns the linear model orders as initial values of nonlinear model orders
(na and nb properties of the idnlarx object) and delays (nk property) to
compute standard regressors in the nonlinear ARX model structure.
• Uses the A and B polynomials of the linear model to compute the linear
function of the nonlinearity estimators (LinearCoef parameter of the
nonlinearity estimator object), except for neural network nonlinearity
estimator.
4-29
4 Nonlinear Black-Box Model Identification
m = nlarx(data,LinARXModel)
Tip When you use the same data set, a nonlinear ARX model initialized using
a linear ARX model produces a better fit than the linear ARX model.
m = nlarx(data,LinARXModel,'sigmoid')
Set the Focus property of the idnlarx object estimation to simulation error
minimization:
m = nlarx(data,LinARXModel,'sigmoid','Focus','simulation')
4-30
Identifying Nonlinear ARX Models
load throttledata.mat
This command loads the data object ThrottleData into the MATLAB
workspace. The object contains input and output samples collected from an
engine throttle system, sampled at a rate of 100 Hz.
A DC motor controls the opening angle of the butterfly valve in the throttle
system. A step signal (in volts) drives the DC motor. The output is the
angular position (in degrees) of the valve.
plot(ThrottleData)
4-31
4 Nonlinear Black-Box Model Identification
In the throttle system, a hard stop limits the valve position to 90 degrees,
and a spring brings the valve to 15 degrees when the DC motor is turned
off. These physical components introduce nonlinearities that a linear model
cannot capture.
4-32
Identifying Nonlinear ARX Models
compare(DetrendedData, LinearModel)
The linear model captures the rising and settling behavior in the linear
operating range but does not account for output saturation at 90 degrees,
as shown in the next figure.
4-33
4 Nonlinear Black-Box Model Identification
The software uses the orders and delay of the linear model for the orders of
the nonlinear model. In addition, the software computes the linear function
of sigmoidnet nonlinearity estimator.
compare(ThrottleData, NonlinearModel)
The model captures the nonlinear effects (output saturation) and improves
the overall fit to data, as shown in the next figure.
4-34
Identifying Nonlinear ARX Models
Examining a nonlinear ARX plot can help you gain insight into which
regressors have the strongest effect on the model output. Understanding the
relative importance of the regressors on the output can help you decide which
regressors should be included in the nonlinear function.
Furthermore, you can create several nonlinear models for the same data
set using different nonlinearity estimators, such a wavelet network and
tree partition, and then compare the nonlinear surfaces of these models.
Agreement between nonlinear surfaces increases the confidence that these
nonlinear models capture the true dynamics of the system.
To create a nonlinear ARX plot in the System Identification Tool GUI, select
the Nonlinear ARX check box in the Model Views area. For general
information about creating and working with plots, see “Working with Plots
in the System Identification Tool GUI” on page 11-15.
4-35
4 Nonlinear Black-Box Model Identification
Note The Nonlinear ARX check box is unavailable if you do not have a
nonlinear ARX model in the Model Board.
4-36
Identifying Nonlinear ARX Models
For example, compare linear and nonlinear ARX models of same order:
load iddata1
LM = arx(z1,[2 2 1]) % estimates linear ARX model
M = nlarx(z1,[2 2 1],'sigmoidnet') % estimates nonlinear ARX model
compare(z1,LM,M) % compares responses of LM and M
% against measured data
Analyze Residuals
Plot Nonlinearity
plot(M)
where M is the nonlinear ARX (idnlarx) model. The plot command opens the
Nonlinear ARX Model Plot window. For more information about working with
this plot window, see “Configuring the Nonlinear ARX Plot” on page 4-38 and
“Axis Limits, Legend, and 3-D Rotation” on page 4-39.
4-37
4 Nonlinear Black-Box Model Identification
If the shape of the plot looks like a plane for all the chosen regressor values,
then the model is probably linear in those regressors. In this case, you can
remove the corresponding regressors from nonlinear block by specifying the
M.NonlinearRegressors property and repeat the estimation.
You can use additional plot arguments to specify the following information:
For detailed information about plot, type the following command at the
prompt:
help idnlarx/plot
1 If your model contains multiple output, select the output channel in the
Select nonlinearity at output list. Selecting the output channel displays
the nonlinearity values that correspond to this output channel.
2 If the regressor selection options are not visible, click to expand the
Nonlinear ARX Model Plot window.
4-38
Identifying Nonlinear ARX Models
4 Specify a second regressor for a 3-D plot by selecting one of the following
types of options:
• Select Regressor 2 to display three axes. In the Range field, enter the
range of values to include on the plot for this regressor. The regressor
values are plotted on the Reg2 axis.
• Select <none> in the Regressor 2 list to display only two axes.
5 To fix the values of the regressor that are not displayed, click Fix Values.
In the Fix Regressor Values dialog box, double-click the Value cell to edit
the constant value of the corresponding regressor. The default values are
determined during model estimation. Click OK.
6 In the Nonlinear ARX Model Plot window, click Apply to update the plot.
7 To change the grid of the regressor space along each axis, Options > Set
number of samples, and enter the number of samples to use for each
regressor. Click Apply and then Close.
4-39
4 Nonlinear Black-Box Model Identification
Action Command
Change axis limits. Select Options > Set axis limits to
open the Axis Limits dialog box, and
edit the limits. Click Apply.
Hide or show the legend. Select Style > Legend. Select this
option again to show the legend.
(Three axes only) Select Style > 3D Rotate and
Rotate in three dimensions. drag the axes on the plot to
a new orientation. To disable
three-dimensional rotation, select
Note Available only when you Style > 3D Rotate again.
have selected two regressors as
independent variables.
This toolbox provides several options to facilitate how you specify initial states.
For example, you can use findstates(idnlarx) and data2state(idnlarx)
to compute state values based on operating conditions or the requirement
to maximize fit to measured output.
To learn more about how sim and predict compute the model output, see
“Low-Level Manipulation of Nonlinear ARX Components” on page 4-41.
4-40
Identifying Nonlinear ARX Models
Linearization
You can compute the operating point for linearization using findop(idnlarx).
You can import estimated Nonlinear ARX models into Simulink software
using the Nonlinear ARX block from the System Identification Toolbox block
library. Import the idnlarx object from the workspace into Simulink using
this block to simulate the model output.
4-41
4 Nonlinear Black-Box Model Identification
Evaluating Nonlinearities
Evaluating the predicted output of a nonlinearity for a specific regressor
value x requires that you first extract the nonlinearity F and regressors
from the model:
Evaluate F(x):
y = evaluate(F,x)
You can also evaluate predicted output values at multiple time instants by
evaluating F for several regressor vectors simultaneously:
y = evaluate(F,[x1;x2;x3])
load twotankdata
estData = iddata(y,u,0.2,'Tstart',0);
M = nlarx(estData,[1 1 0],'sig');
present(M)
Input name: u1
4-42
Identifying Nonlinear ARX Models
Output name: y1
Standard regressors corresponding to the orders
na = 1, nb = 1, nk = 0
No custom regressor
Nonlinear regressors:
y1(t-1)
u1(t)
Nonlinearity estimator: sigmoidnet with 10 units
NL.Parameters
Prediction of Output
y1(t)=f(y1(t-1),u1(t))
where f is the sigmoid network function. The model regressors y1(t-1) and
u1(t) are inputs to the nonlinearity estimator. Time t is a discrete variable
representing kT, where k = 0, 1,…, and T is the sampling interval. In this
example, T=0.2 second.
yp(t)=f(y1_meas(t-1),u1_meas(t))
4-43
4 Nonlinear Black-Box Model Identification
To compute the predicted value of the response using initial conditions and
current input:
load twotankdata
estData = iddata(y,u,0.2,'Tstart',0);
M = nlarx(estData,[1 1 0],'sig');
NL = M.Nonlinearity;
x0 = 0;
The model has one state because there is only one delayed term y1(t-1).
The number of states is equal to sum(getDelayInfo(M)).
RegValue = [estData.y(1),estData.u(2)];
yp_1 = evaluate(NL,RegValue)
4-44
Identifying Nonlinear ARX Models
RegMat = getreg(M,[],estData,x0);
yp = evaluate(NL,RegMat)
This code obtains a matrix of regressors RegMat for all the time samples
using getreg. RegMat has as many rows as there are time samples, and as
many columns as there are regressors in the model—two, in this example.
yp = predict(M,estData,1,'InitialState',x0)
Simulation of Output
y1(t)=f(y1(t-1),u1(t))
where f is the sigmoid network function. The model regressors y1(t-1) and
u1(t) are inputs to the nonlinearity estimator. Time t is a discrete variable
representing kT, where k = 0, 1,…, and T is the sampling interval. In this
example, T=0.2 second.
ys(t)=f(ys(t-1),u1_meas(t))
where ys(t) is the simulated value of the response at time t. The simulation
equation is the same as the prediction equation, except that the past output
value ys(t-1) results from the simulation at the previous time step, rather
than the measured output value.
4-45
4 Nonlinear Black-Box Model Identification
To compute the simulated value of the response using initial conditions and
current input:
load twotankdata
estData = iddata(y,u,0.2,'Tstart',0);
M = nlarx(estData,[1 1 0],'sig');
NL = M.Nonlinearity
x0 = 0;
The model has one state because there is only one delayed term y1(t-1).
The number of states is equal to sum(getDelayInfo(M)).
RegValue = [0,estData.u(1)]
ys_0 = evaluate(NL,RegValue)
RegValue = [ys_0,estData.u(2)];
ys_1 = evaluate(NL,RegValue)
4-46
Identifying Nonlinear ARX Models
RegValue = [ys_1,estData.u(3)];
ys_2 = evaluate(NL,RegValue)
Unlike for output prediction, you cannot use getreg to compute regressor
values for all time values. You must compute regressors values at each time
sample separately because the output samples required for forming the
regressor vector are available iteratively, one sample at a time.
ys = sim(M,estData,x0)
F ( x) = ( x − r) PL + a1 f ( ( x − r ) Qb1 + c1 ) + …
+ an f ( ( x − r ) Qbn + cn ) + d
1
f ( z) = .
−z
e +1
In F(x), the input to the sigmoid function is x-r. x is the regressor value and
r is regressor mean, computed from the estimation data. an, bn, and cn are
the network parameters stored in the model property M.nl.par, where M
is an idnlarx object.
Compute the output value at time t=1, when the regressor values are
x=[estData.y(1),estData.u(2)]:
4-47
4 Nonlinear Black-Box Model Identification
NL = M.Nonlinearity
% Assign values to the parameters in the expression for F(x):
x = [estData.y(1),estData.u(2)]; % regressor values at t=1
r = NL.Parameters.RegressorMean;
P = NL.Parameters.LinearSubspace;
L = NL.Parameters.LinearCoef;
d = NL.Parameters.OutputOffset;
Q = NL.Parameters.NonLinearSubspace;
aVec = NL.Parameters.OutputCoef; %[a_1; a_2; ...]
cVec = NL.Parameters.Translation; %[c_1; c_2; ...]
bMat = NL.Parameters.Dilation; %[b_1; b_2; ...]
% Compute the linear portion of the response (plus offset):
yLinear = (x-r)*P*L+d
% Compute the nonlinear portion of the response:
f = @(z)1/(exp(-z)+1); % anonymous function for sigmoid unit
yNonlinear = 0;
for k = 1:length(aVec)
fInput = (x-r)*Q* bMat(:,k)+cVec(k);
yNonlinear = yNonlinear+aVec(k)*f(fInput);
end
% Total response y = F(x) = yLinear + yNonlinear
y = yLinear + yNonlinear; % y is equal to evaluate(NL,x)
4-48
Identifying Hammerstein-Wiener Models
4-49
4 Nonlinear Black-Box 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 Black-Box Polynomial Models?” on page 3-39.
For ny outputs and nu inputs, the linear block is a transfer function matrix
containing entries:
B j,i (q)
F j,i (q)
4-50
Identifying Hammerstein-Wiener Models
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.
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)).
4-51
4 Nonlinear Black-Box Model Identification
Resulting models are idnlhw objects that store all model data, including
model parameters and nonlinearity estimator. See the idnlhw reference page
for more information.
( )
−1
(s) = es + 1 . βk is a row vector such
that βk ( x − γ k ) is a scalar.
4-52
Identifying Hammerstein-Wiener Models
Custom customnet Similar to sigmoid network but you (For advanced use)
network specify κ(s) . Uses the unit
(user-defined) function that you
specify.
4-53
4 Nonlinear Black-Box Model Identification
By default, the input and output nonlinearity estimators are both piecewise
linear functions, parameterized by breakpoint locations (see the pwlinear
reference page). You can configure the input and output nonlinearity
estimators by:
See these topics for detailed steps to change the model structure:
4-54
Identifying Hammerstein-Wiener Models
You can configure the estimation method using the Algorithm properties of
the idnlhw class. The most common of these properties are:
By default, the initial states of the model are zero and not estimated.
However, you can choose to estimate initial states during model estimation,
which sometimes helps to achieve better results.
4-55
4 Nonlinear Black-Box Model Identification
3 (Optional) Edit the Model name by clicking the pencil icon. The name
of the model should be unique to all Hammerstein-Wiener models in the
System Identification Tool GUI.
5 Keep the default settings in the Nonlinear Models dialog box that specify
the model structure and the algorithm, or modify these settings:
Note For more information about available options, click Help in the
Nonlinear Models dialog box to open the GUI help.
4-56
Identifying Hammerstein-Wiener Models
6 Click Estimate to add this model to the System Identification Tool GUI.
4-57
4 Nonlinear Black-Box Model Identification
7 Validate the model response by selecting the desired plot in the Model
Views area of the System Identification Tool GUI. For more information
about validating models, see Chapter 8, “Model Analysis”.
If you get a poor fit, try changing the model structure or algorithm
configuration in step 5.
Basic Estimation
4-58
Identifying Hammerstein-Wiener Models
The second input argument [nb nf nk] sets the order of the linear transfer
function, where nb is the number of zeros plus 1, nf is the number of poles,
and nk is the input delay. By default, both the input and output nonlinearity
estimators are piecewise linear functions (see the pwlinear reference page).
m is an idnlhw object.
For MIMO systems, nb, nf, and nk are ny-by-nu matrices. See the nlhw
reference page for more information about MIMO estimation.
m = nlhw(data,[2 2 1],'saturation',poly1d('Degree',3))
For MIMO models, specify the nonlinearities using objects unless you want to
use the same nonlinearity with default configuration for all channels.
4-59
4 Nonlinear Black-Box Model Identification
CNetw = cutomnet(@gaussunit);
m = nlhw(data,[na nb nk],CNetw)
For more information about model estimation and properties, see the nlhw
and idnlhw reference pages.
4-60
Identifying Hammerstein-Wiener Models
m1 = nlhw(data, [2 2 1],'sigmoidnet','wavenet');
m2 = pem(data,m1) % can repeatedly run this command
m1 = nlhw(data, [2 2 1],'sigmoidnet','wavenet');
m2 = nlhw(data,m1) % can repeatedly run this command
You can display the progress of the iterative search in the MATLAB Command
Window using the Display property of the idnlhw class:
M2= pem(data,M1p,'Display','On')
4-61
4 Nonlinear Black-Box Model Identification
from the data. By default, the initial states corresponding to the linear block
of the Hammerstein-Wiener model are zero.
m = nlhw(data,[nb nf nk],[sigmoidnet;pwlinear],[],...
'InitialState','e');
If you do not get a satisfactory model after many trials with various model
structures and algorithm settings, it is possible that the data is poor. For
example, your data might be missing important input or output variables and
does not sufficiently cover all the operating points of the system.
load twotankdata
z = iddata(y, u, 0.2);
ze = z(1:1000); zv = z(1001:3000);
m1 = nlhw(ze,[2 3 1]);
m2 = nlhw(ze,[2 2 3]);
m3 = nlhw(ze,[2 2 3], pwlinear('num',13),...
pwlinear('num',10));
m4 = nlhw(ze,[2 2 3], sigmoidnet('num',2),...
pwlinear('num',10));
4-62
Identifying Hammerstein-Wiener Models
3 Compare the resulting models by plotting the model outputs on top of the
measured output:
compare(zv,m1,m2,m3,m4,m5)
4-63
4 Nonlinear Black-Box Model Identification
load iddata1
LM = arx(z1,[2 2 1]);
nb = 1; % In general, nb = ones(ny,nu)
% ny is number of outputs
% nu is number of inputs
nf = nb;
nk = 0; % In general, nk = zeros(ny,nu)
% ny is number of outputs
% nu is number of inputs
M = idnlhw([nb nf nk],'poly1d','pwlinear');
M.b = Num;
M.f = Den;
4 Estimate the model coefficients, which refines the linear model coefficients
in Num and Den:
M = pem(z1, M);
compare(z1,LM,M)
4-64
Identifying Hammerstein-Wiener Models
Tip To learn more about when to use linear models, see “When to Fit
Nonlinear Models” on page 4-2.
Typically, you use the oe or n4sid command to obtain the linear model. You
can provide the linear model only at the command line when constructing (see
idnlhw) or estimating (see nlhw) a Hammerstein-Wiener model.
The software uses the linear model for initializing the Hammerstein-Wiener
estimation:
• Assigns the linear model orders as initial values of nonlinear model orders
(nb and nf properties of the Hammerstein-Wiener (idnlhw) and delays
(nk property).
• Sets the B and F polynomials of the linear transfer function in the
Hammerstein-Wiener model structure.
4-65
4 Nonlinear Black-Box Model Identification
m = nlhw(data,LinModel)
By default, both the input and output nonlinearity estimators are piecewise
linear functions (see pwlinear).
Specify different input and output nonlinearity, for example sigmoid and
deadzone:
m = nlarx(data,LinModel, 'sigmoid','deadzone')
load throttledata.mat
This command loads the data object ThrottleData into the MATLAB
workspace. The object contains input and output samples collected from an
engine throttle system, sampled at a rate of 100 Hz.
A DC motor controls the opening angle of the butterfly valve in the throttle
system. A step signal (in volts) drives the DC motor. The output is the
angular position (in degrees) of the valve.
4-66
Identifying Hammerstein-Wiener Models
plot(ThrottleData)
In the throttle system, a hard stop limits the valve position to 90 degrees,
and a spring brings the valve to 15 degrees when the DC motor is turned
off. These physical components introduce nonlinearities that a linear model
cannot capture.
4-67
4 Nonlinear Black-Box Model Identification
compare(DetrendedData, LinearModel)
The linear model captures the rising and settling behavior in the linear
operating range but does not account for output saturation at 90 degrees,
as shown in the next figure.
4-68
Identifying Hammerstein-Wiener Models
The software uses the orders and delay of the linear model for the orders
of the nonlinear model. In addition, the software uses the B and F
polynomials of the linear transfer function.
compare(ThrottleData, NonlinearModel)
4-69
4 Nonlinear Black-Box Model Identification
4-70
Identifying Hammerstein-Wiener Models
To include or exclude a model on the plot, click the corresponding model icon
in the System Identification Tool GUI. By default, the input nonlinearity
block UNL is selected. You can select the output nonlinearity block YNL or
Linear Block, as shown in the next figure.
4-71
4 Nonlinear Black-Box Model Identification
Hide or show
the top pane.
After you generate a plot, you can learn more about your model by:
4-72
Identifying Hammerstein-Wiener Models
For example, compare linear and nonlinear ARX models of same order:
load iddata1
LM = arx(z1,[2 2 1]) % estimates linear ARX model
M = nlhw(z1,[2 2 1]) % estimates Hammerstein-Wiener model
compare(z1,LM,M) % compares responses of LM and M
% against measured data
Analyze Residuals
Residuals are differences between the model output and the measured output.
Thus, residuals represent the portion of the output not explained by the
model. Use resid to compute and plot the residuals.
Plot Nonlinearity
Access the object representing the nonlinearity estimator and its parameters
using M.InputNonlinearity (or M.unl) and M.OutputNonlinearity (or
M.ynl), where M is the estimated model.
4-73
4 Nonlinear Black-Box Model Identification
Use plot to view the shape of the nonlinearity and properties of the linear
block. For example:
plot(M)
You can use additional plot arguments to specify the following information:
For detailed information about plot, type the following command at the
prompt:
help idnlhw/plot
4-74
Identifying Hammerstein-Wiener Models
• To plot uNL as a command of the input data, click the uNL block.
• To plot yNL as a command of its inputs, click the yNL block.
Note The input to the output nonlinearity block yNL is the output from the
Linear Block and not the measured input data.
3 If your model contains multiple inputs or outputs, select the channel in the
Select nonlinearity at channel list. Selecting the channel updates the
plot and displays the nonlinearity values versus the corresponding input to
this nonlinear block.
4 To change the range of the horizontal axis, select Options > Set input
range to open the Range for Input to Nonlinearity dialog box. Enter the
range using the format [MinValue MaxValue]. Click Apply and then
Close to update the plot.
2 Click the Linear Block to select it. The Linear Block is highlighted in green.
3 In the Select I/O pair list, select the input and output data pair for which
to view the response.
4-75
4 Nonlinear Black-Box Model Identification
4 In the Choose plot type list, select the linear plot from the following
options:
• Step
• Impulse
• Bode
• Pole-Zero Map
5 If you selected to plot step or impulse response, you can set the time span.
Select Options > Time span and enter a new time span in units of time
you specified for the model.
For a time span T, the resulting response is plotted from -T/4 to T. The
default time span is 10.
6 If you selected to plot a Bode plot, you can set the frequency range.
4-76
Identifying Hammerstein-Wiener Models
This toolbox provides a number of options to facilitate how you specify initial
states. For example, you can use findstates(idnlhw) to automatically
search for state values in simulation and prediction applications. You can also
specify the states manually.
If you need to specify the states manually, see the idnlhw reference page for a
definition of the Hammerstein-Wiener model states.
To learn more about how sim and predict compute the model output, see
“Low-Level Manipulation of Hammerstein-Wiener Components” on page 4-78.
Linearization
You can compute the operating point for linearization using findop(idnlhw).
4-77
4 Nonlinear Black-Box Model Identification
Evaluate F(u):
w = evaluate(F,u)
where u is a scalar representing the value of the input signal at a given time.
w = evaluate(F,[u1;u2;u3])
Similarly, you can evaluate the value of the nonlinearity H using the output
of the linear block x(t) as its input:
y = evaluate(H,x)
4-78
Identifying Hammerstein-Wiener Models
M = nlhw(data,[nb nf nk],[wavenet;poly1d],'saturation')
F = M.InputNonlinearity
F1 = F(1);
F2 = F(2);
w1 = evaluate(F(1), u1_value);
w2 = evaluate(F(2), u2_value);
The total input to the linear block, w, is a vector of w1 and w2 (w = [w1 w2]).
load twotankdata
estData = iddata(y,u,0.2)
M = nlhw(estData,[1 5 3],'pwlinear','poly1d');
uNL = M.InputNonlinearity;
linModel = M.LinearModel;
4-79
4 Nonlinear Black-Box Model Identification
yNL = M.OutputNonlinearity;
4-80
Linear Approximation of Nonlinear Black-Box Models
4-81
4 Nonlinear Black-Box Model Identification
linapp estimates the best linear model that is structurally similar to the
original nonlinear model and provides the best fit between a given input and
the corresponding simulated response of the nonlinear model.
• For nonlinear ARX models, linapp estimates a linear ARX model using the
same model orders na, nb, and nk as the original model.
• For Hammerstein-Wiener models, linapp estimates a linear Output-Error
(OE) model using the same model orders nb, nf, and nk.
4-82
Linear Approximation of Nonlinear Black-Box Models
input and model state values. The resulting linear model is accurate in the
local neighborhood of this operating point.
To specify the operating point of your system, you must specify the constant
input and the states. For more information about state definitions for each
type of parametric model, see these reference pages:
If you do not know the operating point values for your system, see “Computing
Operating Points for Nonlinear Black-Box Models” on page 4-83.
If you do not know the operating conditions of your system for linearization,
you can use findop to compute the operating point from specifications:
4-83
4 Nonlinear Black-Box Model Identification
It is optional to specify the initial conditions for simulation when using this
method because initial conditions often do not affect the steady-state values.
By default, the initial conditions are zero.
However, for nonlinear ARX models, the steady-state output value might
depend on initial conditions. For these models, you should investigate
the effect of initial conditions on model response and use the values that
produce the desired output. You can use data2state(idnlarx) to map the
input-output signal values from before the simulation starts to the model’s
initial states. Because the initial states are a function of the past history of
the model’s input and output values, data2state generates the initial states
by transforming the data.
4-84
5
If it is too difficult to describe your system using known physical laws, you
can perform black-box modeling.
You can also use the idss model object to perform structured model
estimation by using structure matrices As, Bs, Cs, Ds, X0s, Ks to fix or free
specific parameters. However, you cannot use this approach to estimate
arbitrary structures (arbitrary parameterization). For more information
about structure matrices, see “How to Estimate State-Space Models with
Structured Parameterization” on page 3-94.
5-2
Data Supported by Grey-Box Models
You must first import your data into the MATLAB workspace. If you are
using the System Identification Tool GUI, then import the data into the GUI
to make the data available to the toolbox. However, if you prefer to work at
the command line, then represent your data as an iddata or idfrd object.
For more information about preparing data for identification, see Chapter 2,
“Data Import and Processing”.
5-3
5 ODE Parameter Estimation (Grey-Box Modeling)
The idgrey object requires that you write a function to describe the linear
dynamics in the state-space form, such that this file returns the state-space
matrices as a function of your parameters. For more information, see
“Specifying the Linear Grey-Box Model Structure” on page 5-6.
The idnlgrey object requires that you write a function or MEX-file to describe
the dynamics as a set of first-order differential equations, such that this file
returns the output and state derivatives as a function of time, input, state,
and parameter values. For more information, see “Specifying the Nonlinear
Grey-Box Model Structure” on page 5-17.
5-4
Choosing idgrey or idnlgrey Model Object
5-5
5 ODE Parameter Estimation (Grey-Box Modeling)
(t)
x (t) = Fx(t) + Gu(t) + Kw
y(t) = Hx(t) + Du(t) + w(t)
x(0) = x0
5-6
Estimating Linear Grey-Box Models
Use the following format to implement the linear grey-box model in the file:
[A,B,C,D,K,x0] = myfunc(par,T,aux)
⎡0 1 ⎤ ⎡0⎤
x (t) = ⎢ ⎥ x(t) + ⎢ ⎥ u(t)
⎣0 θ1 ⎦ ⎣ θ2 ⎦
⎡1 0 ⎤
y(t) = ⎢ ⎥ x(t) + e(t)
⎣0 1 ⎦
⎡ θ3 ⎤
x(0) = ⎢ ⎥
⎣0⎦
5-7
5 ODE Parameter Estimation (Grey-Box Modeling)
The parameter −θ1 is the inverse time constant of the motor, and − θ2 θ is the
1
static gain from the input to the angular velocity.
The motor is at rest at t=0, but its angular position θ3 is unknown. Suppose
that the approximate nominal values of the unknown parameters are θ1 = −1
and θ2 = 0.25 . For more information about this example, see the section
on state-space models in System Identification: Theory for the User, Second
Edition, by Lennart Ljung, Prentice Hall PTR, 1999.
(t)
x (t) = Fx(t) + Gu(t) + Kw
y(t) = Hx(t) + Du(t) + w(t)
x(0) = x0
1 Create the following file to represent the model structure in this example:
5-8
Estimating Linear Grey-Box Models
2 Use the following syntax to define an idgrey model object based on the
myfunc file:
m = idgrey('myfunc',par,'c',T,aux)
Note You must specify T and aux even if they are not used by the myfunc
code.
m = pem(data,m)
where data is the estimation data and m is the idgrey object with unknown
parameters.
5-9
5 ODE Parameter Estimation (Grey-Box Modeling)
∂x(t, ξ) ∂ 2 x(t, ξ)
=κ
∂t ∂ξ2
∂ 2 x(t, ξ) x ( t, ξ + ΔL ) − 2 x(t, ξ) + x ( t, ξ − ΔL )
=
∂ξ 2
( ΔL )2
where ξ = k ⋅ ΔL
k ⋅ ΔL ≤ ξ < ( k + 1) ΔL
(t)
x (t) = Fx(t) + Gu(t) + Kw
y(t) = Hx(t) + Du(t) + w(t)
x(0) = x0
5-10
Estimating Linear Grey-Box Models
The following code describes the state-space equation for this model. In this
case, the auxiliary variables specify grid-size variables, so that you can modify
the grid size without the code file.
5-11
5 ODE Parameter Estimation (Grey-Box Modeling)
Use the following syntax to define an idgrey model object based on the heatd
code file:
m = idgrey('heatd',[0.27 1],'c',[10,1,22])
For given data, you can use pem to estimate the grey-box parameter values:
me = pem(data,m)
The following command shows how you can specify to estimate a new model
with different auxiliary variables directly in the estimator command:
me = pem(data,m,'FileArgument',[20,1,22])
This syntax uses the FileArgument model property to specify a finer grid
using a larger value for Ngrid. For more information about linear grey-box
model properties, see the idgrey reference page.
5-12
Estimating Linear Grey-Box Models
⎡ par1 par 2⎤ ⎡1 ⎤
x(kT + T ) = ⎢ ⎥ x(kT ) + ⎢ ⎥ u(kT ) + w(kT )
⎣ 1 0 ⎦ ⎣0 ⎦
y(kT ) = [ par 3 par 4 ] x(kT ) + e(kT )
x(0) = x0
To run this example, you must load an input-output data set and represent
it as an iddata or idfrd object called data. For more information about
this operation, see “Representing Time- and Frequency-Domain Data Using
iddata Objects” on page 2-49 or “Representing Frequency-Response Data
Using idfrd Objects” on page 2-69.
5-13
5 ODE Parameter Estimation (Grey-Box Modeling)
2 Specify initial guesses for the unknown parameter values and the auxiliary
parameter value R2:
Minit = idgrey('mynoise',Pvec,'d',auxVal);
5-14
Estimating Linear Grey-Box Models
Model = pem(data,Minit)
5-15
5 ODE Parameter Estimation (Grey-Box Modeling)
iddemo
For examples of code files and MEX-files that specify model structure, see the
toolbox/ident/iddemos/examples folder. For example, the model of a DC
motor—used in the demo idnlgreydemo1—is described in files dcmotor_m
and dcmotor_c.
5-16
Estimating Nonlinear Grey-Box Models
After you establish the equations for your system, create a function or
MEX-file. MEX-files, which can be created in C or Fortran, are dynamically
linked subroutines that can be loaded and executed by the MATLAB
interpreter. For more information about MEX-files, see the MATLAB
documentation.
The purpose of the model file is to return the state derivatives and model
outputs as a function of time, states, inputs, and model parameters, as follows:
5-17
5 ODE Parameter Estimation (Grey-Box Modeling)
• t — Current time.
• x — State vector at time t. For static models, equals [].
• u — Input vector at time t. For time-series models, equals [].
• p1,p2, ...,pN — Parameters, which can be real scalars, column vectors
or two-dimensional matrices. N is the number of parameter objects. For
scalar parameters, N is the total number of parameter elements.
• FileArgument — Contains auxiliary variables that might be required for
updating the constants in the state equations.
Tip After creating a model file, call it directly from the MATLAB software
with reasonable inputs and verify the output values.
For an example of creating grey-box model files and idnlgrey model object,
see the demo Creating idnlgrey Model Files.
m = idnlgrey('filename',Order,Parameters,InitialStates)
5-18
Estimating Nonlinear Grey-Box Models
• Order — Vector with three entries [Ny Nu Nx], specifying the number of
model outputs Ny, the number of inputs Nu, and the number of states Nx.
• Parameters — Parameters, specified as struct arrays, cell arrays, or
double arrays.
• InitialStates — Specified in the same way as parameters. Must be the
fourth input to the idnlgrey constructor.
For detailed information about this object and its properties, see the idnlgrey
reference page.
The input-output dimensions of the data must be compatible with the input
and output orders you specified for the idnlgrey model.
m = pem(data,m)
where data is the estimation data and m is the idnlgrey model object you
constructed.
You can pass additional property-value pairs to pem to specify the properties
of the model or the estimation algorithm. Assignable properties include
the ones returned by the get(idnlgrey) command and the algorithm
properties returned by the get(idnlgrey, 'Algorithm'), such as MaxIter
and Tolerance. For detailed information about these model properties, see
the idnlgrey reference page.
For more information about validating your models, see Chapter 8, “Model
Analysis”.
5-19
5 ODE Parameter Estimation (Grey-Box Modeling)
The following algorithm properties can affect the quality of the results:
For detailed information about these and other model properties, see the
idnlgrey reference page.
Simulation Method
You can specify the simulation method using the SimulationOptions
(struct) fields of the model Algorithm property.
Search Method
You can specify the search method for estimating model parameters using the
SearchMethod field of the Algorithm property. Two categories of methods are
available for nonlinear grey-box modeling.
5-20
Estimating Nonlinear Grey-Box Models
Gradient Options
You can specify the method for calculating gradients using the
GradientOptions field of the Algorithm property. Gradients are the
derivatives of errors with respect to unknown parameters and initial states.
Option for gradient computation include the choice of the differencing scheme
(forward, backward or central), the size of minimum perturbation of the
unknown quantities, and whether the gradients are calculated simultaneously
or individually.
For example, you can specify the following properties as part of the pem syntax:
m = pem(data,init_model,'Search','gn',...
'MaxIter',5,...
'Display','On')
5-21
5 ODE Parameter Estimation (Grey-Box Modeling)
5-22
After Estimating Grey-Box Models
The toolbox represents linear grey-box models using the idgrey model object.
To convert grey-box models to state-space form, use the idss command,
as described in “Transforming Between Linear Model Representations” on
page 3-118. You can then analyze the model behavior using transient- and
frequency-response plots and other linear analysis plots.
You can import grey box models into a Simulink model using the System
Identification Toolbox Block Library. For more information, see “Simulating
Model Output” on page 10-6.
5-23
5 ODE Parameter Estimation (Grey-Box Modeling)
5-24
6
You can estimate time-series spectra using both time- and frequency-domain
data. Time-series spectra describe time-series variations using cyclic
components at different frequencies.
Note ARMA and state-space models are supported for time-domain data
only. Only single-output ARMA models are supported.
6-2
Preparing Time-Series Data
For more information about preparing data for modeling, see “Ways to Process
Data for System Identification” on page 2-4.
If your data is already in the MATLAB workspace, you can import it directly
into the System Identification Tool GUI. If you prefer to work at the command
line, you must represent the data as a System Identification Toolbox data
object instead.
y = iddata(s,[],Ts);
6-3
6 Time Series Identification
2 In the Method list, select the spectral analysis method you want to use.
For information about each method, see “Options for Computing Spectral
Models” on page 3-5.
6-4
Estimating Time-Series Power Spectra
5 In the Model Name field, enter the name of the correlation analysis model.
The model name should be unique in the Model Board.
6 Click Estimate to add this model to the Model Board in the System
Identification Tool GUI.
The resulting models are stored as an idfrd model object, which contains
SpectrumData and its variance. For multiple-output data, SpectrumData
contains power spectra of each output and the cross-spectra between each
output pair.
6-5
6 Time Series Identification
Command Description
etfe Estimates a periodogram using Fourier
analysis.
spa Estimates the power spectrum with its
standard deviation using spectral analysis.
spafdr Estimates the power spectrum with
its standard deviation using a variable
frequency resolution.
g = spa(y)
p = etfe(y)
bode(g,p,'sd',3)
6-6
Estimating AR and ARMA Models
The ARMA structure reduces to the AR structure for C(q)=1. The ARMA
model is a special case of the ARMAX model with no input.
For more information about polynomial models, see “What Are Black-Box
Polynomial Models?” on page 3-39.
6-7
6 Time Series Identification
To estimate AR and ARMA models using the System Identification Tool GUI:
2 In the Structure list, select the polynomial model structure you want to
estimate from the following options:
• AR:[na]
• ARMA:[na nc]
This action updates the options in the Linear Parametric Models dialog box
to correspond with this model structure. For information about each model
structure, see “Definition of AR and ARMA Models” on page 6-7.
Tip To enter model orders and delays using the Order Editor dialog box,
click Order Editor.
6-8
Estimating AR and ARMA Models
5 In the Name field, edit the name of the model or keep the default. The
name of the model should be unique in the Model Board.
6 In the Initial state list, specify how you want the algorithm to treat initial
states. For more information about the available options, see “Options for
Initial States” on page 3-66.
Tip If you get an inaccurate fit, try setting a specific method for handling
initial states rather than choosing it automatically.
8 (ARMA only) To view the estimation progress at the command line, select
the Trace check box. During estimation, the following information is
displayed for each iteration:
• Loss function — Equals the determinant of the estimated covariance
matrix of the input noise.
• Parameter values — Values of the model structure coefficients you
specified.
• Search direction — Changes in parameter values from the previous
iteration.
6-9
6 Time Series Identification
9 Click Estimate to add this model to the Model Board in the System
Identification Tool GUI.
10 (Prediction-error method only) To stop the search and save the results
after the current iteration has been completed, click Stop Iterations. To
continue iterations from the current model, click the Continue iter button
to assign current parameter values as initial guesses for the next search.
11 To plot the model, select the appropriate check box in the Model Views
area of the System Identification Tool GUI. For more information about
validating models, see Chapter 8, “Model Analysis”.
You can export the model to the MATLAB workspace for further analysis
by dragging it to the To Workspace rectangle in the System Identification
Tool GUI.
6-10
Estimating AR and ARMA Models
The ar command provides additional options to let you choose the algorithm
for computing the least-squares from a group of several popular techniques
from the following methods:
6-11
6 Time Series Identification
where T is the sampling interval and y(kT) is the output at time instant kT.
6-12
Estimating State-Space Time-Series Models
Command Description
n4sid Noniterative subspace method for estimating
discrete-time linear state-space models.
6-13
6 Time Series Identification
6-14
Estimating Nonlinear Models for Time-Series Data
Before you can estimate models for time-series data, you must have already
prepared the data as described in “Preparing Time-Series Data” on page 6-3.
If you understand the underlying physics of the system, you can specify an
ordinary differential or difference equation and estimate the coefficients. To
learn how to estimate this type of model, see “Estimating Nonlinear Grey-Box
Models” on page 5-16.
6-15
6 Time Series Identification
6-16
7
Recursive Model
Identification
You might also use online models to investigate time variations in system
and signal properties.
The methods for computing online models are called recursive identification
methods. Recursive algorithms are also called recursive parameter estimation,
adaptive parameter estimation, sequential estimation, and online algorithms.
iddemo5
7-2
Commands for Recursive Estimation
Before estimating models using recursive algorithms, you must import your
data into the MATLAB workspace and represent your data in either of the
following formats:
• Matrix of the form [y u]. y represents the output data using one or more
column vectors. Similarly, u represents the input data using one or more
column vectors.
• iddata or idfrd object. For more information about creating these objects,
see Chapter 2, “Data Import and Processing”.
[params,y_hat]=command(data,nn,adm,adg)
params matrix contains the values of the estimated parameters, where the
kth row contains the parameters associated with time k, which are computed
using the data values in the rows up to and including the row k.
y_hat contains the predicted output values such that the kth row of y_hat is
computed based on the data values in the rows up to and including the row k.
Tip y_hat contains the adaptive predictions of the output and is useful for
adaptive filtering applications, such as noise cancelation.
nn specified the model orders and delay according to the specific polynomial
structure of the model. For example, nn=[na nb nk] for ARX models. For
more information about specifying polynomial model orders and delays, see
“Identifying Input-Output Polynomial Models” on page 3-39.
7-3
7 Recursive Model Identification
adm and adg specify any of the four recursive algorithm, as described in
“Algorithms for Recursive Estimation” on page 7-6.
Command Description
rarmax Estimate parameters of
single-input/single-output ARMAX
and ARMA models.
rarx Estimate parameters of single- or
multiple-input and single-output ARX
and AR models. Does not support
multiple-output system.
rbj Estimate parameters of
single-input/single-output Box-Jenkins
models.
roe Estimate parameters of
single-input/single-output Output-Error
models.
7-4
Commands for Recursive Estimation
Command Description
rpem Estimate parameters of multiple-input
and single-output ARMAX/ARMA,
Box-Jenkins, or Output-Error models
using the general recursive prediction-error
algorithm for estimating the parameter
gradient.
7-5
7 Recursive Model Identification
θˆ ( t ) = θˆ ( t − 1) + K ( t ) ( y ( t ) − yˆ ( t ) )
7-6
Algorithms for Recursive Estimation
The simplest way to visualize the role of the gradient ψ ( t ) of the parameters,
is to consider models with a linear-regression form:
y ( t ) = ψ T ( t ) θ0 ( t ) + e ( t )
For linear regression equations, the predicted output is given by the following
equation:
yˆ ( t ) = ψ T ( t ) θˆ ( t − 1)
7-7
7 Recursive Model Identification
For models that do not have the linear regression form, it is not possible to
compute exactly the predicted output and the gradient ψ ( t ) for the current
θˆ ( t ) = θˆ ( t − 1) + K ( t ) ( y ( t ) − yˆ ( t ) )
yˆ ( t ) = ψ T ( t ) θˆ ( t − 1)
P ( t − 1)
Q (t) =
R2 + ψ ( t ) P ( t − 1) ψ ( t )
T
P ( t − 1) ψ ( t ) ψ ( t ) P ( t − 1)
T
P ( t ) = P ( t − 1) + R1 −
R2 + ψ ( t ) P ( t − 1) ψ ( t )
T
y ( t ) = ψ T ( t ) θ0 ( t ) + e ( t )
7-8
Algorithms for Recursive Estimation
This formulation also assumes that the true parameters θ0 ( t ) are described
by a random walk:
θ0 ( t ) = θ0 ( t − 1) + w ( t )
w(t) is Gaussian white noise with the following covariance matrix, or drift
matrix R1:
Ew ( t ) w ( t )
T
= R1
y ( t ) = ψ T ( t ) θ0 ( t ) + e ( t )
The Kalman filter algorithm is entirely specified by the sequence of data y(t),
the gradient ψ ( t ) , R1, R2, and the initial conditions θ ( t = 0 ) (initial guess of
the parameters) and P ( t = 0 ) (covariance matrix that indicates parameters
errors).
Note To simplify the inputs, you can scale R1, R2, and P ( t = 0 ) of the
original problem by the same value such that R2 is equal to 1. This scaling
does not affect the parameters estimates.
[params,y_hat]=command(data,nn,adm,adg)
7-9
7 Recursive Model Identification
To specify the Kalman filter algorithm, set adm to 'kf' and adg to the value
of the drift matrix R1 (described in “Mathematics of the Kalman Filter
Algorithm” on page 7-8).
θˆ ( t ) = θˆ ( t − 1) + K ( t ) ( y ( t ) − yˆ ( t ) )
yˆ ( t ) = ψ T ( t ) θˆ ( t − 1)
P ( t − 1)
Q (t) = P (t) =
λ + ψ ( t ) P ( t − 1) ψ ( t )
T
⎛ P ( t − 1) ψ ( t ) ψ ( t ) P ( t − 1) ⎞
T
P (t) = λ⎜ (
)
1 ⎜ P t −1 − ⎟
λ + ψ ( t ) P ( t − 1) ψ ( t ) ⎠⎟
T
⎝
∑ k=1 λt−k e2 ( k)
t
7-10
Algorithms for Recursive Estimation
λ is called the forgetting factor and typically has a positive value between
0.97 and 0.995.
[params,y_hat]=command(data,nn,adm,adg)
To specify the forgetting factor algorithm, set adm to 'ff' and adg to the
value of the forgetting factor λ (described in “Mathematics of the Forgetting
Factor Algorithm” on page 7-10).
7-11
7 Recursive Model Identification
θˆ ( t ) = θˆ ( t − 1) + K ( t ) ( y ( t ) − yˆ ( t ) )
yˆ ( t ) = ψ T ( t ) θˆ ( t − 1)
Q ( t ) = γI
In the normalized gradient approach, Q(t) is the product of the gain γ , and
the identity matrix is normalized by the magnitude of the gradient ψ ( t ) :
γ
Q (t) = 2
I
ψ (t)
These choices of Q(t) update the parameters in the negative gradient direction,
where the gradient is computed with respect to the parameters.
[params,y_hat]=command(data,nn,adm,adg)
7-12
Algorithms for Recursive Estimation
To specify the unnormalized gain algorithm, set adm to 'ug' and adg to the
value of the gain γ (described in “Mathematics of the Unnormalized and
Normalized Gradient Algorithm” on page 7-12).
To specify the normalized gain algorithm, set adm to 'ng' and adg to the
value of the gain γ .
7-13
7 Recursive Model Identification
Data Segmentation
For systems that exhibit abrupt changes while the data is being collected,
you might want to develop models for separate data segments such that the
system does not change during a particular data segment. Such modeling
requires identification of the time instants when the changes occur in the
system, breaking up the data into segments according to these time instants,
and identification of models for the different data segments.
Use segment to build polynomial models, such as ARX, ARMAX, AR, and
ARMA, so that the model parameters are piece-wise constant over time. For
detailed information about this command, see the corresponding reference
page.
iddemo5
7-14
8
Model Analysis
For ideas on how to adjust your modeling strategy based on validation results,
see “Troubleshooting Models” on page 8-64.
Tip If you have installed the Control System Toolbox product, you can also
view models using the LTI Viewer. For more information, see “Viewing Model
Response Using the LTI Viewer” on page 9-5.
8-2
Overview of Model Validation and Plots
Note Do not use this comparison when feedback is present in the system
because feedback makes nonparametric models unreliable. To test if
feedback is present in the system, use the advice command on the data.
8-3
8 Model Analysis
models (validation data). Although you can designate the same data set to be
used for estimating and validating the model, you risk overfitting your data.
When you validate a model using an independent data set, this process is
called cross-validation.
8-4
Overview of Model Validation and Plots
8-5
8 Model Analysis
For example, in the following figure, Model output is selected. In this case,
the models n4s4 is not included on the plot because only arx441 is active.
Active model
Inactive model
To close a plot, clear the corresponding check box in the System Identification
Tool GUI.
Tip To get information about a specific plot, select a help topic from the Help
menu in the plot window.
For general information about working with plots in the System Identification
Toolbox product , see “Working with Plots in the System Identification Tool
GUI” on page 11-15.
8-6
Overview of Model Validation and Plots
8-7
8 Model Analysis
Simulating a model means computing its response using input data and
initial conditions. The time samples of the model response match the time
samples of the input data used for simulation.
where y is the output and u is the input. For parameter values a = –0.9 and b
= 1.5, the equation becomes:
Suppose you want to compute the values y(1), y(2), y(3),... for given input
values u(0) = 2, u(1) = 1, u(2) = 4,...Here, y(1) is the value of output at the first
sampling instant. Using initial condition of y(0) = 0, the values of y(t) for
times t = 1, 2 and 3 can be computed as:
8-8
Simulating and Predicting Model Output
...
A model also lets you compute a qualified guess of future output values based
on past observations of system’s inputs and outputs. This is called prediction.
Prediction forecasts the model response k steps ahead into the future using
the current and past values of measured input and output values. k is called
the prediction horizon, and corresponds to predicting output at time kTs,
where Ts is the sampling interval.
For example, suppose you use sensors to measure the input signal u(t) and
output signal y(t) of the physical system, described in the previous first-order
equation. At the tenth sampling instant (t = 10), the output y(10) is 16 mm
and the corresponding input u(10) is 12 N. Now, you want to predict the value
of the output at the future time t = 11. Using the previous equation:
In general, to predict the model response k steps into the future (k≥1) from
the current time t, you should know the inputs up to time t+k and outputs
up to time t:
yp(t+k) = f(u(t+k),u(t+k–1),...,u(t),u(t–1),...,u(0)
y(t),y(t–1),y(t–2),...,y(0))
u(0) and y(0) are the initial states. f() represents the predictor, which is a
dynamic model whose form depends on the model structure. For example, the
one-step-ahead predictor yp of the model y(t) + ay(t–1) = bu(t) is:
8-9
8 Model Analysis
Note Prediction with k=∞ means that no previous outputs are used in the
computation and prediction returns the same result as simulation.
Tip If you do not know the initial conditions and have input and output
measurements available, you can estimate the initial condition using this
toolbox.
You can validate linear parametric models and nonlinear models by checking
how well the simulated or predicted output of the model matches the
measured output. You can use either time or frequency domain data for
simulation or prediction. For frequency domain data, the simulation and
prediction results are products of the Fourier transform of the input and
frequency function of the model.
Simulation provides a better validation test for the model than prediction.
However, how you validate the model output should match how you plan to
use the model. For example, if you plan to use your model for control design,
you can validate the model by predicting its response over a time horizon that
represents the dominating time constants of the model.
8-10
Simulating and Predicting Model Output
See Also
“Simulation and Prediction in the GUI” on page 8-11
To include or exclude a model on the plot, click the corresponding model icon
in the System Identification Tool GUI. Active models display a thick line
inside the Model Board icon.
To learn how to interpret the model output plot, see “Interpreting the Model
Output Plot” on page 8-12.
To change plot settings, see “Changing Model Output Plot Settings” on page
8-13.
For general information about creating and working with plots, see “Working
with Plots in the System Identification Tool GUI” on page 11-15.
8-11
8 Model Analysis
The model output plot shows different information depending on the domain
of the input-output validation data, as follows:
8-12
Simulating and Predicting Model Output
For linear models, you can estimate a model using time-domain data, and
then validate the model using frequency domain data. For nonlinear models,
you can only use time-domain data for both estimation and validation.
The right side of the plot displays the percentage of the output that the model
reproduces (Best Fit), computed using the following equation:
⎛ y − yˆ ⎞
Best Fit = ⎜⎜ 1 − ⎟⎟ × 100
⎝ y− y ⎠
Because of the definition of Best Fit, it is possible for this value to be negative.
A negative best fit is worse than 0% and can occur for the following reasons:
8-13
8 Model Analysis
Action Command
Display confidence intervals. • To display the dashed lines on
either side of the nominal model
curve, select Options > Show
Note Confidence intervals are only confidence intervals. Select
available for simulated model output this option again to hide the
of linear models. Confidence internal confidence intervals.
are not available for nonlinear ARX
• To change the confidence
and Hammerstein-Wiener models.
value, select Options > Set %
confidence level, and choose a
value from the list.
See “Definition: Confidence Interval”
on page 8-15. • To enter your own confidence
level, select Options > Set
confidence level > Other.
Enter the value as a probability
(between 0 and 1) or as the
number of standard deviations of
a Gaussian distribution.
Change between simulated output • Select Options > Simulated
or predicted output. output or Options > k step
ahead predicted output.
• To change the prediction horizon,
Note Prediction is only available
select Options > Set prediction
for time-domain validation data.
horizon, and select the number
of samples.
• To enter your own prediction
horizon, select Options > Set
prediction horizon > Other.
Enter the value in terms of the
number of samples.
Display the actual output values Select Options > Signal plot or
(Signal plot), or the difference Options > Error plot.
between model output and measured
output (Error plot).
8-14
Simulating and Predicting Model Output
Action Command
(Time-domain validation data only) Select Options > Customized time
Set the time range for model output span for fit and enter the minimum
and the time interval for which the and maximum time values. For
Best Fit value is computed. example:
[1 20]
(Multiple-output system only) Select the output by name in the
Select a different output. Channel menu.
For example, for a 95% confidence interval, the region around the nominal
curve represents the range of values that have a 95% probability of being the
true system response. You can specify the confidence interval as a probability
(between 0 and 1) or as the number of standard deviations of a Gaussian
distribution. For example, a probability of 0.99 (99%) corresponds to 2.58
standard deviations.
Note The calculation of the confidence interval assumes that the model
sufficiently describes the system dynamics and the model residuals pass
independence tests.
In the GUI, you can display a confidence interval on the plot to gain insight
into the quality of a linear model. To learn how to show or hide confidence
interval, see “Changing Model Output Plot Settings” on page 8-13.
8-15
8 Model Analysis
Note If you estimated a linear model from detrended data and want to
simulate or predict the output at the original operation conditions, use the
retrend command to the simulated or predicted output.
Plots simulated or
predicted model
Note Omitting the third
output on top of the
argument assumes an
measured output.
infinite horizon and results in
You should use
simulation.
an independent
validation data set
as input to the model.
8-16
Simulating and Predicting Model Output
sim(model,data)
predict Predict and plot the To perform one-step-ahead
model output only. prediction of the response for
the model model and input
data data, use the following
command:
predict(model,data,1)
Simulation: Default initial conditions are zero for polynomial (idpoly and
idarx) models. For state-space (idss), low-order transfer functions (idproc),
and linear grey-box (idgrey) models, the default initial conditions are the
internal model initial states (model property x0). You can specify other initial
conditions using the InitialState argument in sim, as described in the next
example.
8-17
8 Model Analysis
If you use sim, the simulated and the measured responses might differ when
the initial conditions of the estimated model and the system that measured
the validation data set differ—especially at the beginning of the response. To
minimize this difference, estimate the initial state values from the data using
the findstates command and specify these initial states as input arguments
to the sim command. For example, to compute the initial states that optimize
the fit of the model m to the output data in z:
Prediction: Default initial conditions depend on the type of model. You can
specify other initial conditions using the InitialState argument in predict.
For example, to compute the initial states that optimize the 1-step-ahead
predicted response of the model m to the output data z:
[Yp,X0est] = predict(m,z,1,'InitialState','Estimate')
This command returns the estimated initial states as the output argument
X0est. For information about other ways to specify initials states, see the
predict reference page for the corresponding model type.
8-18
Simulating and Predicting Model Output
Create the ARMAX model and simulate output data with random binary
input u using the following commands:
⎡ −1 1 ⎤ ⎡ 1 ⎤ ⎡ 0 .5 ⎤
x = ⎢ ⎥ x + ⎢ ⎥u + ⎢ ⎥ e
⎣ −0.5 0 ⎦ ⎣ 0 .5 ⎦ ⎣ 0 .5 ⎦
y = [1 0] x + e
8-19
8 Model Analysis
Note The argument 'noise' specifies to simulate with the Gaussian noise e
present in the model. Omit this argument to simulate the noise-free response
to the input u, which is equivalent to setting e to zero.
8-20
Residual Analysis
Residual Analysis
In this section...
“What Is Residual Analysis?” on page 8-21
“Supported Model Types” on page 8-22
“What Residual Plots Show for Different Data Domains” on page 8-22
“Displaying the Confidence Interval” on page 8-23
“How to Plot Residuals Using the GUI” on page 8-24
“How to Plot Residuals at the Command Line” on page 8-26
“Example – Examining Model Residuals” on page 8-26
Residual analysis consists of two tests: the whiteness test and the
independence test.
According to the whiteness test criteria, a good model has the residual
autocorrelation function inside the confidence interval of the corresponding
estimates, indicating that the residuals are uncorrelated.
Your model should pass both the whiteness and the independence tests,
except in the following cases:
8-21
8 Model Analysis
For time-domain validation data, the plot shows the following two axes:
Note For time-series models, the residual analysis plot does not provide
any input-residual correlation plots.
8-22
Residual Analysis
For frequency-domain validation data, the plot shows the following two axes:
For linear models, you can estimate a model using time-domain data, and
then validate the model using frequency domain data. For nonlinear models,
the System Identification Toolbox product supports only time-domain data.
The following figure shows a sample Residual Analysis plot, created in the
System Identification Tool GUI.
8-23
8 Model Analysis
Note If you are working in the System Identification Tool GUI, you can
specify a custom confidence interval. If you are using the resid command, the
confidence interface is fixed at 99%.
For example, for a 95% confidence interval, the region around zero represents
the range of residual values that have a 95% probability of being statistically
insignificant. You can specify the confidence interval as a probability
(between 0 and 1) or as the number of standard deviations of a Gaussian
distribution. For example, a probability of 0.99 (99%) corresponds to 2.58
standard deviations.
To include or exclude a model on the plot, click the corresponding model icon
in the System Identification Tool GUI. Active models display a thick line
inside the Model Board icon.
8-24
Residual Analysis
Action Command
Display confidence • To display the dashed lines on either
intervals around zero. side of the nominal model curve, select
Options > Show confidence intervals.
Select this option again to hide the
Note Confidence internal confidence intervals.
are not available for
• To change the confidence value, select
nonlinear ARX and
Options > Set % confidence level and
Hammerstein-Wiener
choose a value from the list.
models.
• To enter your own confidence level, select
Options > Set confidence level > Other.
Enter the value as a probability (between
0 and 1) or as the number of standard
deviations of a Gaussian distribution.
Change the number of lags • Select Options > Number of lags and
(data samples) for which choose the value from the list.
to compute autocorellation
• To enter your own lag value, select
and cross-correlation
Options > Set confidence level > Other.
functions.
Enter the value as the number of data
samples.
Note For
frequency-domain
validation data, increasing
the number of lags
increases the frequency
resolution of the residual
spectrum and the transfer
function.
8-25
8 Model Analysis
pe(model,data)
resid Performs whiteness and To plot residual correlations
independence tests on model for the model model using
residuals, or prediction data data, type the following
errors. Uses validation data command:
input as model input.
resid(model,data)
ident('dryer2_linear_models')
2 To generate a residual analysis plot, select the Model resids check box in
the System Identification Tool GUI.
8-26
Residual Analysis
3 In the System Identification Tool window, click each model icon to display
it on the Residual Analysis plot.
Note For the nonparametric models, imp and spad, residual analysis plots
are not available.
8-27
8 Model Analysis
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 the output is formed from 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. The models arxqs and amx2222 extend
beyond the confidence interval and do not perform as well as the other models.
8-28
Residual Analysis
The Residual Analysis plot now includes only the three models that pass the
residual tests: arx692, n4s6, and amx3322.
The plots for these models fall within the confidence intervals. Thus, when
choosing the best model among several estimated models, it is reasonable to
pick amx3322 because it is a simpler, low-order model.
8-29
8 Model Analysis
Supported Models
You can plot the simulated response of a model using impulse and step
signals as the input for all linear parametric models and correlation analysis
(nonparametric) models.
You can also create step-response plots for nonlinear models. These step
and impulse response plots, also called transient response plots, provide
insight into the characteristics of model dynamics, including peak response
and settling time.
Transient response plots also help you validate how well a linear parametric
model, such as a linear ARX model or a state-space model, captures the
dynamics. For example, you can estimate an impulse or step response from
the data using correlation analysis (nonparametric model), and then plot the
8-30
Impulse and Step Response Plots
The impulse response of a dynamic model is the output signal that results
when the input is an impulse. That is, u(t) is zero for all values of t except at
t=0, where u(0)=1. In the following difference equation, you can compute the
impulse response by setting y(-T)=y(-2T)=0, u(0)=1, and u(t>0)=0.
The step response is the output signal that results from a step input, where
u(t<0)=0 and u(t>0)=1.
If your model includes a noise model, you can display the transient response
of the noise model associated with each output channel. For more information
about how to display the transient response of the noise model, see “How to
Plot Impulse and Step Response Using the GUI” on page 8-32.
8-31
8 Model Analysis
To include or exclude a model on the plot, click the corresponding model icon
in the System Identification Tool GUI. Active models display a thick line
inside the Model Board icon.
8-32
Impulse and Step Response Plots
Action Command
Display step response for linear Select Options > Step response.
or nonlinear model.
Display impulse response for Select Options > Impulse response.
linear model.
8-33
8 Model Analysis
Action Command
8-34
Impulse and Step Response Plots
Action Command
For example, for a 95% confidence interval, the region around the nominal
curve represents the range of values that have a 95% probability of being the
true system response. You can specify the confidence interval as a probability
(between 0 and 1) or as the number of standard deviations of a Gaussian
distribution. For example, a probability of 0.99 (99%) corresponds to 2.58
standard deviations.
Note The calculation of the confidence interval assumes that the model
sufficiently describes the system dynamics and the model residuals pass
independence tests.
8-35
8 Model Analysis
command(model,'sd',sd)
command(model,'sd',sd,'fill')
8-36
Impulse and Step Response Plots
step(mod,
'InputLevel',[u1;u2])
8-37
8 Model Analysis
y = Gu
In this case, the frequency function G(iw) is the transfer function evaluated
on the imaginary axis s=iw.
Y ( z) = G( z)U ( z)
In this case, the frequency function G(eiwT) is the transfer function G(z)
evaluated on the unit circle. The argument of the frequency function G(eiwT)
8-38
Frequency Response Plots
The frequency response of a linear dynamic model describes how the model
reacts to sinusoidal inputs. If the input u(t) is a sinusoid of a certain frequency,
then the output y(t) is also a sinusoid of the same frequency. However, the
magnitude of the response is different from the magnitude of the input signal,
and the phase of the response is shifted relative to the input signal.
Frequency response plots provide insight into linear systems dynamics, such
as frequency-dependent gains, resonances, and phase shifts. Frequency
response plots also contain information about controller requirements and
achievable bandwidths. Finally, frequency response plots can also help you
validate how well a linear parametric model, such as a linear ARX model or a
state-space model, captures the dynamics.
8-39
8 Model Analysis
• Bode plot of the model response. A Bode plot consists of two plots. The top
plot shows the magnitude G by which the transfer function G magnifies
the amplitude of the sinusoidal input. The bottom plot shows the phase
ϕ = arg G by which the transfer function shifts the input. The input to
the system is a sinusoid, and the output is also a sinusoid with the same
frequency.
• Bode plot of the disturbance model, called noise spectrum. This plot is the
same as a Bode plot of the model response, but it shows the frequency
response of the noise model instead. For more information, see “Noise
Spectrum Plots” on page 8-46.
• (Only in the MATLAB Command Window)
Nyquist plot. Plots the imaginary versus the real part of the transfer
function.
The following figure shows a sample Bode plot of the model dynamics, created
in the System Identification Tool GUI.
8-40
Frequency Response Plots
To include or exclude a model on the plot, click the corresponding model icon
in the System Identification Tool GUI. Active models display a thick line
inside the Model Board icon.
For example, for a 95% confidence interval, the region around the nominal
curve represents the range of values that have a 95% probability of being the
8-41
8 Model Analysis
true system response. You can specify the confidence interval as a probability
(between 0 and 1) or as the number of standard deviations of a Gaussian
distribution. For example, a probability of 0.99 (99%) corresponds to 2.58
standard deviations.
Action Command
Display the confidence • To display the dashed lines on either
interval. side of the nominal model curve, select
Options > Show confidence intervals.
Select this option again to hide the
confidence intervals.
• To change the confidence value, select
Options > Set % confidence level, and
choose a value from the list.
• To enter your own confidence level,
select Options > Set confidence
level > Other. Enter the value as a
probability (between 0 and 1) or as
the number of standard deviations of a
Gaussian distribution.
Change the frequency Select Options > Frequency range and
values for computing the specify a new frequency vector in units of
noise spectrum. rad/s.
The default frequency Enter the frequency vector using any one of
vector is 128 linearly following methods:
distributed values, greater
than zero and less than • MATLAB expression, such as
or equal to the Nyquist [1:100]*pi/100 or logspace(-3,-1,200).
frequency. Cannot contain variables in the MATLAB
workspace.
• Row vector of values, such as [1:.1:100]
8-42
Frequency Response Plots
Action Command
8-43
8 Model Analysis
command(model,'sd',sd)
command(model,'sd',sd,'fill')
The following table summarizes commands that generate Bode and Nyquist
plots for linear models. For detailed information about each command and
how to specify the frequency values for computing the response, see the
corresponding reference page.
8-44
Frequency Response Plots
nyquist(mod)
Note Does not support
time-series models.
8-45
8 Model Analysis
Supported Models
When you estimate the noise model of your linear system, you can plot the
spectrum of the estimated noise model. Noise-spectrum plots are available for
all linear parametric models and spectral analysis (nonparametric) models.
In this equation, G is an operator that takes the input to the output and
captures the system dynamics, and v is the additive noise term. The toolbox
treats the noise term as filtered white noise, as follows:
v(t) = H ( z) e(t)
The toolbox computes both H and λ during the estimation of the noise model
and stores these quantities as model properties. The H(z) operator represents
the noise model. e(t) is a white-noise source with variance λ .
8-46
Noise Spectrum Plots
( )
2
Φ v (ω) = λ H eiω
For time-series models (no input), the vertical axis of the noise-spectrum plot
is the same as the dynamic model spectrum. These axes are the same because
there is no input for time series and y = He .
Note You can avoid estimating the noise model by selecting the Output-Error
model structure or by setting the DisturbanceModel property value to 'None'
for a state space model. If you choose to not estimate a noise model for
your system, then H and the noise spectrum amplitude are equal to 1 at all
frequencies.
For example, for a 95% confidence interval, the region around the nominal
curve represents the range of values that have a 95% probability of being the
true system noise spectrum. You can specify the confidence interval as a
probability (between 0 and 1) or as the number of standard deviations of a
8-47
8 Model Analysis
Note The calculation of the confidence interval assumes that the model
sufficiently describes the system dynamics and the model residuals pass
independence tests.
To include or exclude a model on the plot, click the corresponding model icon
in the System Identification Tool GUI. Active models display a thick line
inside the Model Board icon.
8-48
Noise Spectrum Plots
Action Command
Display the confidence • To display the dashed lines on either side of the
interval. nominal model curve, select Options > Show
confidence intervals. Select this option
again to hide the confidence intervals.
• To change the confidence value, select
Options > Set % confidence level, and
choose a value from the list.
• To enter your own confidence level, select
Options > Set confidence level > Other.
Enter the value as a probability (between 0
and 1) or as the number of standard deviations
of a Gaussian distribution.
8-49
8 Model Analysis
Action Command
Change the frequency Select Options > Frequency range and specify
values for computing a new frequency vector in units of radians per
the noise spectrum. second.
The default frequency Enter the frequency vector using any one of
vector is 128 linearly following methods:
distributed values,
greater than zero and • MATLAB expression, such as [1:100]*pi/100
less than or equal to the or logspace(-3,-1,200). Cannot contain
Nyquist frequency. variables in the MATLAB workspace.
• Row vector of values, such as [1:.1:100]
8-50
Noise Spectrum Plots
Action Command
First, select the portion of the model object that corresponds to the noise
model H. For example, to select the noise model in the model object m, type
the following command:
m_noise=m('noise')
To plot the frequency-response of the noise model, use the bode command:
bode(m_noise)
To determine if your estimated noise model is good enough, you can compare
the frequency-response of the estimated noise-model H to the estimated
frequency response of v(t). To compute v(t), which represents the actual noise
term in the system, use the following commands:
ysimulated = sim(m,data);
v = ymeasured-ysimulated;
8-51
8 Model Analysis
V = spa(v);
The toolbox uses the following equation to compute the noise spectrum of
the actual noise:
∞
Φ v (ω) = ∑ Rv ( τ ) e−iωτ
τ=−∞
Rv ( τ ) = Ev ( t ) v ( t − τ )
bode(V,m('noise'))
If the parametric and the nonparametric estimates of the noise spectra are
different, then you might need a higher-order noise model.
8-52
Pole and Zero Plots
Supported Models
You can create pole-zero plots of linear input-output polynomial, state-space,
and grey-box models.
8-53
8 Model Analysis
In this equation, G is an operator that takes the input to the output and
captures the system dynamics, and v is the additive noise term.
The poles of a linear system are the roots of the denominator of the transfer
function G. The poles have a direct influence on the dynamic properties of
the system. The zeros are the roots of the numerator of G. If you estimated
a noise model H in addition to the dynamic model G, you can also view the
poles and zeros of the noise model.
Zeros and the poles are equivalent ways of describing the coefficients of a
linear difference equation, such as the ARX model. Poles are associated with
the output side of the difference equation, and zeros are associated with the
input side of the equation. The number of poles is equal to the number of
sampling intervals between the most-delayed and least-delayed output. The
number of zeros) is equal to the number of sampling intervals between the
8-54
Pole and Zero Plots
most-delayed and least-delayed input. For example, there two poles and one
zero in the following ARX model:
To include or exclude a model on the plot, click the corresponding model icon
in the System Identification Tool GUI. Active models display a thick line
inside the Model Board icon.
In addition, you can display a confidence interval for each pole and zero on the
plot. The confidence interval corresponds to the range of pole or zero values
with a specific probability of being the actual pole or zero of the system. The
toolbox uses the estimated uncertainty in the model parameters to calculate
confidence intervals and assumes the estimates have a Gaussian distribution.
For example, for a 95% confidence interval, the region around the nominal
pole or zero value represents the range of values that have a 95% probability
of being the true system pole or zero value. You can specify the confidence
interval as a probability (between 0 and 1) or as the number of standard
deviations of a Gaussian distribution. For example, a probability of 0.99 (99%)
corresponds to 2.58 standard deviations.
The following table summarizes the Zeros and Poles plot settings.
8-55
8 Model Analysis
Action Command
Display the confidence • To display the dashed lines on either side
interval. of the nominal pole and zero values, select
Options > Show confidence intervals.
Select this option again to hide the confidence
intervals.
• To change the confidence value, select
Options > Set % confidence level, and
choose a value from the list.
• To enter your own confidence level, select
Options > Set confidence level > Other.
Enter the value as a probability (between 0
and 1) or as the number of standard deviations
of a Gaussian distribution.
Show real and Select Style > Re/Im-axes. Select this option
imaginary axes. again to hide the axes.
Show the unit circle. Select Style > Unit circle. Select this option
again to hide the unit circle.
(Multiple-output system Select the output by name in the Channel menu.
only)
Select an input-output
pair to view the poles
and zeros corresponding
to those channels.
pzmap(model,'sd',sd)
8-56
Pole and Zero Plots
For detailed information about pzmap, see the corresponding reference page.
For example, you can use the following syntax to plot a 1-standard-deviation
confidence interval around model poles and zeros.
pzmap(model,'sd',1)
Always validate model output and residuals to see if the quality of the
fit changes after reducing model order. If the plot indicates pole-zero
cancellations, but reducing model order degrades the fit, then the extra
poles probably describe noise. In this case, you can choose a different model
structure that decouples system dynamics and noise. For example, try
ARMAX, Output-Error, or Box-Jenkins polynomial model structures with
an A or F polynomial of an order equal to that of the number of uncanceled
poles. For more information about estimating linear polynomial models, see
“Identifying Input-Output Polynomial Models” on page 3-39.
8-57
8 Model Analysis
Definition of FPE
Akaike’s Final Prediction Error (FPE) criterion provides a measure of model
quality by simulating the situation where the model is tested on a different
data set. After computing several different models, you can compare them
using this criterion. According to Akaike’s theory, the most accurate model
has the smallest FPE.
Note If you use the same data set for both model estimation and validation,
the fit always improves as you increase the model order and, therefore, the
flexibility of the model structure.
⎛1+ dN ⎞
FPE = V ⎜
⎜ 1 − d ⎟⎟
⎝ N⎠
The toolbox assumes that the final prediction error is asymptotic for d<<N
and uses the following approximation to compute FPE:
FPE = V (1 + 2 d N )
8-58
Akaike’s Criteria for Model Validation
⎛ N ⎞
( ) ( ε ( t, θ N ))
T
⎜ ∑
1
V = det ⎜ N ε t, θ N ⎟
⎟
⎝ 1 ⎠
Computing FPE
You can compute Akaike’s Final Prediction Error (FPE) criterion for linear
and nonlinear models.
Note FPE for nonlinear ARX models that include a tree partition
nonlinearity is not supported.
FPE = fpe(m1,m2,m3,...,mN)
According to Akaike’s theory, the most accurate model has the smallest FPE.
You can also access the FPE value of an estimated model by accessing the
FPE field of the EstimationInfo property of this model. For example, if you
estimated the model m, you can access its FPE using the following command:
m.EstimationInfo.FPE
Definition of AIC
Akaike’s Information Criterion (AIC) provides a measure of model quality
by simulating the situation where the model is tested on a different data
set. After computing several different models, you can compare them using
this criterion. According to Akaike’s theory, the most accurate model has
the smallest AIC.
Note If you use the same data set for both model estimation and validation,
the fit always improves as you increase the model order and, therefore, the
flexibility of the model structure.
8-59
8 Model Analysis
2d
AIC = log V +
N
⎛ N ⎞
( ) ( ε ( t, θ N ))
T
⎜ ∑
1
V = det ⎜ N ε t, θ N ⎟
⎟
⎝ 1 ⎠
For d<<N:
⎛ ⎛ 2d ⎞ ⎞
AIC = log ⎜ V ⎜ 1 + ⎟⎟
⎝ ⎝ N ⎠⎠
Computing AIC
Use the aic command to compute Akaike’s Information Criterion (AIC) for
one or more linear or nonlinear models, as follows:
AIC = aic(m1,m2,m3,...,mN)
According to Akaike’s theory, the most accurate model has the smallest AIC.
8-60
Computing Model Uncertainty
Note You can get model uncertainty data for linear parametric black-box
models, and both linear and nonlinear grey-box models. Supported model
objects include idproc, idpoly, idss, idarx, idgrey, idfrd, and idnlgrey.
8-61
8 Model Analysis
Computing the covariance matrix is based on the assumption that the model
structure gives the correct description of the system dynamics. For models
that include a disturbance model H, a correct uncertainty estimate assumes
that the model produces white residuals. To determine whether you can trust
the estimated model uncertainty values, perform residual analysis tests on
your model, as described in “Residual Analysis” on page 8-21. If your model
passes residual analysis tests, there is a good chance that the true system lies
within the confidence interval and any parameter uncertainties results from
random disturbances in the output.
8-62
Computing Model Uncertainty
• Simulated output values for linear models with standard deviations using
the sim command.
Call the sim command with output arguments, where the second output
argument is the estimated standard deviation of each output value.
For example, type [ysim,ysimsd]=sim(model,data), where ysim is
the simulated output, ysimsd contains the standard deviations on the
simulated output, and data is the simulation data.
8-63
8 Model Analysis
Troubleshooting Models
In this section...
“About Troubleshooting Models” on page 8-64
“Model Order Is Too High or Too Low” on page 8-64
“Nonlinearity Estimator Produces a Poor Fit” on page 8-65
“Substantial Noise in the System” on page 8-66
“Unstable Models” on page 8-66
“Missing Input Variables” on page 8-68
“Complicated Nonlinearities” on page 8-68
If the tips suggested in these sections do not help improve your models, then
a good model might not be possible for this data. For example, your data
might have poor signal-to-noise ratio, large and nonstationary disturbances,
or varying system properties.
8-64
Troubleshooting Models
When a low-order model fits the validation data poorly, try estimating a
higher-order model to see if the fit improves. For example, if a Model Output
plot shows that a fourth-order model gives poor results, try estimating an
eighth-order model. When a higher-order model improves the fit, you can
conclude that higher-order models might be required and linear models might
be sufficient.
You should use an independent data set to validate your models. If you
use the same data set to both estimate and validate a model, the fit always
improves as you increase model order, and you risk overfitting. However, if
you use an independent data set to validate your models, the fit eventually
deteriorates if your model orders are too high.
Note To see the model fit degrade when the nonlinearity estimator becomes
too complex, you must use an independent data set to validate the data that is
different from the estimation data set.
8-65
8 Model Analysis
B 1
y= u+ e
A A
To model noise more carefully, use the ARMAX or the Box-Jenkins model
structure, where the dynamics term and the noise term are modeled by
different polynomials.
Unstable Models
• For stable continuous-time models, the real part of the pole is less than 0.
• For stable discrete-time models, the magnitude of the pole is less than 1.
8-66
Troubleshooting Models
For more information about Threshold fields for linear models, see the
Algorithm Properties reference page.
8-67
8 Model Analysis
Try including other measured signals in your input data, and then estimating
the models again.
Inputs need not be control signals. Any measurable signal can be considered
an input, including measurable disturbances.
Complicated Nonlinearities
If the Model Output plot and Residual Analysis plot shows a poor fit, consider
if nonlinear effects are present in the system.
If your problem is sufficiently complex and you do not have physical insight
into the problem, you might try fitting nonlinear black-box models. For more
information, see Chapter 4, “Nonlinear Black-Box Model Identification”.
8-68
Next Steps After Getting an Accurate Model
Tip To export a model from the GUI, drag the model icon to the To
Workspace rectangle. For more information about working with the GUI,
see Chapter 11, “System Identification Tool GUI”.
If you have the Control System Toolbox software installed, you can import
your linear plant model for control-system design. For more information, see
“Using Models with Control System Toolbox Software” on page 9-2.
Finally, if you have Simulink software installed, you can exchange data
between the System Identification Toolbox software and the Simulink
8-69
8 Model Analysis
8-70
9
Control System Toolbox software also provides the LTI Viewer GUI to extend
System Identification Toolbox functionality for linear model analysis.
Note You can only use the System Identification Toolbox software to linearize
nonlinear ARX (idnlarx) and Hammerstein-Wiener (idnlhw) models.
Linearization of nonlinear grey-box (idnlgrey) models is not supported.
For information about using the Control System Toolbox software, see the
Control System Toolbox documentation.
9-2
Using Models with Control System Toolbox™ Software
For more information about using balred, see the corresponding reference
page. To learn how you can reduce model order using pole-zero plots, see
“Reducing Model Order Using Pole-Zero Plots” on page 8-57.
Control System Toolbox software provides both the SISO Design Tool GUI
and commands for working at the command line. You can import polynomial
and state-space models directly into SISO Design Tool using the following
command:
sisotool(model('measured'))
where you use only the dynamic model and not the noise model. For more
information about subreferencing the dynamic or the noise model, see
“Subreferencing Measured and Noise Models” on page 3-121. To design a
controller using Control System Toolbox commands and methods at the
command line, you must convert the plant model to an LTI object. For more
information, see “Converting Models to LTI Objects” on page 9-4.
9-3
9 Control Design Applications
For more information about controller design using SISO Design Tool
and Control System Toolbox commands, see the Control System Toolbox
documentation.
You can convert linear polynomial, state-space, and grey-box model objects,
including idarx, idpoly, idproc, idss, or idgrey, to LTI objects.
tf Convert to
transfer-function form. tf_sys = tf(model)
9-4
Using Models with Control System Toolbox™ Software
model = model('measured')
% Convert to LTI object
LTI_sys = idss(model)
The LTI object includes only the dynamic model and not the noise model,
which is estimated for every linear model in the System Identification Toolbox
software.
Note To include noise channels in the LTI models, first use noisecnv to
convert the noise in the idmodel object to measured channels, and then
convert to an LTI object.
For more information about subreferencing the dynamic or the noise model,
see “Subreferencing Measured and Noise Models” on page 3-121.
The LTI Viewer is a graphical user interface for viewing and manipulating
the response plots of linear models.
For more information about working with plots in the LTI Viewer, see the
Control System Toolbox documentation.
9-5
9 Control Design Applications
Alternatively, use the following syntax when working at the command line
to view a model in the LTI Viewer:
view(model)
For example, you can perform the following operations on identified models:
• G1+G2
• G1*G2
• append(G1,G2)
• feedback(G1,G2)
9-6
Using Models with Control System Toolbox™ Software
9-7
9 Control Design Applications
9-8
10
System Identification
Toolbox Blocks
You can use the System Identification Toolbox block library to perform the
following tasks:
10-2
Opening the System Identification Toolbox™ Block Library
You can also open the System Identification Toolbox block library directly by
typing the following command at the MATLAB prompt:
slident
For more information about blocks, see “Block Reference” in the System
Identification Toolbox Reference. To get help on a specific block, right-click
the block in the Library Browser, and select Help.
10-3
10 System Identification Toolbox™ Blocks
Preparing Data
The following table summarizes the blocks you use to transfer data between
the MATLAB and Simulink environments.
After you add a block to the Simulink model, double-click the block to specify
block parameters. For an example of bringing data into a Simulink model,
see the tutorial on estimating process models in the System Identification
Toolbox Getting Started Guide.
Block Description
Iddata Sink Export input and output signals to the MATLAB
workspace as an iddata object.
Iddata Source Import iddata object from the MATLAB
workspace.
Input and output ports of the block correspond
to input and output signals of the data. These
inputs and outputs provide signals to blocks that
are connected to this data block.
For information about configuring each block, see the corresponding reference
pages.
10-4
Identifying Linear Models
After you add a block to the model, double-click the block to specify block
parameters.
Block Description
AutoRegressive model Estimate AR model parameters from time-series
estimator data, which has one output and no input.
AutoRegressive Moving Estimate ARMAX model parameters from
Average with eXternal input/output data.
input model estimator
AutoRegressive with Estimate ARX model parameters from
eXternal input model input/output data.
estimator
Box-Jenkins model Estimate BJ model parameters from input/output
estimator data.
Output-error model Estimate OE model parameters from
estimator input/output data.
For information about configuring each block, see the corresponding reference
pages.
10-5
10 System Identification Toolbox™ Blocks
You use the model simulation blocks to import the models you identified using
System Identification Toolbox software from the MATLAB workspace into the
Simulink environment. For a list of System Identification Toolbox simulation
blocks, see “Summary of Simulation Blocks” on page 10-6.
Block Description
Idmodel Simulate idmodel model in Simulink, including
low-order transfer function (idproc), linear
polynomial (idpoly), state-space (idss), and
grey-box (idgrey) models. Also simulates idarx
model objects.
Nonlinear ARX Model Simulate idnlarx model in Simulink.
10-6
Simulating Model Output
Block Description
Hammerstein-Wiener Simulate idnlhw model in Simulink.
Model
Nonlinear Grey-Box Simulate nonlinear ODE (idnlgrey model object)
Model in Simulink.
After you import the model into Simulink software, use the block parameter
dialog box to specify the initial conditions for simulating that block. (See
“Specifying Initial Conditions for Simulation” on page 10-7.) For information
about configuring each block, see the corresponding reference pages.
For more information on specifying initial conditions, see the following topics:
For idpoly and idarx models, the default initial states values are zero. If
you want to specify different values, such as maximize fit to a given output
10-7
10 System Identification Toolbox™ Blocks
data, convert the model to idss object, and then specify its initial states as
described previously. For example, for the following idpoly model:
m2=idss(m1);
For more information about specifying initial conditions for simulation, see
the IDMODEL Model reference page.
For simulating nonlinear ARX models, you can specify the initial conditions
as input/output values, or as a vector. For more information about specifying
initial conditions for simulation, see the IDNLARX Model reference page.
10-8
Example – Simulating a Model Using Simulink® Software
Prerequisites
When you estimate a model using multiple data sets, the initial-states
property, X0, of the model, M, stores only the estimated states corresponding to
the last data set. In this example:
• Values of M.X0 are the estimated state values, corresponding to the last
experiment in Z.
• M.X0 is a vector of length 5, corresponding to the five states of the model.
To compute initial states that maximizes the fit to the corresponding output
y2, and simulate the model using the second experiment:
X0est = findstates(M,z2);
10-9
10 System Identification Toolbox™ Blocks
slident
3 Open a new Simulink model window. Then, drag and drop an Idmodel
block from the library into the model window.
b In the Initial states field, type X0est to specify the estimated initial
states.
c Click OK.
5 Drag and drop an Iddata Source block into the model window. Then,
configure the model, as shown in the following figure.
6 Simulate the model for 2 seconds, and compare the simulated output ysim
with the measured output ymeasured using the Scope block.
10-10
11
• “Steps for Using the System Identification Tool GUI” on page 11-2
• “Starting and Managing GUI Sessions” on page 11-3
• “Managing Models in the GUI” on page 11-9
• “Working with Plots in the System Identification Tool GUI” on page 11-15
• “Customizing the System Identification Tool GUI” on page 11-20
11 System Identification Tool GUI
2 Start a new session in the System Identification Tool GUI, or open a saved
session. For more information, see “Starting a New Session in the GUI”
on page 11-4.
3 Import data into the GUI from the MATLAB workspace. For more
information, see “Importing Data into the GUI” on page 2-14.
5 Specify the data for estimation and validation. For more information, see
“Specifying Estimation and Validation Data” on page 2-31.
6 Select the model to estimating using the Estimate menu. For more
information, see Chapter 1, “Choosing Your System Identification
Approach”.
11-2
Starting and Managing GUI Sessions
You can save a session to a file with a .sid extension. For example, you can
save different stages of your progress as different sessions so that you can
revert to any stage by simply opening the corresponding session.
To start a new session, see “Starting a New Session in the GUI” on page 11-4.
For more information about the steps for using the System Identification Tool
GUI, see “Steps for Using the System Identification Tool GUI” on page 11-2.
11-3
11 System Identification Tool GUI
ident
You can also start a new session by closing the current session using
File > Close session. This toolbox prompts you to save your current session
if it is not already saved.
11-4
Starting and Managing GUI Sessions
The layout of the window organizes tasks and information from left to right.
This organization follows a typical workflow, where you start in the top-left
corner by importing data into the System Identification Tool GUI using
11-5
11 System Identification Tool GUI
the Import data menu and end in the bottom-right corner by plotting the
characteristics of your estimated model on model plots. For more information
about using the System Identification Tool GUI, see “Steps for Using the
System Identification Tool GUI” on page 11-2.
The Data Board area, located below the Import data menu in the System
Identification Tool GUI, contains rectangular icons that represent the data
you imported into the GUI.
The Model Board, located to the right of the <--Preprocess menu in the
System Identification Tool GUI, contains rectangular icons that represent the
models you estimated or imported into the GUI. You can drag and drop model
icons in the Model Board into open dialog boxes.
ident(session,path)
session is the file name of the session you want to open and path is the
location of the session file. Session files have the extension .sid. When the
session file in on the matlabpath, you can omit the path argument.
If the System Identification Tool GUI is already open, you can open a session
by selecting File > Open session.
Note If there is data in the System Identification Tool GUI, you must
close the current session before you can open a new session by selecting
File > Close session.
11-6
Starting and Managing GUI Sessions
Deleting a Session
To delete a saved session, you must delete the corresponding session file.
Contextual help is available from each dialog box by clicking the Help button
in the dialog box.
11-7
11 System Identification Tool GUI
Tip Alternatively, select File > Exit System Identification Tool GUI.
11-8
Managing Models in the GUI
The following procedure assumes that you begin with the System
Identification Tool GUI already open. If this window is not open, type the
following command at the prompt:
ident
1 In the System Identification Tool GUI, select Import from the Import
models list to open the Import Model Object dialog box.
2 In the Enter the name field, type the name of a model object. Press Enter.
3 (Optional) In the Notes field, type any notes you want to store with this
model.
4 Click Import.
11-9
11 System Identification Tool GUI
The Data/model Info dialog box opens. This dialog box describes the contents
and the properties of the corresponding model. It also displays any associated
notes and the command-line equivalent of the operations you used to create
this model.
Tip To view or modify properties for several models, keep this window
open and right-click each model in the System Identification Tool GUI. The
Data/model Info dialog box updates when you select each model.
11-10
Managing Models in the GUI
The Data/model Info dialog box opens. This dialog box describes both the
contents and the properties of the model. The object description area displays
the syntax of the operations you used to create the model in the GUI.
To rename the model, enter a new name in the Model name field.
You can also specify a new display color using three RGB values in the Color
field. Each value is between 0 to 1 and indicates the relative presence of
red, green, and blue, respectively. For more information about specifying
default data color, see “Customizing the System Identification Tool GUI” on
page 11-20.
Tip As an alternative to using three RGB values, you can enter any one of
the following letters in single quotes:
These strings represent yellow, red, blue, cyan, green, magenta, and black,
respectively.
Finally, you can enter comments about the origin and state of the model in
the Diary And Notes area.
Note You cannot drag and drop a model icon into the data area on the left.
11-11
11 System Identification Tool GUI
When you need additional space for organizing model icons, select
Options > Extra model/data board in the System Identification Tool GUI.
This action opens an extra session window with blank rectangles. The new
window is an extension of the current session and does not represent a new
session.
Tip When you import or estimate models and there is insufficient space for
the icons, an additional session window opens automatically.
You can drag and drop model icons between the main System Identification
Tool GUI and any extra session windows.
Type comments in the Notes field to describe the models. When you save a
session, as described in “Saving, Merging, and Closing Sessions” on page 11-6,
all additional windows and notes are also saved.
11-12
Managing Models in the GUI
To restore a model from Trash, drag its icon from Trash to the Model Board
in the System Identification Tool GUI. You can view the Trash contents
by double-clicking the Trash icon.
Note You must restore a model to the Model Board; you cannot drag model
icons to the Data Board.
To permanently delete all items in Trash, select Options > Empty trash.
11-13
11 System Identification Tool GUI
When you export models to the MATLAB workspace, the resulting variables
have the same name as in the System Identification Tool GUI.
11-14
Working with Plots in the System Identification Tool GUI
You can also display data tips for each line on the plot by clicking a plot curve
and holding down the mouse button.
Note You must disable zoom by selecting Style > Zoom before you can
display data tips. For more information about enabling zoom, see “Magnifying
Plots” on page 11-16.
The following figure shows an example of a data tip, which contains the name
of the data set and the coordinates of the data point.
11-15
11 System Identification Tool GUI
Magnifying Plots
Enable zoom by selecting Style > Zoom in the plot window. To disable zoom,
select Style > Zoom again.
Tip To verify that zoom is active, click the Style menu. A check mark should
appear next to Zoom.
11-16
Working with Plots in the System Identification Tool GUI
• To zoom in default increments, left-click the portion of the plot you want to
center in the plot window.
• To zoom in on a specific region, click and drag a rectangle that identifies
the region for magnification. When you release the mouse button, the
selected region is displayed.
• To zoom out, right-click on the plot.
1 Select Options > Set axes limits to open the Limits dialog box.
2 Specify a new range for each axis by editing its lower and upper limits. The
limits must be entered using the format [LowerLimit UpperLimit]. Click
Apply. For example:
[0.1 100]
Note To restore full axis limits, select the Auto check box to the right
of the axis name, and click Apply.
3 To plot data on a linear scale, clear the Log check box to the right of the
axis name, and click Apply.
Note To revert to base-10 logarithmic scale, select the Log check box to
the right of the axis name, and click Apply.
4 Click Close.
11-17
11 System Identification Tool GUI
Note To view the entire data range, select Options > Autorange in the
plot window.
Note When you select to plot multiple data sets, and each data set contains
several input and output channels, the Channel menu lists channel pairs
from all data sets.
You can select a different input-output channel pair from the Channel menu
in any System Identification Toolbox plot window.
The Channel menu uses the following notation for channels: u1->y2 means
that the plot displays a transfer function from input channel u1 to output
channel y2. System Identification Toolbox estimates as many noise sources as
there are output channels. In general, e@ynam indicates that the noise source
corresponds to the output with name ynam.
For example, e@y3->y1 means that the transfer function from the noise
channel (associated with y3) to output channel y2 is displayed. For more
information about noise channels, see “Subreferencing Measured and Noise
Models” on page 3-121.
Tip When you import data into the System Identification Tool GUI, it is
helpful to assign meaningful channel names in the Import Data dialog box.
For more information about importing data, see “Importing Data into the
GUI” on page 2-14.
11-18
Working with Plots in the System Identification Tool GUI
Grid Lines
To toggle showing or hiding grid lines, select Style > Grid.
To display all solid lines, select Style > All solid lines. This choice is the
default.
All line styles match the color of the corresponding data or model icon in
the System Identification Tool GUI.
After you create the plot, as described in “Plotting Models in the GUI” on page
8-5, select File > Copy figure in the plot window. This command opens the
plot in a MATLAB Figure window.
Printing Plots
To print a System Identification Toolbox plot, select File > Print in the plot
window. In the Print dialog box, select the printing options and click OK.
11-19
11 System Identification Tool GUI
You can save the session to save the customized GUI state.
Advanced users might choose to edit the file that controls default settings, as
described in “Modifying idlayout.m” on page 11-21.
11-20
Customizing the System Identification Tool GUI
midprefs('c:\matlab\toolbox\local\')
You can also type midprefs and browse to the desired folder.
Modifying idlayout.m
Advanced users might want to customize the default plot options by editing
idlayout.m.
Caution Do not edit the original file to avoid overwriting the idlayout.m
defaults shipped with the product.
11-21
11 System Identification Tool GUI
Note When you save preferences using Options > Save preferences
to idprefs.mat, these preferences override the defaults in idlayout.m.
To give idlayout.m precedence every time you start a new session, select
Options > Default preferences.
11-22
Index
A
Index confidence interval
active impulse response plot 8-35
model in GUI 8-5 model output plot 8-15
advice noise spectrum plot 8-47
for data 2-87 residual plot 8-23
for models 8-7 step response plot 8-35
AIC 8-58 confidence interval on plots 8-62
definition 8-59 constructor 1-15
Akaike’s Final Prediction Error (FPE) 8-58 continuous-time models
Akaike’s Information Criterion (AIC) 8-58 supported 1-10
Algorithm property 1-18 continuous-time process models 3-20
algorithms for estimation Control System Toolbox
recursive 7-6 combining model objects 9-6
spectral models 3-5 converting models to LTI objects 9-4
aliasing effects 2-105 for compensator design 9-3
AR 6-7 LTI Viewer 9-5
ARMA 6-7 reducing model order 9-3
ARMAX 3-42 correlation analysis 3-11
ARX 3-42 covariance 8-61
ARX Model Structure Selection window 3-54 CovarianceMatrix 8-61
cra 3-14
cross-validation 8-3
B
best fit
D
definition 8-12
negative value 8-13 D matrix 3-90
BJ model. See Box-Jenkins model d2c 3-113
Bode plot 8-40 d2d 3-113
Box-Jenkins model 3-42 data
Burg’s method 6-11 creating iddata object 2-49
creating idfrd object 2-69
creating subsets 2-33
C detrending 2-97
c2d 3-113 exporting to MATLAB workspace 2-47
canonical parameterization 3-92 filter 2-109
complex data 2-133 frequency-domain 2-9
concatenating frequency-response 2-11
iddata objects 2-66 importing into System Identification Tool
idfrd objects 2-73 GUI 2-14
models 3-125 managing in GUI 2-14
Index-1
Index
E
H
estimating models
black-box polynomial 3-39 Hammerstein-Wiener models 4-49
commands 1-12
frequency response 3-2 I
Hammerstein-Wiener 4-49
idarx 1-16
linear grey-box 5-6
iddata
nonlinear ARX 4-8
concatenating 2-66
nonlinear grey-box 5-16
creating 2-49
process models 3-20
subreferencing 2-57
recursive estimation 7-2
ident 11-4
state-space 3-73
idfrd
Index-2
Index
concatenating 2-73 M
creating 2-69 MDL 3-53
model 1-16 merging
subreferencing 2-72 data 2-35
idgrey 1-16 models 3-129
idlayout.m 11-21 methods 1-14
idnlarx 1-16 missing data 2-93
idnlgrey 1-16 model
idnlhw 1-16 black-box polynomial 3-39
idpoly 1-16 estimating frequency response 3-2
idproc 1-16 estimating process model 3-20
idss 1-16 estimating transient response 3-11
importing exporting to MATLAB workspace 11-13
data into System Identification Tool grey-box estimation 5-1
GUI 2-14 Hammerstein-Wiener estimation 4-49
impulse response importing into GUI 11-9
computing values 3-15 linear grey-box estimation 5-6
confidence interval 8-35 managing in GUI 11-9
definition 3-11 nonlinear ARX estimation 4-8
estimating in the GUI 3-12 nonlinear black-box estimation 4-1
impulse 3-14 nonlinear grey-box estimation 5-16
impulse-response plot 8-30 ordinary difference equation 5-1
independence test 8-21 ordinary differential equation 5-1
plotting 8-4
K properties 1-17
recursive estimation 7-2
K matrix 3-90
reducing order using balred 9-3
Kalman filter algorithm 7-8
reducing order using pole-zero plot 8-57
refining linear parametric 3-104
L renaming in GUI 11-11
linear grey-box models 5-6 state-space 3-73
linear models time-series 6-1
extracting numerical data 3-109 uncertainty 8-61
transforming between continuous and validating 8-2
discrete time 3-113 viewing properties in GUI 11-10
transforming between structures 3-118 Model Board 11-6
LTI Viewer 9-5 arranging icons 11-11
deleting icons 11-12
model object
concatenating 3-125
Index-3
Index
Index-4
Index
Index-5
Index
Index-6