System Identification Toolbox™ User's Guide: Lennart Ljung
System Identification Toolbox™ User's Guide: Lennart Ljung
User's Guide
R2014b
Lennart Ljung
How to Contact MathWorks
Phone: 508-647-7000
v
Recommended Model Estimation Sequence . . . . . . . . . . . . . 1-30
vi Contents
Time-Series Data Representation . . . . . . . . . . . . . . . . . . . . 2-10
Frequency-Domain Data Representation . . . . . . . . . . . . . . . 2-11
vii
Create Multiexperiment Data at the Command Line . . . . . 2-60
Why Create Multiexperiment Data Sets? . . . . . . . . . . . . . . 2-60
Limitations on Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . 2-60
Entering Multiexperiment Data Directly . . . . . . . . . . . . . . . 2-60
Merging Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-61
Adding Experiments to an Existing iddata Object . . . . . . . . 2-61
viii Contents
Handling Offsets and Trends in Data . . . . . . . . . . . . . . . . . 2-108
When to Detrend Data . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-108
Alternatives for Detrending Data in App or at the Command-
Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-109
Next Steps After Detrending . . . . . . . . . . . . . . . . . . . . . . . 2-110
ix
Transforming Between Time- and Frequency-Domain Data 2-137
Transforming Data Domain in the App . . . . . . . . . . . . . . . 2-137
Transforming Data Domain at the Command Line . . . . . . 2-141
x Contents
Process Model Structure Specification . . . . . . . . . . . . . . . . . 3-35
Estimating Multiple-Input, Multi-Output Process Models . . 3-36
Disturbance Model Structure for Process Models . . . . . . . . . 3-37
Assigning Estimation Weightings . . . . . . . . . . . . . . . . . . . . 3-37
Specifying Initial Conditions for Iterative Estimation
Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-38
xi
Refine Linear Parametric Models Using System Identification
App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-86
Refine Linear Parametric Models at the Command Line . . . 3-88
xii Contents
Concatenating Noise Spectrum Data of idfrd Objects . . . . . 3-122
See Also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-123
xiii
Estimate State-Space Models at the Command Line . . . . . . 4-21
Black Box vs. Structured State-Space Model Estimation . . . 4-21
Estimating State-Space Models Using ssest, ssregest and
n4sid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-22
Choosing the Structure of A, B, C Matrices . . . . . . . . . . . . . 4-23
Choosing Between Continuous-Time and Discrete-Time
Representations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-23
Choosing to Estimate D, K, and X0 Matrices . . . . . . . . . . . . 4-24
xiv Contents
Nonlinear Black-Box Model Identification
5
About Nonlinear Model Identification . . . . . . . . . . . . . . . . . . 5-2
What Are Nonlinear Models? . . . . . . . . . . . . . . . . . . . . . . . . 5-2
When to Fit Nonlinear Models . . . . . . . . . . . . . . . . . . . . . . . 5-2
Available Nonlinear Models . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
xv
Choosing Your Linear Approximation Approach . . . . . . . . . 5-81
Linear Approximation of Nonlinear Black-Box Models for a
Given Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-81
Tangent Linearization of Nonlinear Black-Box Models . . . . 5-82
Computing Operating Points for Nonlinear Black-Box
Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-83
xvi Contents
Time Series Identification
7
What Are Time-Series Models? . . . . . . . . . . . . . . . . . . . . . . . . 7-2
xvii
Algorithms for Recursive Estimation . . . . . . . . . . . . . . . . . . . 8-4
Types of Recursive Estimation Algorithms . . . . . . . . . . . . . . 8-4
General Form of Recursive Estimation Algorithm . . . . . . . . . 8-4
Kalman Filter Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5
Forgetting Factor Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 8-7
Unnormalized and Normalized Gradient Algorithms . . . . . . . 8-9
Online Estimation
9
What Is Online Estimation? . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-3
xviii Contents
State Estimation Using Time-Varying Kalman Filter . . . . . 9-48
Model Analysis
10
Validating Models After Estimation . . . . . . . . . . . . . . . . . . . 10-2
Ways to Validate Models . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2
Data for Model Validation . . . . . . . . . . . . . . . . . . . . . . . . . . 10-3
Supported Model Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-3
Definition of Confidence Interval for Specific Model Plots . . 10-4
How to Plot Impulse and Step Response Using the App . . 10-34
xix
How to Plot Impulse and Step Response at the Command
Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-36
How to Plot Model Poles and Zeros Using the App . . . . . . 10-58
xx Contents
Labels Pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-70
Limits Pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-70
Units Pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-71
Style Pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-77
Options Pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-77
Editing Subplots Using the Property Editor . . . . . . . . . . . 10-78
xxi
Options Pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-8
xxii Contents
System Identification App
14
Steps for Using the System Identification App . . . . . . . . . . 14-2
xxiii
xxiv
1
Acknowledgments
System Identification Toolbox™ software is developed in association with the following
leading researchers in the system identification field:
Peter Lindskog. Dr. Peter Lindskog is employed by NIRA Dynamics AB, Sweden. He
conducts research in the areas of system identification, signal processing, and automatic
control with a focus on vehicle industry applications.
Anatoli Juditsky. Professor Anatoli Juditsky is with the Laboratoire Jean Kuntzmann
at the Université Joseph Fourier, Grenoble, France. He conducts research in the areas of
nonparametric statistics, system identification, and stochastic optimization.
1-2
What Are Model Objects?
1-3
1 Choosing Your System Identification Approach
Other model attributes stored as model data include time units, names for the model
inputs or outputs, and time delays.
Note: All model objects are MATLAB® objects, but working with them does not require
a background in object-oriented programming. To learn more about objects and object
syntax, see “Classes in the MATLAB Language” in the MATLAB documentation.
More About
• “Types of Model Objects” on page 1-5
1-4
Types of Model Objects
The diagram illustrates the following two overlapping broad classifications of model
object types:
1-5
1 Choosing Your System Identification Approach
• Dynamic System Models vs. Static Models — In general, Dynamic System Models
represent systems that have internal dynamics, while Static Models represent static
input/output relationships.
• Numeric Models vs. Generalized Models — Numeric Models are the basic
numeric representation of linear systems with fixed coefficients. Generalized Models
represent systems with tunable or uncertain components.
More About
• “What Are Model Objects?” on page 1-3
• “Dynamic System Models” on page 1-7
• “Numeric Models” on page 1-9
1-6
Dynamic System Models
Most commands for analyzing linear systems, such as bode, margin, and ltiview, work
on most Dynamic System Model objects. For Generalized Models, analysis commands use
the current value of tunable parameters and the nominal value of uncertain parameters.
1-7
1 Choosing Your System Identification Approach
More About
• “Numeric Linear Time Invariant (LTI) Models” on page 1-9
• “Identified LTI Models” on page 1-9
• “Identified Nonlinear Models” on page 1-10
1-8
Numeric Models
Numeric Models
The following table summarizes the available types of numeric LTI models.
The following table summarizes the available types of identified LTI models.
1-9
1 Choosing Your System Identification Approach
The following table summarizes the available types of identified nonlinear models.
1-10
About Identified Linear Models
Models that only have the noise component H are called time-series or signal models.
Typically, you create such models using time-series data that consist of one or more
outputs y(t) with no corresponding input.
The total output is the sum of the contributions from the measured inputs and the
disturbances: y = G u + H e, where u represents the measured inputs and e the
disturbance. e(t) is modeled as zero-mean Gaussian white noise with variance Λ. The
following figure illustrates an IDLTI model.
IDLTI
H
u y
G
1-11
1 Choosing Your System Identification Approach
When you simulate an IDLTI model, you study the effect of input u(t) (and possibly
initial conditions) on the output y(t). The noise e(t) is not considered. However, with
finite-horizon prediction of the output, both the measured and the noise components of
the model contribute towards computation of the (predicted) response.
u
H-1G
y_predicted
y_measured
1-H -1
1-12
About Identified Linear Models
1-13
1 Choosing Your System Identification Approach
1
y( s) = K p e-sTd u( s) + e(s).
( Tp1 s + 1)
1 1 + c1 s
y( s) = K p e-sTd u( s) + e( s)
( Tp1 s + 1) 1 + d1 s
1-14
About Identified Linear Models
Sometimes, fixing coefficients or specifying bounds on the parameters are not sufficient.
For example, you may have unrelated parameter dependencies in the model or
parameters may be a function of a different set of parameters that you want to identify
exclusively. For example, in a mass-spring-damper system, the A and B parameters
both depend on the mass of the system. To achieve such parameterization of linear
models, you can use grey-box modeling where you establish the link between the actual
parameters and model coefficients by writing an ODE file. To learn more, see “Grey-Box
Model Estimation”.
The estimation function treats the noise variable e(t) as prediction error – the
residual portion of the output that cannot be attributed to the measured inputs. All
estimation algorithms work to minimize a weighted norm of e(t) over the span of
available measurements. The weighting function is defined by the nature of the noise
transfer function H and the focus of estimation, such as simulation or prediction error
minimization.
In a black-box estimation, you only have to specify the order to configure the structure of
the model.
1-15
1 Choosing Your System Identification Approach
where estimator is the name of an estimation command to use for the desired model
type.
For example, you use tfest to estimate transfer function models, arx for ARX-structure
polynomial models, and procest for process models.
The first argument, data, is time- or frequency domain data represented as an iddata
or idfrd object. The second argument, orders, represents one or more numbers whose
definitions depends upon the model type:
• For transfer functions, orders refers to the number of poles and zeros.
• For state-space models, orders is a scalar that refers to the number of states.
• For process models, orders is a string denoting the structural elements of a process
model, such as, the number of poles and presence of delay and integrator.
When working with the app, you specify the orders in the appropriate edit fields of
corresponding model estimation dialogs.
Structured Estimations
In some situations, you want to configure the structure of the desired model more closely
than what is achieved by simply specifying the orders. In such cases, you construct a
template model and configure its properties. You then pass that template model as an
input argument to the estimation commands in place of orders.
To illustrate, the following example assigns initial guess values to the numerator and the
denominator polynomials of a transfer function model, imposes minimum and maximum
bounds on their estimated values, and then passes the object to the estimator function.
The estimation algorithm uses the provided initial guesses to kick-start the estimation
and delivers a model that respects the specified bounds.
1-16
About Identified Linear Models
You can use such a model template to also configure auxiliary model properties such
as input/output names and units. If the values of some of the model’s parameters are
initially unknown, you can use NaNs for them in the template.
Estimation Options
There are many options associated with a model’s estimation algorithm that
configure the estimation objective function, initial conditions and numerical search
algorithm, among other things. For every estimation command, estimator, there
is a corresponding option command named estimatorOptions. To specify options
for a particular estimator command, such as tfest, use the options command that
corresponds to the estimation command, in this case, tfestOptions. The options
command returns an options set that you then pass as an input argument to the
corresponding estimation command.
For example, to estimate an Output-Error structure polynomial model, you use oe.
To specify simulation as the focus and lsqnonlin as the search method, you use
oeOptions:
load iddata1 z1
Options = oeOptions('Focus','simulation','SearchMethod','lsqnonlin');
sys= oe(z1, [2 2 1], Options);
For information about how to view the list of options used to create an estimated model,
see “Estimation Report” on page 1-17.
Estimation Report
The model returned by the estimation command contains information about the
estimation operation in the Report property. Information includes:
1-17
1 Choosing Your System Identification Approach
• The option set used for estimation under a category called OptionsUsed
sys.Report
FitPercent: 70.5666
FPE: 1.7558
LossFcn: 1.7094
MSE: 1.6865
1-18
Linear Model Structures
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 “Available Linear
Models” on page 1-20 and “Available Nonlinear Models” on page 1-29.
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, an
idpoly model has an InputName property for storing one or more input channel names.
Different model objects have different properties.
The allowed operations on an object are called methods. In System Identification Toolbox
software, some methods have the same name but apply to multiple model objects. For
example, bode creates a bode plot for all linear model objects. However, other methods
are unique to a specific model object. For example, the estimation method canon is
unique to the state-space idss model.
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
1-19
1 Choosing Your System Identification Approach
the name of the class representing linear black-box polynomial models and the name of
the constructor for instantiating the model object.
num
y= u+ e
den
1-20
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.
1-21
1 Choosing Your System Identification Approach
You must construct the model object independently of estimation when you want to:
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 tfest creates a transfer function model using data and some
information on the order of the model - the number of poles and zeros. For information
about how to both construct and estimate models with a single command, see “Model
Estimation Commands” on page 1-37.
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.
1-22
Linear Model Structures
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 “Model Estimation Commands” on page 1-37.
• ARX
• ARMAX
• Output-Error
• Box-Jenkins
idss Linear state-space models.
idtf Linear transfer function models.
idgrey Linear ordinary differential or difference equations
(grey-box models). You write a function that translates
user parameters to state-space matrices. Can also
be viewed as state-space models with user-specified
parameterization.
idnlgrey Nonlinear ordinary differential or difference equation
(grey-box models). You write a function or MEX-file to
represent the governing equations.
idnlarx Nonlinear ARX models, which define the predicted
output as a nonlinear function of past inputs and
outputs.
idnlhw Nonlinear Hammerstein-Wiener models, which
include a linear dynamic system with nonlinear static
transformations of inputs and outputs.
1-23
1 Choosing Your System Identification Approach
For more information about when to use these commands, see “When to Construct a
Model Structure Independently of Estimation” on page 1-22.
Model Properties
• “Categories of Model Properties” on page 1-24
• “Viewing Model Properties and Estimated Parameters” on page 1-25
Each model object has properties for storing information that are relevant only to that
specific model type. The idtf, idgrey, idpoly, idproc, and idss model objects are
based on the idlti superclass and inherit all idlti properties.
Similarly, the nonlinear models idnlarx, idnlhw, and idnlgrey are based on the
idnlmodel superclass and inherit all idnlmodel properties.
In general, all model objects have properties that belong to the following categories:
• Algorithm
Structure includes fields that specify the estimation method. Algorithm includes
another structure, called Advanced, which provides additional flexibility for
setting the search algorithm. Different fields apply to different estimation
techniques.
For linear parametric models, Algorithm specifies the frequency weighing of the
estimation using the Focus property.
For information about getting help on object properties, see the model reference pages.
1-24
Linear Model Structures
The following table summarizes the commands for viewing and changing model property
values. 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.
Task Command Example
View all model get Load sample data, compute an ARX model, and
properties and list the model properties:
their values
load iddata8
m_arx=arx(z8,[4 3 2 3 0 0 0]);
get(m_arx)
Access a specific Use dot notation View the A matrix containing the estimated
model property parameters in the previous model:
m_arx.a
For properties, such as View the method used in ARX model estimation:
Report, that are configured
like structures, use dot m_arx.Report.Method
notation of the form
model.PropertyName.FieldName.
FieldName is the name of
any field of the property.
Change model dot notation Change the input delays for all three input
property values channels to [1 1 1] for an ARX model:
m_arx.InputDelay = [1 1 1]
Access model Use getpar, getpvec and • View a table of all parameter attributes:
parameter values getcov
and uncertainty See Also: polydata, getpar(m_arx)
information idssdata, tfdata, • View the A polynomial and 1 standard
zpkdata uncertainty of an ARX model:
[a,~,~,~,~,da] = polydata(m_arx)
Set model Use setpar, setpvec and • Set default parameter labels:
property values setcov
and uncertainty m_arx = setpar(m_arx,'label','default')
information • Set parameter covariance data:
m_arx = setcov(m_arx,cov)
1-25
1 Choosing Your System Identification Approach
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 “Validating Models After Estimation”.
1-26
Imposing Constraints on Model Parameter Values
The Structure property contains the essential parameters that define the structure of a
given model:
• For identified transfer functions, includes the numerator, denominator and delay
parameters
• For polynomial models, includes the list of active polynomials
• For state-space models, includes the list of state-space matrices
For information about other model types, see the model reference pages.
For example, the following example constructs an idtf model, specifying values for the
num and den parameters:
num = [1 2];
den = [1 2 2];
sys = idtf(num,den)
You can update the value of the num and den properties after you create the object as
follows:
new_den = [1 1 10];
sys.den = new_den;
To fix the denominator to the value you specified (treat its coefficients as fixed
parameters), use the Structure property of the object as follows:
sys.Structure.den.Value = new_den;
sys.Structure.den.Free = false(1,3);
For a transfer function model, the num, den, and ioDelay model properties are simply
pointers to the Value attribute of the corresponding parameter in the Structure
property.
1-27
1 Choosing Your System Identification Approach
ioDelay:
. .
Value:
Minimum:
. . Maximum:
Free:
Scale:
Info:
Similar relationships exist for other model structures. For example, the a property of a
state-space model contains the double value of the state matrix. It is an alias to the A
parameter value stored in Structure.a.Value.
1-28
Available Nonlinear Models
1-29
1 Choosing Your System Identification Approach
Another reason to start with simple model structures is that higher-order models are
not always more accurate. Increasing model complexity increases the uncertainties in
parameter estimates and typically requires more data (which is common in the case of
nonlinear models).
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 Prepare Data for System Identification”.
1 Transfer function, ARX polynomial and state-space models provide the simplest
structures. Estimation of ARX and state-space models let you determine the model
orders.
At the command line. Use the tfest, arx, and the n4sid commands,
respectively.
1-30
Recommended Model Estimation Sequence
For general information about choosing you model strategy, see “System Identification
Overview”. For information about validating models, see “Validating Models After
Estimation”.
1-31
1 Choosing Your System Identification Approach
You can also use d2c to convert an estimated discrete-time model into a continuous-time
model.
Discrete-Time Models
You can estimate all linear and nonlinear models supported by the System Identification
Toolbox product as discrete-time models, except process models, which are defined only in
continuous-time..
You can estimate both continuous-time and discrete-time models from time-domain data
for linear and nonlinear differential and difference equations.
Nonlinear Models
You can estimate discrete-time Hammerstein-Wiener and nonlinear ARX models from
time-domain data.
You can also estimate nonlinear grey-box models from time-domain data. See
“Estimating Nonlinear Grey-Box Models” on page 6-15.
1-32
Supported Models for Time- and Frequency-Domain Data
The data is considered continuous-time if its sample time (Ts) is 0, and is considered
discrete-time if the sample time is nonzero.
Continuous-Time Models
You can also use d2c to convert an estimated discrete-time model into a continuous-time
model.
Discrete-Time Models
You can estimate all linear model types supported by the System Identification Toolbox
product as discrete-time models, except process models, which are defined in continuous-
time only. For estimation of discrete-time models, you must use discrete-time data.
The noise component of a model cannot be estimated using frequency domain data, with
the exception of ARX models. Thus, the K matrix of an identified state-space model, the
noise component, is zero. An identified polynomial model has output-error (OE) or ARX
structure; BJ/ARMAX or other polynomial structure with nontrivial values of C or D
polynomials cannot be estimated.
1-33
1 Choosing Your System Identification Approach
For linear grey-box models, you can estimate both continuous-time and discrete-time
models from frequency-domain data. The noise component of the model, the K matrix,
cannot be estimated using frequency domain data; it remains fixed to 0.
See Also
“Supported Continuous- and Discrete-Time Models” on page 1-35
1-34
Supported Continuous- and Discrete-Time Models
For black-box models, the following tables summarize supported continuous-time and
discrete-time models.
1-35
1 Choosing Your System Identification Approach
1-36
Model Estimation Commands
Note: For ODEs (grey-box models), you must first construct the model structure and then
apply an estimation command (either greyest or pem) to the resulting model object.
The following table summarizes System Identification Toolbox estimation commands. For
detailed information about using each command, see the corresponding reference page.
1-37
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-39.
1-38
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”.
To construct partial models, use subreferencing to create partial data sets, such that each
data set contains all inputs and one output. For more information about creating partial
data sets, see the following sections in the System Identification Toolbox User's Guide:
• For working in the System Identification app, see “Create Data Sets from a Subset of
Signal Channels” on page 2-33.
• For working at the command line, see the “Select Data Channels, I/O Data and
Experiments in iddata Objects”.
You can try refining the concatenated multiple-output model using the original (multiple-
output) data set.
For linear models, use the OutputWeight estimation to indicate the desired output
weighting. If you set this option to 'noise', an automatic weighting, equal to the
1-39
1 Choosing Your System Identification Approach
inverse of the estimated noise variance, is used for model estimation. You can also specify
a custom weighting matrix, which must be a positive semi-definite matrix.
Note:
• The OutputWeight option is not available for polynomial models, except ARX
models, since their estimation algorithm estimates the parameters one output at a
time.
For nonlinear models, you can specify output weights directly in the estimation command
using the Criterion and Weighting estimation options. 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.
For more information about the OutputWeight estimation option, see arxOptions,
ssestOptions, tfestOptions, procestOptions, etc. For more information about
the Algorithm fields for nonlinear estimation, see the idnlarx and idnlhw reference
pages.
1-40
Regularized Estimates of Model Parameters
What Is Regularization?
Regularization is the technique for specifying constraints on a model’s flexibility, thereby
reducing uncertainty in the estimated parameter values.
Model parameters are obtained by fitting measured data to the predicted model response,
such as a transfer function with three poles or a second-order state-space model.
The model order is a measure of its flexibility — higher the order, the greater the
flexibility. For example, a model with three poles is more flexible than one with two
poles. Increasing the order causes the model to fit the observed data with increasing
accuracy. However, the increased flexibility comes with the price of higher uncertainty
in the estimates, measured by a higher value of random or variance error. On the other
hand, choosing a model with too low an order leads to larger systematic errors. Such
errors cannot be attributed to measurement noise and are also known as bias error.
Ideally, the parameters of a good model should minimize the mean square error (MSE),
given by a sum of systematic error (bias) and random error (variance):
The minimization is thus a tradeoff in constraining the model. A flexible (high order)
model gives small bias and large variance, while a simpler (low order) model results
in larger bias and smaller variance errors. Typically, you can investigate this tradeoff
between bias and variance errors by cross-validation tests on a set of models of
increasing flexibility. However, such tests do not always give full control in managing the
parameter estimation behavior. For example:
• You cannot use the known (a priori) information about the model to influence the
quality of the fits.
• In grey-box and other structured models, the order is fixed by the underlying ODEs
and cannot be changed. If the data is not rich enough to capture the full range of
dynamic behavior, this typically leads to high uncertainty in the estimated values.
1-41
1 Choosing Your System Identification Approach
• Varying the model order does not let you explicitly shape the variance of the
underlying parameters.
Regularization gives you a better control over the bias versus variance tradeoff by
introducing an additional term in the minimization criterion that penalizes the model
flexibility. Without regularization, the parameter estimates are obtained by minimizing a
weighted quadratic norm of the prediction errors ε(t,θ):
N
VN (q ) = Âe 2 (t,q )
t =1
where t is the time variable, N is the number of data samples, and ε(t,θ) is the predicted
error computed as the difference between the observed output and the predicted output
of the model.
Regularization modifies the cost function by adding a term proportional to the square of
the norm of the parameter vector θ, so that the parameters θ are obtained by minimizing:
N
2
Vˆ N (q ) = Âe 2 (t,q ) + l q
t =1
where λ is a positive constant that has the effect of trading variance error in VN(θ)
for bias error — the larger the value of λ, the higher the bias and lower the variance
of θ. The added term penalizes the parameter values with the effect of keeping their
values small during estimation. In statistics, this type of regularization is called ridge
regression. For more information, see “Ridge Regression” in the Statistics Toolbox™
documentation.
Note: Another choice for the norm of θ vector is the L1-norm, known as lasso
regularization. However, System Identification Toolbox supports only the 2-norm based
penalty, known as L2 regularization, as shown in the previous equation.
The penalty term is made more effective by using a positive definite matrix R, which
allows weighting and/or rotation of the parameter vector:
N
Vˆ N (q ) = Âe 2 (t,q ) + lq T Rq
t =1
1-42
Regularized Estimates of Model Parameters
• Shaping the penalty term to meet the required constraints, such as keeping the model
stable
• Adding known information about the model parameters, such as reliability of the
individual parameters in the θ vector
For structured models such as grey-box models, you may want to keep the estimated
parameters close to their guess values to maintain the physical validity of the estimated
T
model. This can be achieved by generalizing the penalty term to l q - q * ( ) R (q - q * ) ,
such that the cost function becomes:
N T
Vˆ N (q ) = Âe 2 (t,q ) + l (q - q * ) (
R q -q* )
t =1
Minimizing this cost function has the effect of estimating θ such that their values remain
close to initial guesses θ*.
In regularization:
You can use the regularization variables λ and R as tools to find a good model that
balances complexity and provides the best tradeoff between bias and variance. You can
obtain regularized estimates of parameters for transfer function, state-space, polynomial,
grey-box, process and nonlinear black-box models. The three terms defining the penalty
term, λ, R and θ*, are represented by regularization options Lambda, R, and Nominal,
respectively in the toolbox. You can specify their values in the estimation options set
for linear models and the Algorithm property for nonlinear models. In the System
Identification app, click Regularization in the linear model estimation dialog box or
Estimation Options in the Nonlinear Models dialog box.
1-43
1 Choosing Your System Identification Approach
In such cases, regularization improves the numerical conditioning of the estimation. You
can explore bias-vs.-variance tradeoff using various values of the regularization constant
Lambda. Typically, the Nominal option is its default value of 0, and R is an identity
matrix such that the following cost function is minimized:
N
2
Vˆ N (q ) = Âe 2 (t,q ) + l q
t =1
In the following example, a nonlinear ARX model estimation using a large number of
neurons leads to an ill-conditioned estimation problem.
% Load estimation data
load regularizationExampleData.mat nldata
% Estimate model without regularization
Orders = [1 2 1];
NL = sigmoidnet('NumberOfUnits',30);
sys = nlarx(nldata, Orders, NL);
compare(nldata, sys)
Applying even a small regularizing penalty produces a good fit for the model to the data.
% Estimate model using regularization constant # = 1e-8;
al = sys.Algorithm;
al.Regularization.Lambda = 1e-8;
sysr = nlarx(nldata, Orders, NL, 'Algorithm',al);
1-44
Regularized Estimates of Model Parameters
compare(nldata, sysr)
In models derived from differential equations, the parameters have physical significance.
You may have a good guess for typical values of those parameters even if the reliability
of the guess may be different for each parameter. Because the model structure is fixed in
such cases, you cannot simplify the structure to reduce variance errors.
Using the regularization constant Nominal, you can keep the estimated values close to
their initial guesses. You can also design R to reflect the confidence in the initial guesses
of the parameters. For example, if θ is a 2-element vector and you can guess the value of
the first element with more confidence than the second one, set R to be a diagonal matrix
of size 2-by-2 such that R(1,1) >> R(2,2).
In many situations, you may know the shape of the system impulse response from impact
tests. For example, it is quite common for stable systems to have an impulse response
that is smooth and exponentially decaying. You can use such prior knowledge of system
behavior to derive good values of regularization constants for linear-in-parameter models
such as ARX and FIR structure models using the arxRegul command.
1-45
1 Choosing Your System Identification Approach
For black-box models of arbitrary structure, it is often difficult to determine the optimal
values of Lambda and R that yield the best bias-vs.-variance tradeoff. Therefore, it
is recommended that you start by obtaining the regularized estimate of an ARX or
FIR structure model. Then, convert the model to a state-space, transfer function or
polynomial model using the idtf, idss, or idpoly commands, followed by order
reduction if required.
Therefore, use regularized ARX estimation and then convert the model to transfer
function structure.
% Specify regularization constants
[L, R] = arxRegul(ze, [15 15 1]);
optARX = arxOptions;
optARX.Regularization.Lambda = L;
optARX.Regularization.R = R;
% Estimate ARX model
sysARX = arx(ze, [15 15 1], optARX);
% Convert model to continuous time
sysc = d2c(sysARX);
% Convert model to transfer function
sys2 = idtf(sysc);
% Validate the models sys1 and sys2
compare(zv, sys1, sys2)
1-46
Regularized Estimates of Model Parameters
You can relate naturally to such an assumption for a grey-box model, where the
parameters are of known physical interpretation. In other cases, this may be more
difficult. Then, you have to use ridge regression (R = 1; θ* = 0) and tune λ by trial and
error.
Tuning the regularization constants for ARX models in arxRegul is based on simple
assumptions about the properties of the true impulse responses.
In the case of an FIR model, the parameter vector contains the impulse response
coefficients bk for the system. From prior knowledge of the system, it is often known that
the impulse response is smooth and exponentially decaying:
2
E [ bk ] = Cm k , corr {bkbk -1 } = r
You can estimate the parameters of the kernel by adjusting them to the measured data
using the RegulKernel input of the arxRegul command. For example, the DC kernel
estimates all three parameters while the TC kernel links r = m . This technique of
tuning kernels applies to all linear-in-parameter models such as ARX and FIR models.
A general way to test and evaluate any regularization parameters is to estimate a model
based on certain parameters on an estimation data set, and evaluate the model fit for
another validation data set. This is known as cross-validation.
1-47
1 Choosing Your System Identification Approach
For example:
% Create estimation and validation data sets
ze = z(1:N/2);
zv = z(N/2:end);
% Specify regularization options and estimate models
opt = ssestOptions;
for tests = 1:M
opt.Regularization.Lambda = Lvalue(test);
opt.Regularization.R = Rvalue(test);
m{test} = ssest(ze,order,opt);
end
% Compare models with validation data for model fit
[~,fit] = compare(zv,m{:))
References
[1] L. Ljung. “Some Classical and Some New Ideas for Identification of Linear Systems.”
Journal of Control, Automation and Electrical Systems. April 2013, Volume 24,
Issue 1-2, pp 3-10.
[2] L. Ljung, and T. Chen. “What can regularization offer for estimation of dynamical
systems?” In Proceedings of IFAC International Workshop on Adaptation and
Learning in Control and Signal Processing, ALCOSP13, Caen, France, July 2013.
Related Examples
• “Estimate Regularized ARX Model Using System Identification App” on page
1-49
• “Regularized Identification of Dynamic Systems”
1-48
Estimate Regularized ARX Model Using System Identification App
The session imports the following data and model into the System Identification app:
The data is collected by simulating a system with the following known transfer
function:
trueSys is the transfer function model used to generate the estimation data eData
described previously. You also use the impulse response of this model later to compare
the impulse responses of estimated ARX models.
1 In the System Identification app, select Estimate > Polynomial Models to open
the Polynomial Models dialog box.
1-49
1 Choosing Your System Identification Approach
1-50
Estimate Regularized ARX Model Using System Identification App
Select the Model output check box in the System Identification app.
1-51
1 Choosing Your System Identification Approach
The Measured and simulated model output plot shows that both the models have an 84%
fit with the data.
Because the model fit to the estimation data is similar with and without using
regularization, compare the impulse response of the ARX models with the impulse
responses of trueSys, the system used to collect the estimation data.
1 Click the trueSys icon in the model board of the System Identification app.
1-52
Estimate Regularized ARX Model Using System Identification App
2 Select the Transient resp check box to open the Transient Response plot window.
1-53
1 Choosing Your System Identification Approach
The plot shows that the impulse response of the unregularized model arx0500 is far
off from the true system and has huge uncertainties.
To get a closer look at the model fits to the data and the variances, magnify a portion
of the plot.
1-54
Estimate Regularized ARX Model Using System Identification App
The fit of the regularized ARX model arx0500reg closely matches the impulse
response of the true system and the variance is greatly reduced as compared to the
unregularized model.
Related Examples
• “Regularized Identification of Dynamic Systems”
More About
• “Regularized Estimates of Model Parameters” on page 1-41
1-55
1-56
2
2-2
Supported Data
Supported Data
System Identification Toolbox software supports estimation of linear models from both
time- and frequency-domain data. For nonlinear models, this toolbox supports only time-
domain data. For more information, see “Supported Models for Time- and Frequency-
Domain Data” on page 1-32.
The data can have single or multiple inputs and outputs, and can be either real or
complex.
Your time-domain data should be sampled at discrete and uniformly spaced time instants
to obtain an input sequence
u={u(T),u(2T),...,u(NT)}
u(t) and y(t) are the values of the input and output signals at time t, respectively.
2-3
2 Data Import and Processing
Note: If your data is complex valued, see “Manipulating Complex-Valued Data” on page
2-145 for information about supported operations for complex data.
2-4
Ways to Obtain Identification Data
Your data must capture the important system dynamics, such as dominant time
constants. After measuring the signals, organize the data into variables, as described
in “Representing Data in MATLAB Workspace” on page 2-9. Then, import it in
the System Identification app or represent it as a data object for estimating models at
the command line.
• Generating an input signal with desired characteristics, such as a random Gaussian
or binary signal or a sinusoid, using idinput. Then, generate an output signal using
this input to simulate a model with known coefficients. For more information, see
“Generate Data Using Simulation” on page 2-131.
Using input/output data thus generated helps you study the impact of input signal
characteristics and noise on estimation.
• Logging signals from Simulink® models.
This technique is useful when you want to replace complex components in your model
with identified models to speed up simulations or simplify control design tasks.
For more information on how to log signals, see “Export Signal Data Using Signal
Logging” in the Simulink documentation.
2-5
2 Data Import and Processing
The following tasks help to prepare your data for identifying models from data:
• For working in the app, import data into the System Identification app.
See “How to Analyze Data Using the advice Command” on page 2-98.
2-6
Preprocess data
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 Offsets and Trends in Data” on page 2-108 for information about
subtracting means and linear trends, and “Filtering Data” on page 2-123 for
information about filtering.
• High-frequency disturbances above the frequency interval of interest for the system
dynamics.
See “Resampling Data” on page 2-114 for information about decimating and
interpolating values, and “Filtering Data” on page 2-123 for information about
filtering.
To learn more about selecting data, see “Selecting Subsets of Data” on page 2-100.
2-7
2 Data Import and Processing
The System Identification Toolbox product provides limited support for nonuniformly
sampled data. For more information about specifying uniform and nonuniform time
vectors, see “Constructing an iddata Object for Time-Domain Data” on page 2-50.
2-8
Representing Data in MATLAB Workspace
• For single-input/single-output (SISO) data, the sampled data values must be double
column vectors.
• For multi-input/multi-output (MIMO) data with Nu inputs and Ny outputs, and Ns
number of data samples (measurements):
To use time-domain data for identification, you must know the sampling interval. If you
are working with uniformly sampled data, use the actual sampling interval from your
experiment. Each data value is assigned a time instant, which is calculated from the
start time and sampling interval. You can work with nonuniformly sampled data only at
the command line by specifying a vector of time instants using the SamplingInstants
property of iddata, as described in “Constructing an iddata Object for Time-Domain
Data” on page 2-50.
For continuous-time models, you must also know the input intersample behavior, such as
zero-order hold and first-order-hold.
For more information about importing data into MATLAB, see “Data Import and
Export”.
After you have the variables in the MATLAB workspace, import them into the System
Identification app or create a data object for working at the command line. For more
2-9
2 Data Import and Processing
information, see “Import Time-Domain Data into the App” on page 2-16 and
“Representing Time- and Frequency-Domain Data Using iddata Objects” on page
2-50.
• For single-input/single-output (SISO) data, the output data values must be a column
vector.
• For data with Ny outputs, the output is an Ns-by-Ny matrix, where Ns is the number of
output data samples (measurements).
To use time-series data for identification, you also need the sampling interval. If you
are working with uniformly sampled data, use the actual sampling interval from your
experiment. Each data value is assigned a sample time, which is calculated from the
start time and the sampling interval. If you are working with nonuniformly sampled
data at the command line, you can specify a vector of time instants using the iddata
SamplingInstants property, as described in “Constructing an iddata Object for Time-
Domain Data” on page 2-50. Note that model estimation cannot be performed using
non-uniformly sampled data.
For more information about importing data into the MATLAB workspace, see “Data
Import and Export”.
After you have the variables in the MATLAB workspace, import them into the System
Identification app or create a data object for working at the command line. For more
information, see “Import Time-Domain Data into the App” on page 2-16 and
“Representing Time- and Frequency-Domain Data Using iddata Objects” on page
2-50.
For information about estimating time-series model parameters, see “Time-Series Model
Identification”.
2-10
Representing Data in MATLAB Workspace
Frequency-domain data is the Fourier transform of the input and output time-domain
signals. For continuous-time signals, the Fourier transform over the entire time axis is
defined as follows:
•
Y (iw) = Ú y(t) e-iwt dt
-•
•
-iwt
U ( iw) = Ú u(t)e dt
-•
N
Y ( eiwT ) = T Â y(kT )e-iwkT
k =1
Note: This form only discretizes the time. The frequency is continuous.
2-11
2 Data Import and Processing
In practice, the Fourier transform cannot be handled for all continuous frequencies
and you must specify a finite number of frequencies. The discrete Fourier transform
(DFT) of time-domain data for N equally spaced frequencies between 0 and the sampling
frequency 2π/N is:
N
Y ( eiwnT ) = Â y(kT )e-iw kT
n
k= 1
2pn
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.
For more information on how to obtain identification data, see “Ways to Obtain
Identification Data” on page 2-5.
How to Represent Frequency-Domain Data in MATLAB
•
The input data must be a column vector containing the values u eiw kT
( )
•
The output data must be a column vector containing the values y eiw kT
( )
k=1, 2, ..., Nf, where Nf is the number of frequencies.
• For multi-input/multi-output data with Nu inputs, Ny outputs and Nf frequency
measurements:
2-12
Representing Data in MATLAB Workspace
For more information about importing data into the MATLAB workspace, see “Data
Import and Export”.
After you have the variables in the MATLAB workspace, import them into the System
Identification app or create a data object for working at the command line. For more
information, see “Importing Frequency-Domain Input/Output Signals into the App” on
page 2-19 and “Representing Time- and Frequency-Domain Data Using iddata
Objects” on page 2-50.
The transfer function G is an operator that takes the input u of a linear system to the
output y:
y = Gu
For a continuous-time system, the transfer function relates the Laplace transforms of the
input U(s) and output Y(s):
Y ( s) = G ( s)U ( s)
In this case, the frequency function G(iw) is the transfer function evaluated on the
imaginary axis s=iw.
For a discrete-time system sampled with a time interval T, the transfer function relates
the Z-transforms of the input U(z) and output Y(z):
Y ( z) = G ( z)U ( z)
2-13
2 Data Import and Processing
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 p 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 j = arg G . G is
evaluated at the frequency of the input sinusoid.
For more information on how to obtain identification data, see “Ways to Obtain
Identification Data” on page 2-5.
How to Represent Frequency-Response Data in MATLAB
You can import both the formats directly in the System Identification app. At the
command line, you must represent complex data using an frd or idfrd object. If the
data is in amplitude and phase format, convert it to complex frequency-response vector
using h(ω) = A(ω)ejϕ(ω).
Rrequency-Response For Single-Input Single-Output (SISO) For Multi-Input Multi-Output (MIMO) Data
Data Representation Data
Complex Values • Frequency function must be a • Frequency function must be an Ny-
column vector. by-Nu-by-Nf array, where Nu is the
• Frequency values must be a number of inputs, Ny is the number
column vector.
2-14
Representing Data in MATLAB Workspace
Rrequency-Response For Single-Input Single-Output (SISO) For Multi-Input Multi-Output (MIMO) Data
Data Representation Data
of outputs, and Nf is the number of
frequency measurements.
• Frequency values must be a column
vector.
Amplitude and phase • Amplitude and phase must • Amplitude and phase must each be
shift values each be a column vector. an Ny-by-Nu-by-Nf array, where Nu
• Frequency values must be a is the number of inputs, Ny is the
column vector. number of outputs, and Nf is the
number of frequency measurements.
• Frequency values must be a column
vector.
For more information about importing data into the MATLAB workspace, see “Data
Import and Export”.
After you have the variables in the MATLAB workspace, import them into the System
Identification app or create a data object for working at the command line. For more
information about importing data into the app, see “Importing Frequency-Response
Data into the App” on page 2-21. To learn more about creating a data object, see
“Representing Frequency-Response Data Using idfrd Objects” on page 2-83.
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.
1 Type the following command in the MATLAB Command Window to open the app:
systemIdentification
2 In the System Identification app window, select Import data > Time domain data.
This action opens the Import Data dialog box.
Note: For time series, only import the output signal and enter [] for the input.
2-16
Import Time-Domain Data into the App
• Starting time — Enter the starting value of the time axis for time 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-28.
Tip The System Identification Toolbox product uses the sampling interval during
model estimation and to set the horizontal axis on time plots. If you transform
a time-domain signal to a frequency-domain signal, the Fourier transforms are
computed as discrete Fourier transforms (DFTs) using this sampling interval.
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.
• Period — Enter Inf to specify a nonperiodic input. If the underlying time-
domain data was periodic over an integer number of periods, enter the period of
the input signal.
Note: If your data is periodic, always include a whole number of periods for model
estimation.
Channel Names
2-17
2 Data Import and Processing
• Input — Enter a string to specify the name of one or more input channels.
Tip Naming channels helps you to identify data in plots. For multivariable input-
output signals, you can specify the names of individual Input and Output
channels, separated by commas.
• Output — Enter a string to specify the name of one or more output channels.
Tip When you have multiple inputs and outputs, enter a comma-separated list of
Input and Output units corresponding to each channel.
• Output — Enter a string to specify the output units.
Notes — Enter comments about the experiment or the data. For example, you might
enter the experiment name, date, and a description of experimental conditions.
Models you estimate from this data inherit your data notes.
5 Click Import. This action adds a new data icon to the System Identification app
window.
6 Click Close to close the Import Data dialog box.
2-18
Import Frequency-Domain Data into the App
In this section...
“Importing Frequency-Domain Input/Output Signals into the App” on page 2-19
“Importing Frequency-Response Data into the App” on page 2-21
Before you can import frequency-domain data into the System Identification app, you
must import the data into the MATLAB workspace, as described in “Frequency-Domain
Input/Output Signal Representation” on page 2-11.
Note: The input and output signals must have the same number of data samples.
1 Type the following command in the MATLAB Command Window to open the app:
systemIdentification
2 In the System Identification app window, select Import data > Freq. domain
data. This action opens the Import Data dialog box.
3 Specify the following options:
2-19
2 Data Import and Processing
The frequency vector must have the same number of rows as the input and
output signals.
• Data name — Enter the name of the data set, which appears in the System
Identification app window after the import operation is completed.
• Frequency unit — Enter Hz for Hertz or keep the rad/s default value.
• Sampling interval — Enter the actual sampling interval in the experiment.
For continuous-time data, enter 0. For more information about this setting, see
“Specifying the Data Sampling Interval” on page 2-28.
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.
• Period — Enter Inf to specify a nonperiodic input. If the underlying time-
domain data was periodic over an integer number of periods, enter the period of
the input signal.
Note: If your data is periodic, always include a whole number of periods for model
estimation.
Channel Names
2-20
Import Frequency-Domain Data into the App
• Input — Enter a string to specify the name of one or more input channels.
Tip Naming channels helps you to identify data in plots. For multivariable input
and output signals, you can specify the names of individual Input and Output
channels, separated by commas.
• Output — Enter a string to specify the name of one or more output channels.
Tip When you have multiple inputs and outputs, enter a comma-separated list of
Input and Output units corresponding to each channel.
• Output — Enter a string to specify the output units.
Notes — Enter comments about the experiment or the data. For example, you might
enter the experiment name, date, and a description of experimental conditions.
Models you estimate from this data inherit your data notes.
5 Click Import. This action adds a new data icon to the System Identification app
window.
6 Click Close to close the Import Data dialog box.
Prerequisite
Before you can import frequency-response data into the System Identification app, you
must import the data into the MATLAB workspace, as described in “Frequency-Response
Data Representation” on page 2-13.
2-21
2 Data Import and Processing
1 Type the following command in the MATLAB Command Window to open the app:
systemIdentification
2 In the System Identification app 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).
4 Specify the following options:
Channel Names
• Input — Enter a string to specify the name of one or more input channels.
Tip Naming channels helps you to identify data in plots. For multivariable input
and output signals, you can specify the names of individual Input and Output
channels, separated by commas.
• Output — Enter a string to specify the name of one or more output channels.
2-22
Import Frequency-Domain Data into the App
Tip When you have multiple inputs and outputs, enter a comma-separated list of
Input and Output units corresponding to each channel.
• Output — Enter a string to specify the output units.
Notes — Enter comments about the experiment or the data. For example, you might
enter the experiment name, date, and a description of experimental conditions.
Models you estimate from this data inherit your data notes.
6 Click Import. This action adds a new data icon to the System Identification app
window.
7 Click Close to close the Import Data dialog box.
1 Type the following command in the MATLAB Command Window to open the app:
systemIdentification
2 In the System Identification app 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 (Amp/Phase).
4 Specify the following options:
2-23
2 Data Import and Processing
Channel Names
• Input — Enter a string to specify the name of one or more input channels.
Tip Naming channels helps you to identify data in plots. For multivariable input
and output signals, you can specify the names of individual Input and Output
channels, separated by commas.
• Output — Enter a string to specify the name of one or more output channels.
Tip When you have multiple inputs and outputs, enter a comma-separated list of
Input and Output units corresponding to each channel.
• Output — Enter a string to specify the output units.
Notes — Enter comments about the experiment or the data. For example, you might
enter the experiment name, date, and a description of experimental conditions.
Models you estimate from this data inherit your data notes.
6 Click Import. This action adds a new data icon to the System Identification app
window.
7 Click Close to close the Import Data dialog box.
2-24
Import Data Objects into the App
Before you can import a data object into the System Identification app, 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-50 or “Representing
Frequency-Response Data Using idfrd Objects” on page 2-83.
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.
1 Type the following command in the MATLAB Command Window to open the app:
systemIdentification
2 In the System Identification app 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.
3 Specify the following options:
• Object — Enter the name of the MATLAB variable that represents the data
object in the MATLAB workspace. Press Enter.
2-25
2 Data Import and Processing
• Data name — Enter the name of the data set, which appears in the System
Identification app 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-28.
Tip The System Identification Toolbox product uses the sampling interval during
model estimation and to set the horizontal axis on time plots. If you transform
a time-domain signal to a frequency-domain signal, the Fourier transforms are
computed as discrete Fourier transforms (DFTs) using this sampling interval.
4 (Optional) In the Data Information area, click More to expand the dialog box and
enter the following optional settings:
• 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 input 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.
• Period — Enter Inf to specify a nonperiodic input. If the underlying time-
domain data was periodic over an integer number of periods, enter the period of
the input signal.
2-26
Import Data Objects into the App
Note: If your data is periodic, always include a whole number of periods for model
estimation.
Channel Names
• Input — Enter a string to specify the name of one or more input channels.
Tip Naming channels helps you to identify data in plots. For multivariable input
and output signals, you can specify the names of individual Input and Output
channels, separated by commas.
• Output — Enter a string to specify the name of one or more output channels.
Tip When you have multiple inputs and outputs, enter a comma-separated list of
Input and Output units corresponding to each channel.
• Output — Enter a string to specify the output units.
Notes — Enter comments about the experiment or the data. For example, you might
enter the experiment name, date, and a description of experimental conditions.
Models you estimate from this data inherit your data notes.
5 Click Import. This action adds a new data icon to the System Identification app
window.
6 Click Close to close the Import Data dialog box.
2-27
2 Data Import and Processing
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.
The sampling interval is used during model estimation. For time-domain data, the
sampling interval is used together with the start time to calculate the sampling time
instants. When you transform time-domain signals to frequency-domain signals (see the
fft reference page), the Fourier transforms are computed as discrete Fourier transforms
(DFTs) for this sampling interval. In addition, the sampling instants are used to set the
horizontal axis on time plots.
2-28
Specifying the Data Sampling Interval
2-29
2 Data Import and Processing
In the System Identification app, Working Data refers to estimation data. Similarly,
Validation Data refers to the data set you use to validate a model. For example, when
you plot the model output, the input to the model is the input signal from the validation
data set. This plot compares model output to the measured output in the validation data
set. Selecting Model resids performs residual analysis using the validation data.
To specify Working Data, drag and drop the corresponding data icon into the Working
Data rectangle, as shown in the following figure. Similarly, to specify Validation
Data, drag and drop the corresponding data icon into the Validation Data rectangle.
Alternatively, right-click the icon to open the Data/model Info dialog box. Select the Use
as Working Data or Use as Validation Data and click Apply to specify estimation
and validation data, respectively.
2-30
Specify Estimation and Validation Data in the App
2-31
2 Data Import and Processing
Note: For information about when to subtract mean values from the data, see
“Handling Offsets and Trends in Data” on page 2-108.
• Split data into two parts.
• Specify the first part as estimation data for models (or Working Data).
• Specify the second part as Validation Data.
2-32
Create Data Sets from a Subset of Signal Channels
1 In the System Identification app, 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.
3 In the Inputs list, select one or more channels in any of following ways:
2-33
2 Data Import and Processing
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:
2-34
Create Multiexperiment Data Sets in the App
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.
For example, suppose that you want to combine the data sets tdata, tdata2, tdata3,
tdata4 shown in the following figure.
2-35
2 Data Import and Processing
1 In the Operations area, select <--Preprocess > Merge experiments from the
drop-down menu to open the Merge Experiments dialog box.
2-36
Create Multiexperiment Data Sets in the App
2 In the System Identification app window, drag a data set icon to the Merge
Experiments dialog box, to the drop them here to be merged rectangle.
The name of the data set is added to the List of sets. Repeat for each data set you
want to merge.
2-37
2 Data Import and Processing
2-38
Create Multiexperiment Data Sets in the App
Tip To get information about a data set in the System Identification app, 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:
1 In the System Identification app window, drag and drop the tdatam data icon to the
Working Data rectangle.
2-39
2 Data Import and Processing
2-40
Create Multiexperiment Data Sets in the App
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
app.
6 Click Close to close the Select Experiment dialog box.
2-41
2 Data Import and Processing
In this section...
“Viewing Data Properties” on page 2-42
“Renaming Data and Changing Display Color” on page 2-43
“Distinguishing Data Types” on page 2-46
“Organizing Data Icons” on page 2-46
“Deleting Data Sets” on page 2-47
“Exporting Data to the MATLAB Workspace” on page 2-48
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 app. The Data/model Info dialog box
updates as you select each data set.
2-42
Managing Data in the App
Data object
description
History of
syntax that
created this
object
To displays the data properties in the MATLAB Command Window, click Present.
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 app.
The Data/model Info dialog box also lets you rename the data by entering a new name in
the Data name field.
2-43
2 Data Import and Processing
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 App” on page 14-15.
Tip As an alternative to using three RGB values, you can enter any one of the following
letters in single quotes:
'y' 'r' 'b' 'c' 'g' 'm' 'k'
These strings represent yellow, red, blue, cyan, green, magenta, and black, respectively.
2-44
Managing Data in the App
Specify name
for data set
Specify color
used to display
data set
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-45
2 Data Import and Processing
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 app. 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-46
Managing Data in the App
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 app 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 14-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
app to be Working Data or Validation Data, as described in “Specify Estimation and
Validation Data in the App” on page 2-30.
To restore a data set from Trash, drag its icon from Trash to the Data or Model Board
in the System Identification app window. You can view the Trash contents by double-
clicking the Trash icon.
2-47
2 Data Import and Processing
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.
When you export data to the MATLAB workspace, the resulting variables have the same
name as in the System Identification app. For example, the following figure shows how to
export the time-domain data object datad.
2-48
Managing Data in the App
In this example, the MATLAB workspace contains a variable named data after export.
2-49
2 Data Import and Processing
iddata Constructor
• “Requirements for Constructing an iddata Object” on page 2-50
• “Constructing an iddata Object for Time-Domain Data” on page 2-50
• “Constructing an iddata Object for Frequency-Domain Data” on page 2-52
To construct an iddata object, you must have already imported data into the MATLAB
workspace, as described in “Representing Data in MATLAB Workspace” on page 2-9.
data = iddata(y,u,Ts)
data = iddata(y,u,Ts,'Property1',Value1,...,'PropertyN',ValueN)
In this example, Ts is the sampling time, or the time interval, between successive data
samples. For uniformly sampled data, Ts is a scalar value equal to the sampling interval
of your experiment. The default time unit is seconds, but you can set it to a new value
using the TimeUnit property. For more information about iddata time properties, see
“Modifying Time and Frequency Vectors” on page 2-78.
2-50
Representing Time- and Frequency-Domain Data Using iddata Objects
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)
Note: You can modify the property SamplingInstants by setting it to a new vector
with the length equal to the number of data samples.
ts_data = iddata(y,[],Ts)
where y is the output data, [] indicates empty input data, and Ts is the sampling
interval.
The following example shows how to create an iddata object using single-input/single-
output (SISO) data from dryer2.mat. The input and output each contain 1000 samples
with the sampling interval of 0.08 second.
data =
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
2-51
2 Data Import and Processing
to the first and only input channel. For more information about naming channels, see
“Naming, Adding, and Removing Data Channels” on page 2-80.
Frequency-domain data is the Fourier transform of the input and output signals at
specific frequency values. To represent frequency-domain data, use the following syntax
to create the iddata object:
data = iddata(y,u,Ts,'Frequency',w)
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-78.
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:
load dryer2 % Load input u2 and output y2
data = iddata(y2,u2,0.08); % Create iddata object
get(data) % Get property values of data
ans =
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: 'seconds'
ExperimentName: 'Exp1'
Notes: {}
UserData: []
For a complete description of all properties, see the iddata reference page.
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.
Tip You can use data.y as an alternative to data.OutputData to access the output
values, or use data.u as an alternative to data.InputData to access the input values.
2-53
2 Data Import and Processing
To view the property list, type the following command sequence at the prompt:
% Load input u2 and output y2
load dryer2;
% Create iddata object
data = iddata(y2,u2,0.08);
% Take the Fourier transform of the data
% transforming it to frequency domain
data = fft(data)
% Get property values of data
get(data)
data =
ans =
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
2-54
Representing Time- and Frequency-Domain Data Using iddata Objects
FrequencyUnit: 'rad/TimeUnit'
Frequency: [501x1 double]
TimeUnit: 'seconds'
ExperimentName: 'Exp1'
Notes: {}
UserData: []
Subreferencing data and its properties lets you select data values and assign new data
and property values.
Use the following general syntax to subreference specific data values in iddata objects:
data(samples,outputchannels,inputchannels,experimentname)
In this syntax, samples specify one or more sample indexes, outputchannels and
inputchannels specify channel indexes or channel names, and experimentname
specifies experiment indexes or names.
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.
2-55
2 Data Import and Processing
You can retrieve the input signal from an iddata object using the following commands:
u = get(data,'InputData')
or
data.InputData
or
data.OutputData
or
Use the following general syntax to subreference specific data channels in iddata
objects:
data(samples,outputchannels,inputchannels,experiment)
In this syntax, samples specify one or more sample indexes, outputchannels and
inputchannels specify channel indexes or channel names, and experimentname
specifies experiment indexes or names.
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
2-56
Representing Time- and Frequency-Domain Data Using iddata Objects
Tip Use a colon (:) to specify all samples or all channels, and the empty matrix ([]) to
specify no samples or no channels.
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)
In this syntax, samples specify one or more sample indexes, outputchannels and
inputchannels specify channel indexes or channel names, and experimentname
specifies experiment indexes or names.
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
2-57
2 Data Import and Processing
Tip Use a colon (:) to denote all samples and all channels, and the empty matrix ([]) to
specify no samples and no channels.
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)
The InputData iddata property stores column-wise input data, and the OutputData
property stores column-wise output data. For more information about accessing iddata
properties, see “iddata Properties” on page 2-52.
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 =
2-58
Representing Time- and Frequency-Domain Data Using iddata Objects
[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:
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.
2-59
2 Data Import and Processing
In the System Identification Toolbox product, experiments can either mean data collected
during different sessions, or portions of the data 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.
2-60
Create Multiexperiment Data at the Command Line
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.
z =
These commands create an iddata object that contains two experiments, where the
experiments are assigned default names 'Exp1' and 'Exp2', respectively.
For example, to add the experiments in the iddata object dat4 to data, use the
following syntax:
2-61
2 Data Import and Processing
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-62
Dealing with Multi-Experiment Data and Merging Models
Introduction
The analysis and estimation functions in System Identification Toolbox let you work with
multiple batches of data. Essentially, if you have performed multiple experiments and
recorded several input-output datasets, you can group them up into a single IDDATA
object and use them with any estimation routine.
In some cases, you may want to "split up" your (single) measurement dataset to remove
portions where the data quality is not good. For example, portion of data may be
unusable due to external disturbance or a sensor failure. In those cases, each good
portion of data may be separated out and then combined into a single multi-experiment
IDDATA object.
load iddemo8
The name of the data object is dat, and let us view it.
dat
plot(dat)
dat =
2-63
2 Data Import and Processing
We see that there are some problems with the output around sample 250-280 and around
samples 600 to 650. These might have been sensor failures.
Therefore split the data into three separate experiments and put then into a multi-
experiment data object:
d1 = dat(1:250);
d2 = dat(281:600);
d3 = dat(651:1000);
d = merge(d1,d2,d3) % merge lets you create multi-exp IDDATA object
d =
2-64
Dealing with Multi-Experiment Data and Merging Models
d =
As mentioned before, all model estimation routines accept multi-experiment data and
take into account that they are recorded at different periods. Let us use the two first
experiments for estimation and the third one for validation:
2-65
2 Data Import and Processing
2-66
Dealing with Multi-Experiment Data and Merging Models
Also, spa, etfe, resid, predict, sim operate in the same way for multi-experiment
data, as they do for single experiment data.
There is another way to deal with separate data sets: a model can be computed for each
set, and then the models can be merged:
m4 = armax(getexp(de,1),[2 2 2 1]);
m5 = armax(getexp(de,2),[2 2 2 1]);
m6 = merge(m4,m5); % m4 and m5 are merged into m6
This is conceptually the same as computing m from the merged set de, but it is not
numerically the same. Working on de assumes that the signal-to-noise ratios are
2-67
2 Data Import and Processing
(about) the same in the different experiments, while merging separate models makes
independent estimates of the noise levels. If the conditions are about the same for the
different experiments, it is more efficient to estimate directly on the multi-experiment
data.
We can check the models m3 and m6 that are both ARMAX models obtained on the same
data in two different ways:
[m3.a;m6.a]
[m3.b;m6.b]
[m3.c;m6.c]
compare(dv,m3,m6)
ans =
ans =
0 1.0079 0.4973
0 1.0073 0.4989
ans =
2-68
Dealing with Multi-Experiment Data and Merging Models
We now turn to another situation. Let us consider two data sets generated by the system
m0. The system is given by:
m0
m0 =
Discrete-time identified state-space model:
x(t+Ts) = A x(t) + B u(t) + K e(t)
y(t) = C x(t) + D u(t) + e(t)
A =
x1 x2 x3
2-69
2 Data Import and Processing
B =
u1 u2
x1 -1.146 -0.03763
x2 1.191 0.3273
x3 0 0
C =
x1 x2 x3
y1 -0.1867 -0.5883 -0.1364
y2 0.7258 0 0.1139
D =
u1 u2
y1 1.067 0
y2 0 0
K =
y1 y2
x1 0 0
x2 0 0
x3 0 0
Parameterization:
STRUCTURED form (some fixed coefficients in A, B, C).
Feedthrough: on some input channels
Disturbance component: none
Number of free coefficients: 23
Use "idssdata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Created by direct construction or transformation. Not estimated.
The data sets that have been collected are z1 and z2, obtained from m0 with different
inputs, noise and initial conditions. These datasets are obtained from iddemo8.mat that
was loaded earlier.
pause off
2-70
Dealing with Multi-Experiment Data and Merging Models
plot(z1) %generates a separate plot for each I/O pair if pause is on; showing only the
plot(z2) %generates a separate plot for each I/O pair if pause is on; showing only the
2-71
2 Data Import and Processing
pause on
zzl =
2-72
Dealing with Multi-Experiment Data and Merging Models
y2
clf
2-73
2 Data Import and Processing
bode(m0,ml)
legend('show')
This is not a very good model, as observed from the four Bode plots above.
zzm = merge(z1,z2)
% The model for this data can be estimated as before (watching progress this time)
mm = ssest(zzm,3,'Ts',1,'Feedthrough',[true, false], ssestOptions('Display', 'on'));
zzm =
2-74
Dealing with Multi-Experiment Data and Merging Models
clf
bode(m0,'b',ml,'g',mm,'r')
legend('show')
2-75
2 Data Import and Processing
The merged data give a better model, as observed from the plot above.
Conclusions
In this example we analyzed how to use multiple data sets together for estimation of
one model. This technique is useful when you have multiple datasets from independent
experiment runs or when you segment data into multiple sets to remove bad segments.
Multiple experiments can be packaged into a single IDDATA object, which is then usable
for all estimation and analysis requirements. This technique works for both time and
frequency domain iddata.
It is also possible to merge models after estimation. This technique can be used to
"average out" independently estimated models. If the noise characteristics on multiple
2-76
Dealing with Multi-Experiment Data and Merging Models
datasets are different, merging models after estimation works better than merging the
datasets themselves before estimation.
Additional Information
2-77
2 Data Import and Processing
Note: You can modify the property SamplingInstants by setting it to a new vector
with the length equal to the number of data samples. For more information, see
“Constructing an iddata Object for Time-Domain Data” on page 2-50.
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-78
Managing iddata Objects
2-79
2 Data Import and Processing
• For multiexperiement
data with Ne experiments,
Frequency is a 1-by-Ne
cell array, and each cell
contains the frequencies
of the corresponding
experiment.
FrequencyUnit Unit of Frequency. Specify Set the frequency unit to Hz:
as one of the following: be
one of the following: 'rad/ data.FrequencyUnit = 'Hz'
TimeUnit', 'cycles/ Note that changing the
TimeUnit', 'rad/s', 'Hz', frequency unit does not scale
'kHz', 'MHz', 'GHz', and, the frequency vector. For a
'rpm'. Default: ‘rad/ proper translation of units, use
TimeUnit’ chgFreqUnit.
2-80
Managing iddata Objects
A multivariate system might contain several input variables or several output variables,
or both. When an input or output signal includes several measured variables, these
variables are called channels.
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 14-14.
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'.
Adding Channels
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:
2-81
2 Data Import and Processing
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 “Increasing Number of
Channels or Data Points of iddata Objects” on page 2-58.
After you create an iddata object, you can modify or remove specific input and output
channels, if needed. You can accomplish this by subreferencing the input and output
matrices and assigning new values.
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-82
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 “Frequency-Response Data
Representation” on page 2-13.
Note: The idfrd object can only encapsulate one frequency-response data set. It does not
support the iddata equivalent of multiexperiment data.
Suppose that ny is the number of output channels, nu is the number of input channels,
and nf is a vector of frequency values. response is an ny-by-nu-by-nf 3-D array. f is the
frequency vector that contains the frequencies of the response.Ts is the sampling time,
which is used when measuring or computing the frequency response. If you are working
with a continuous-time system, set Ts to 0.
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).
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.
2-83
2 Data Import and Processing
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.1 s and get its properties:
f = logspace(-1,1,100);
[mag, phase] = bode(idtf([1 .2],[1 2 1 1]),f);
response = mag.*exp(1j*phase*pi/180);
fr_data = idfrd(response,f,0.1);
get(fr_data)
FrequencyUnit: 'rad/TimeUnit'
Report: [1x1 idresults.frdest]
SpectrumData: []
CovarianceData: []
NoiseCovariance: []
InterSample: {'zoh'}
ResponseData: [1x1x100 double]
ioDelay: 0
InputDelay: 0
OutputDelay: 0
Ts: 0.1000
TimeUnit: 'seconds'
InputName: {''}
InputUnit: {''}
InputGroup: [1x1 struct]
OutputName: {''}
OutputUnit: {''}
OutputGroup: [1x1 struct]
Name: ''
Notes: {}
UserData: []
SamplingGrid: [1x1 struct]
Frequency: [100x1 double]
For a complete description of all idfrd object properties, see the idfrd reference page.
2-84
Representing Frequency-Response Data Using idfrd Objects
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:
fr_data.Name = 'DC_Converter';
Tip Use a colon (:) to specify all channels, and use the empty matrix ([]) to specify no
channels.
For example, the following command references frequency-response data from input
channel 3 to output channel 2:
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'})
To retrieve only the responses corresponding to frequency values between 200 and 300,
use the following command:
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).
2-85
2 Data Import and Processing
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.
The horizontal and vertical concatenation of idfrd objects combine information in the
ResponseData properties of these objects. ResponseData is an ny-by-nu-by-nf array
that stores the response of the system, where ny is the number of output channels, nu is
the number of input channels, and nf is a vector of frequency values (see “Properties”).
The following syntax creates a new idfrd object data that contains the horizontal
concatenation of data1,data2,...,dataN:
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-86
Representing Frequency-Response Data Using idfrd Objects
Note: Horizontal concatenation of idfrd objects requires that they have the same
outputs and frequency vectors. If the output channel names are different and their
dimensions are the same, the concatenation operation resets the output names to their
default values.
The following syntax creates a new idfrd object data that contains the vertical
concatenation of data1,data2,...,dataN:
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
y1
Same u1 Vertical Concatenation Combined
of Data 1 and Data 2 y2
inputs u2 outputs
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 resets the input names to their default values.
When the SpectrumData property of individual idfrd objects is not empty, horizontal
and vertical concatenation handle SpectrumData, as follows.
2-87
2 Data Import and Processing
Ê data1 .s
Á 0 ˆ˜
data.s = Á O ˜
ÁÁ ˜
Ë 0 dataN .s ˜¯
See “Select I/O Channels and Data in idfrd Objects” on page 2-85.
2-88
Representing Frequency-Response Data Using idfrd Objects
For example:
sys_idpoly = idpoly([1 2 1],[0 2],'Ts',1);
G = idfrd(sys_idpoly,linspace(0,pi,128))
G =
IDFRD model.
Contains Frequency Response Data for 1 output(s) and 1 input(s), and the spectra for
Response data and disturbance spectra are available at 128 frequency points, ranging
2-89
2 Data Import and Processing
In this section...
“Is Your Data Ready for Modeling?” on page 2-90
“Plotting Data in the App Versus at the Command Line” on page 2-91
“How to Plot Data in the App” on page 2-91
“How to Plot Data at the Command Line” on page 2-96
“How to Analyze Data Using the advice Command” on page 2-98
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.
• Spectral plot — Shows a periodogram that is computed by taking the absolute squares
of the Fourier transforms of the data, dividing by the number of data points, and
multiplying by the sampling interval.
• Frequency-response plot — For frequency-response data, shows the amplitude and
phase of the frequency-response function on a Bode plot. For time- and frequency-
domain data, shows the empirical transfer function estimate (see etfe) .
See Also
2-90
Analyzing Data Quality
The plots you create using the plot commands, such as plot, and bode 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-96. For more
information about working with Figure window, see “Graphics”.
After importing data into the System Identification app, as described in “Represent
Data”, you can plot the data.
To create one or more plots, select the corresponding check box in the Data Views area
of the System Identification app.
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 app. Clicking the data
icon updates any plots that are currently open.
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 14-14.
2-91
2 Data Import and Processing
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 app.
Tip To get information about working with a specific plot, select a help topic from the
Help menu in the plot window.
The Time plot only shows time-domain data. In this example, data1 is displayed on
the time plot because, of the three data sets, it is the only one that contains time-domain
input and output.
2-92
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” on page 14-11.
Action Command
Toggle input display between piece-wise Select Style > Staircase input for zero-
continuous (zero-order hold) and linear order hold or Style > Regular input for
interpolation (first-order hold) between first-order hold.
samples.
2-93
2 Data Import and Processing
The Data spectra plot shows a periodogram or a spectral estimate of data1 and
data3fd.
The periodogram is computed by taking the absolute squares of the Fourier transforms
of the data, dividing by the number of data points, and multiplying by the sampling
interval. The spectral estimate for time-domain data is a smoothed spectrum calculated
using spa. For frequency-domain data, the Data spectra plot shows the square of the
absolute value of the actual data, normalized by the sampling interval.
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-94
Analyzing Data Quality
Action Command
Toggle display between periodogram and Select Options > Periodogram or
spectral estimate. Options > Spectral analysis.
Change frequency units. Select Style > Frequency (rad/s) or Style
> Frequency (Hz).
Toggle frequency scale between linear and Select Style > Linear frequency scale or
logarithmic. Style > Log frequency scale.
Toggle amplitude scale between linear and Select Style > Linear amplitude scale or
logarithmic. Style > Log amplitude scale.
For time-domain data, the Frequency function plot shows the empirical transfer
function estimate (etfe). For frequency-domain data, the plot shows the ratio of output
to input data.
The frequency-response plot shows the amplitude and phase plots of the corresponding
frequency response. For more information about frequency-response data, see
“Frequency-Response Data Representation” on page 2-13.
2-95
2 Data Import and Processing
Action Command
Change frequency units. Select Style > Frequency (rad/s) or Style
> Frequency (Hz).
Toggle frequency scale between linear and Select Style > Linear frequency scale or
logarithmic. Style > Log frequency scale.
Toggle amplitude scale between linear and Select Style > Linear amplitude scale or
logarithmic. Style > Log amplitude scale.
2-96
Analyzing Data Quality
All plot commands display the data in the standard MATLAB Figure window. For more
information about working with the Figure window, see “Graphics”.
To plot portions of the data, you can subreference specific samples (see “Select Data
Channels, I/O Data and Experiments in iddata Objects” on page 2-55 and “Select I/O
Channels and Data in idfrd Objects” on page 2-85. 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.SamplingInstants,data.u)
2-97
2 Data Import and Processing
semilogx(data.Frequency,abs(data.u))
When you specify to plot a multivariable iddata object, each input-output combination is
displayed one at a time in the same MATLAB Figure window. You must press Enter to
update the Figure window and view the next channel combination. To cancel the plotting
operation, press Ctrl+C.
Tip To plot specific input and output channels, use plot(data(:,ky,ku)), where ky
and ku are specific output and input channel indexes or names. For more information
about subreferencing channels, see “Subreferencing Data Channels” on page 2-56.
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-50.
If you are using the System Identification app, 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 App to the MATLAB
Workspace” on page 14-10.
Use the following syntax to get advice about an iddata object data:
advice(data)
2-98
Analyzing Data Quality
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.
• Is there an indication of nonlinearity in the process that generated the data?
See Also
advice
delayest
detrend
feedback
pexcit
2-99
2 Data Import and Processing
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 “Create Data Sets from a Subset of Signal
Channels” on page 2-33 or “Representing Time- and Frequency-Domain Data Using
iddata Objects” on page 2-50.
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.
Selecting potions of frequency-domain data is equivalent to filtering the data. For more
information about filtering, see “Filtering Data” on page 2-123.
2-100
Selecting Subsets of Data
You can use System Identification app to select ranges of data on a time-domain or
frequency-domain plot. Selecting data in the frequency domain is equivalent to passband-
filtering the data.
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 “Specify Estimation and Validation Data in the App” on page 2-30.
Note: Selecting <--Preprocess > Quick start performs the following actions
simultaneously:
You can select a range of data values on a time plot and save it as a new data set in the
System Identification app.
Note: Selecting data does not extract experiments from a data set containing
multiple experiments. For more information about multiexperiment data, see “Create
Multiexperiment Data Sets in the App” on page 2-35.
1 Import time-domain data into the System Identification app, as described in “Create
Data Sets from a Subset of Signal Channels” on page 2-33.
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.
2-101
2 Data Import and Processing
Although you view only one I/O channel pair at a time, your data selection is applied
to all channels in this data set.
4 Select the data of interest in either of the following ways:
28.5 56.8
• By specifying the Samples range — Edit the beginning and the end indices of the
sample range. The Time span field is updated to match the selected region. For
example:
342 654
Selecting a range of values in frequency domain is equivalent to filtering the data. For
more information about data filtering, see “Filtering Frequency-Domain or Frequency-
Response Data in the App” on page 2-126.
For more information about subreferencing time-domain and frequency-domain data, see
“Select Data Channels, I/O Data and Experiments in iddata Objects” on page 2-55.
2-102
Selecting Subsets of Data
For more information about subreferencing frequency-response data, see “Select I/O
Channels and Data in idfrd Objects” on page 2-85.
2-103
2 Data Import and Processing
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-50.
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.
dat = iddata(y,u,0.2) % y and u contain NaNs
% representing missing data
Apply the misdata command to the new data object. For example:
dat1 = misdata(dat);
2-104
Handling Missing Data and Outliers
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 10-23.
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 “Extract and Model Specific Data Segments” on page
2-106). For more information about selecting and extracting data segments, see
“Selecting Subsets of Data” on page 2-100.
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-104. Use this method when your
data contains several inputs and outputs, and when you have difficulty finding
reliable data segments in all variables.
2-105
2 Data Import and Processing
• 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-123.
Note: The estimation algorithm can handle outliers by assigning a smaller weight
to outlier data. A robust error criterion applies an error penalty that is quadratic for
small and moderate prediction errors, and is linear for large prediction errors. Because
outliers produce large prediction errors, this approach gives a smaller weight to the
corresponding data points during model estimation. Set the ErrorThreshold estimation
option (see Advanced.ErrorThreshold in, for example, polyestOptions) to a
nonzero value to activate the correction for outliers in the estimation algorithm.
Assume that the data has poor or no measurements for some sample ranges (for
example 341–499). 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-106
Handling Missing Data and Outliers
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-107
2 Data Import and Processing
For steady-state data, you should remove mean values and linear trends from both input
and output signals.
For transient data, you should remove physical-equilibrium offsets measured prior to the
excitation input signal.
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:
• Linear models that capture offsets essential for describing important system
dynamics. For example, when a model contains integration behavior, you could
estimate a low-order transfer function (process model) from nondetrended data. For
more information, see “Identifying Process Models”.
• Nonlinear black-box models, such as nonlinear ARX or Hammerstein-Wiener models.
For more information, see “Nonlinear Model Identification”.
Tip When signals vary around a large signal level, you can improve computational
accuracy of nonlinear models by detrending the signal means.
2-108
Examples
• Nonlinear ODE parameters (nonlinear grey-box models). For more information, see
“Estimating Nonlinear Grey-Box Models”.
To simulate or predict the linear model response at the system operating conditions,
you can restore the removed trend to the simulated or predicted model output using the
retrend command.
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.
Examples
“How to Detrend Data Using the App” on page 2-111
Both the app and the command line let you subtract the mean values and one linear
trend from steady-state time-domain signals.
However, the detrend command provides the following additional functionality (not
available in the app):
As an alternative to detrending data beforehand, you can specify the offsets levels as
estimation options and use them directly with the estimation command.
2-109
2 Data Import and Processing
For example, suppose your data has an input offset, u0, and an output offset, y0. There
are two ways to perform a linear model estimation (say, a transfer function model
estimation) using this data:
• Using detrend:
T=getTrend(data)
T.InputOffset = u0;
T.OutputOffset = y0;
datad = detrend(data, T);
The advantage of this approach is that there is a record of offset levels in the model
in model.Report.OptionsUsed. The limitation of this approach is that it cannot
handle linear trends, which can only be removed from the data by using detrend.
• Perform other data preprocessing operations. See “Ways to Prepare Data for System
Identification” on page 2-6.
• Estimate a linear model. See “Linear Model Identification”.
2-110
How to Detrend Data Using the App
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 app, drag the data set you want to detrend to the
Working Data rectangle.
2 Detrend the data.
More About
“Handling Offsets and Trends in Data” on page 2-108
2-111
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)
where data is the data to be detrended. The second input argument Type=0 removes
signal means or Type=1 removes linear trends. data_d is the detrended data. T is
a TrendInfo object that stores the values of the subtracted offsets and slopes of the
removed trends.
More About
“Handling Offsets and Trends in Data” on page 2-108
2-112
More About
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-96.
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;
T.OutputOffset=O_value;
where I_value is the input offset value, and O_value is the input offset value.
3 Remove the specified offsets from data.
data_d = detrend(data,T)
where the second input argument T stores the offset values as its properties.
More About
“Handling Offsets and Trends in Data” on page 2-108
See Also
detrend
TrendInfo
2-113
2 Data Import and Processing
Resampling Data
In this section...
“What Is Resampling?” on page 2-114
“Resampling Data Without Aliasing Effects” on page 2-115
“See Also” on page 2-119
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 new 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 app (zero-order or first-order
hold). For more information about the data properties you specify before importing the
data, see “Represent Data”.
You can resample data using the System Identification app or the resample command.
You can only resample time-domain data at uniform time intervals.
Examples
“Resampling Data Using the App” on page 2-120
2-114
Examples
The command resample performs the decimation without aliasing effects. This
command includes a factor of T to normalize the spectrum and preserve the energy
density after decimation. For more information about spectrum normalization, see
“Spectrum Normalization” on page 3-13.
If you use manual decimation instead of resample—by picking every fourth sample from
the signal, for example—the energy contributions from higher frequencies are folded
back into the lower frequencies("aliasing"). Because the total signal energy is preserved
by this operation and this energy must now be squeezed into a smaller frequency range,
the amplitude of the spectrum at each frequency increases. Thus, the energy density of
the decimated signal is not constant.
Estimate the spectrum of the modified signal including every fourth sample of the
original signal. This command automatically sets Ts to 4.
g2 = spa(y(1:4:2000));
2-115
2 Data Import and Processing
h = spectrumplot(g1,g2,g1.Frequency);
opt = getoptions(h);
opt.FreqScale='linear';
opt.FreqUnits='Hz';
setoptions(h,opt);
Estimate the spectrum after prefiltering that does not introduce folding effects.
g3 = spa(resample(y,1,4));
figure
spectrumplot(g1,g3,g1.Frequency,opt);
2-116
Examples
Use resample to decimate the signal before estimating the spectrum and plot the
frequency response.
g3 = spa(resample(y,1,4));
figure
spectrumplot(g1,g3,g1.Frequency,opt);
2-117
2 Data Import and Processing
The plot 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.
Examples
“Resampling Data Using the App” on page 2-120
2-118
Examples
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-119
2 Data Import and Processing
The System Identification app uses idresamp to interpolate or decimate the data. For
more information about this command, type help idresamp at the prompt.
To create a new data set by resampling the input and output signals:
1 Import time-domain data into the System Identification app, as described in “Create
Data Sets from a Subset of Signal Channels” on page 2-33.
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.
6 Click Close to close the Resample dialog box.
More About
“Resampling Data” on page 2-114
2-120
Resampling Data at the Command Line
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.
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.
The data.InterSample property of the iddata object is taken into account during
resampling (for example, first-order hold or zero-order hold). For more information, see
“iddata Properties” on page 2-52.
2-121
2 Data Import and Processing
More About
“Resampling Data” on page 2-114
2-122
Filtering Data
Filtering Data
In this section...
“Supported Filters” on page 2-123
“Choosing to Prefilter Your Data” on page 2-123
“See Also” on page 2-124
Supported Filters
You can filter the input and output signals through a linear filter before estimating a
model in the System Identification app or at the command line. How you want to handle
the noise in the system determines whether it is appropriate to prefilter the data.
Examples
“How to Filter Data Using the App” on page 2-125
In addition to minimizing noise, prefiltering lets you focus your model on specific
frequency bands. The frequency range of interest often corresponds to a passband over
the breakpoints on a Bode plot. For example, if you are modeling a plant for control-
design applications, you might prefilter the data to specifically enhance frequencies
around the desired closed-loop bandwidth.
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-123
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.
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.
Examples
“How to Filter Data Using the App” on page 2-125
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 prefiltering data, see the chapter on preprocessing data in
System Identification: Theory for the User, Second Edition, by Lennart Ljung, Prentice
Hall PTR, 1999.
For practical examples of prefiltering data, see the section on posttreatment of data in
Modeling of Dynamic Systems, by Lennart Ljung and Torkel Glad, Prentice Hall PTR,
1994.
2-124
How to Filter Data Using the App
In this section...
“Filtering Time-Domain Data in the App” on page 2-125
“Filtering Frequency-Domain or Frequency-Response Data in the App” on page 2-126
2-125
2 Data Import and Processing
For example:
Tip 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).
6 In the Range is list, select one of the following:
More About
“Filtering Data” on page 2-123
1 Import data into the System Identification app, as described in “Represent Data”.
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.
2-126
More About
For example:
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).
6 In the Range is list, select one of the following:
More About
“Filtering Data” on page 2-123
2-127
2 Data Import and Processing
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:
fdata = idfilt(data,[wl wh])
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.
For time-domain data, the passband filtering is cascaded Butterworth filters of specified
order. The default filter order is 5. The Butterworth filter is the same as butter in the
Signal Processing Toolbox product. For frequency-domain data, select the indicated
portions of the data to perform passband filtering.
2-128
More About
More About
“Filtering Data” on page 2-123
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 can define a general single-input/single-output (SISO) system for filtering time-
domain or frequency-domain data. For frequency-domain only, you can specify the
(nonparametric) frequency response of the filter.
You use this syntax to filter an iddata object data using a custom filter specified by
filter:
fdata = idfilt(data,filter)
idm is a SISO identified linear model or LTI object. For more information about LTI
objects, see the Control System Toolbox documentation.
{num,den} defines the filter as a transfer function as a cell array of numerator and
denominator filter coefficients.
Specifically for frequency-domain data, you specify the frequency response of the filter:
filter = Wf
Here, Wf is a vector of real or complex values that define the filter frequency response,
where the inputs and outputs of data at frequency data.Frequency(kf) are
2-129
2 Data Import and Processing
multiplied by Wf(kf). Wf is a column vector with the length equal to the number of
frequencies in data.
When data contains several experiments, Wf is a cell array with the length equal to the
number of experiments in data.
More About
“Filtering Data” on page 2-123
fdata = idfilt(data,filter,'noncausal')
For frequency-domain data, the signals are multiplied by the frequency response of the
filter. With the filters defined as passband filters, this calculation gives ideal, zero-phase
filtering (“brick wall filters”). Frequencies that have been assigned zero weight by the
filter (outside the passband or via frequency response) are removed.
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-143). The result is an iddata object.
More About
“Filtering Data” on page 2-123
2-130
Generate Data Using Simulation
Simulating output data requires that you have a model with known coefficients.
For more information about commands for constructing models, see “Commands for
Constructing Model Structures” on page 1-22.
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-131
2 Data Import and Processing
Create a periodic input for one input and consisting of five periods, where each period is
300 samples.
Create an iddata object using the periodic input and leaving the output empty.
u = iddata([],per_u,'Period',.300);
2-132
Generate Data Using Simulation
2-133
2 Data Import and Processing
You use the generated data to estimate a model of the same order as the model used to
generate the data. Then, you check how closely both models match to understand the
effects of input data characteristics and noise on the estimation.
A = [1 -1.2 0.7];
B = {[0 1 0.5 0.1],[0 1.5 -0.5],[0 -0.1 0.5 -0.1]};
2-134
Generate Data Using Simulation
C = [1 0 0 0 0];
Ts = 1;
m0 = idpoly(A,B,C,'Ts',1);
The leading zeros in the B matrix indicate the input delay (nk), which is 1 for each input
channel.
u = idinput([255,3],'prbs');
y = sim(m0,u,simOptions('AddNoise',true));
iodata = iddata(y,u,m0.Ts);
na = 2;
nb = [3 2 3];
nc = 4;
nk = [1 1 1];
me = armax(iodata,[na,nb,nc,nk]);
compare(iodata,me);
2-135
2 Data Import and Processing
2-136
Transforming Between Time- and Frequency-Domain Data
In this section...
“Transforming Data Domain in the App” on page 2-137
“Transforming Data Domain at the Command Line” on page 2-141
In the System Identification app, time-domain data has an icon with a white background.
You can transform time-domain data to frequency-domain or frequency-response data.
The frequency values of the resulting frequency vector range from 0 to the Nyquist
frequency fS = p Ts , where Ts is the sampling interval.
1 In the System Identification app, drag the icon of the data you want to transform to
the Working Data rectangle.
2 In the Operations area, select <--Preprocess > Transform data in the drop-down
menu to open the Transform Data dialog box.
3 In the Transform to list, select one of the following:
• Frequency Function — Create a new idfrd object using the spafdr method.
Go to step 4.
2-137
2 Data Import and Processing
• Frequency Domain Data — Create a new iddata object using the fft method.
Go to step 6.
4 In the Frequency Spacing list, select the spacing of the frequencies at which the
frequency function is estimated:
In the System Identification app, frequency-domain data has an icon with a green
background. You can transform frequency-domain data to time-domain or frequency-
response (frequency-function) data.
2-138
Transforming Between Time- and Frequency-Domain Data
1 In the System Identification app, drag the icon of the data you want to transform to
the Working Data rectangle.
2 Select <--Preprocess > Transform data.
3 In the Transform to list, select one of the following:
• Frequency Function — Create a new idfrd object using the spafdr method.
Go to step 4.
• Time Domain Data — Create a new iddata object using the ifft (inverse fast
Fourier transform) method. Go to step 6.
4 In the Frequency Spacing list, select the spacing of the frequencies at which the
frequency function is estimated:
In the System Identification app, frequency-response data has an icon with a yellow
background. You can transform frequency-response data to frequency-domain data
(iddata object) or to frequency-response data with a different frequency resolution.
For the multiple-input case, the toolbox transforms the frequency-response data to
frequency-domain data as if each input contributes independently to the entire output
of the system and then combines information. For example, if a system has three inputs,
u1, u2, and u3 and two frequency samples, the input matrix is set to:
2-139
2 Data Import and Processing
È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 number of frequencies), the input matrix
has nu columns and (ns ◊ nu) rows.
Note: To create a separate experiment for the response from each input, see
“Transforming Between Frequency-Domain and Frequency-Response Data” on page
2-143.
When you transform frequency-response data by changing its frequency resolution, you
can modify the number of frequency values by changing between linear or logarithmic
spacing. You might specify variable frequency spacing to increase the number of data
points near the system resonance 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 app 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 app, drag the icon of the data you want to transform to
the Working Data rectangle.
2 Select <--Preprocess > Transform data.
3 In the Transform to list, select one of the following:
2-140
Transforming Between Time- and Frequency-Domain Data
4 In the Frequency Spacing list, select the spacing of the frequencies at which the
frequency function is estimated:
See Also
To learn how to transform data at the command line instead of the app, see
“Transforming Data Domain at the Command Line” on page 2-141.
The following table shows the different ways you can transform data from one data
domain to another. If the transformation is supported for a given row and column
combination in the table, the method used by the software is listed in the cell at their
intersection.
2-141
2 Data Import and Processing
The iddata object stores time-domain or frequency-domain data. The following table
summarizes the commands for transforming data between time and frequency domains.
t_data =
ifft(f_data)
2-142
Transforming Between Time- and Frequency-Domain Data
dataf = iddata(idfrdobj)
The resulting frequency-domain iddata object contains values at the same frequencies
as the original idfrd object.
For the multiple-input case, the toolbox represents frequency-response data as if each
input contributes independently to the entire output of the system and then combines
information. For example, if a system has three inputs, u1, u2, and u3 and two frequency
samples, the input matrix is set to:
2-143
2 Data Import and Processing
È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 have ny outputs, the transformation operation produces an output matrix has ny
columns and (ns ◊ nu) rows using the values in the complex frequency response G(iw)
matrix (ny-by-nu-by-ns). In this example, y1 is determined by unfolding G(1,1,:),
G(1,2,:), and G(1,3,:) into three column vectors and vertically concatenating
these vectors into a single column. Similarly, y2 is determined by unfolding G(2,1,:),
G(2,2,:), and G(2,3,:) into three column vectors and vertically concatenating these
vectors.
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')
In this example, the additional argument 'me' specifies that multiple experiments are
created.
See Also
2-144
Manipulating Complex-Valued Data
Model transformation routines, such as freqresp and zpkdata, work for complex-
valued models. However, they do not provide pole-zero confidence regions. For complex
models, the parameter variance-covariance information refers to the complex-valued
parameters and the accuracy of the real and imaginary is not computed separately.
The display commands compare and plot also work with complex-valued data
and models. 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.
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.
2-145
2 Data Import and Processing
Command Description
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-146
3
3-2
Black-Box Modeling
Black-Box Modeling
In this section...
“Selecting Black-Box Model Structure and Order” on page 3-3
“When to Use Nonlinear Model Structures?” on page 3-4
“Black-Box Estimation Example” on page 3-5
The simplest linear black-box structures require the fewest options to configure:
You can configure a model structure using the model order. The definition of model order
varies depending on the type of model you select. For example, if you choose a transfer
function representation, the model order is related to the number of poles and zeros. For
state-space representation, the model order corresponds to the number of states. In some
cases, such as for linear ARX and state-space model structures, you can estimate the
model order from the data.
3-3
3 Linear Model Identification
If the simple model structures do not produce good models, you can select more complex
model structures by:
• Specifying a higher model order for the same linear model structure. Higher model
order increases the model flexibility for capturing complex phenomena. However,
unnecessarily high orders can make the model less reliable.
• Explicitly modeling the noise:
y(t)=Gu(t)+He(t)
where H models the additive disturbance by treating the disturbance as the output of
a linear system driven by a white noise source e(t).
Using a model structure that explicitly models the additive disturbance can help
to improve the accuracy of the measured component G. Furthermore, such a model
structure is useful when your main interest is using the model for predicting future
response values.
• Using a different linear model structure.
Nonlinear models have more flexibility in capturing complex phenomena than linear
models of similar orders. See “Available Nonlinear Models”.
Ultimately, you choose the simplest model structure that provides the best fit to your
measured data. For more information, see “Estimating Linear Models Using Quick
Start”.
Regardless of the structure you choose for estimation, you can simplify the model for your
application needs. For example, you can separate out the measured dynamics (G) from
the noise dynamics (H) to obtain a simpler model that represents just the relationship
between y and u. You can also linearize a nonlinear model about an operating point.
3-4
Black-Box Modeling
You can assess the need to use a nonlinear model structure by plotting the response of
the system to an input. If you notice that the responses differ depending on the input
level or input sign, try using a nonlinear model. For example, if the output response to
an input step up is faster than the response to a step down, you might need a nonlinear
model.
Before building a nonlinear model of a system that you know is nonlinear, try
transforming the input and output variables such that the relationship between the
transformed variables is linear. For example, consider a system that has current and
voltage as inputs to an immersion heater, and the temperature of the heated liquid as
an output. The output depends on the inputs via the power of the heater, which is equal
to the product of current and voltage. Instead of building a nonlinear model for this two-
input and one-output system, you can create a new input variable by taking the product
of current and voltage and then build a linear model that describes the relationship
between power and temperature.
If you cannot determine variable transformations that yield a linear relationship between
input and output variables, you can use nonlinear structures such as Nonlinear ARX or
Hammerstein-Wiener models. For a list of supported nonlinear model structures and
when to use them, see “Available Nonlinear Models”.
G ( s) =
(b0 + b1 s + b2 s2 + ...)
(1 + f1s + f2s2 + ...)
For the mass-spring damper system, this transfer function is:
3-5
3 Linear Model Identification
1
G ( s) =
( ms 2
+ cs + k )
bz-1
G ( z -1 ) =
(1 + f1 z-1 + f2 z-2 )
where the model orders correspond to the number of coefficients of the numerator and
the denominator (nb = 1 and nf = 2) and the input-output delay equals the lowest order
exponent of z–1 in the numerator (nk = 1).
In continuous-time, you can build a linear transfer function model using the tfest
command:
m = tfest(data, 2, 0)
where data is your measured input-output data, represented as an iddata object and
the model order is the set of number of poles (2) and the number of zeros (0).
Similarly, you can build a discrete-time model Output Error structure using the following
command:
m = oe(data, [1 2 1])
The model order is [nb nf nk] = [1 2 1]. Usually, you do not know the model orders
in advance. You should try several model order values until you find the orders that
produce an acceptable model.
In black-box modeling, you do not need the system’s equation of motion—only a guess of
the model orders.
3-6
Black-Box Modeling
For more information about building models, see “Steps for Using the System
Identification App” and “Model Estimation Commands”.
3-7
3 Linear Model Identification
For a discrete-time system sampled with a time interval T, the frequency-response model
G(z) relates the Z-transforms of the input U(z) and output Y(z):
Y ( z) = G ( z)U ( z)
The estimation result is an idfrd model, which stores the estimated frequency response
and its covariance.
3-8
Identifying Frequency-Response Models
1 In the System Identification app, select Estimate > Spectral models to open the
Spectral Model dialog box.
2 In the Method list, select the spectral analysis method you want to use. For
information about each method, see “Selecting the Method for Computing Spectral
Models” on page 3-11.
3 Specify the frequencies at which to compute the spectral model in one of the
following ways:
For time-domain data, the frequency ranges from 0 to the Nyquist frequency. For
frequency-domain data, the frequency ranges from the smallest to the largest
frequency in the data set.
4 In the Frequency Resolution field, enter the frequency resolution, as described in
“Controlling Frequency Resolution of Spectral Models ” on page 3-12. To use the
default value, enter default or, equivalently, the empty matrix [].
3-9
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
app.
7 In the Spectral Model dialog box, click Close.
8 To view the frequency-response plot, select the Frequency resp check box in the
System Identification app. For more information about working with this plot, see
“Frequency Response Plots” on page 10-38.
9 To view the estimated disturbance spectrum, select the Noise spectrum check box
in the System Identification app. For more information about working with this plot,
see “Noise Spectrum Plots” on page 10-46.
10 Validate the model after estimating it. For more information, see “Model Validation”.
To export the model to the MATLAB workspace, drag it to the To Workspace rectangle
in the System Identification app. You can retrieve the responses from the resulting
idfrd model object using the bode or nyquist command.
The resulting models are stored as idfrd model objects. For detailed information about
the commands and their arguments, see the corresponding reference page.
3-10
Identifying Frequency-Response Models
Validate the model after estimating it. For more information, see “Model Validation”.
For input-output data. This method computes the ratio of the Fourier transform of
the output to the Fourier transform of the input.
ETFE works well for highly resonant systems or narrowband systems. The drawback
of this method is that it requires linearly spaced frequency values, does not estimate
the disturbance spectrum, and does not provide confidence intervals. ETFE also
works well for periodic inputs and computes exact estimates at multiples of the
fundamental frequency of the input and their ratio.
• spa (SPectral Analysis)
3-11
3 Linear Model Identification
Frequency resolution is the size of the smallest frequency for which details in the
frequency response and the spectrum can be resolved by the estimate. A resolution of 0.1
rad/s means that the frequency response variations at frequency intervals at or below 0.1
rad/s are not resolved.
Specifying the frequency resolution for etfe and spa is different than for spafdr.
For etfe and spa, the frequency resolution is approximately equal to the following
value:
2p Ê 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.
A large value of M gives good resolution, but results in more uncertain estimates. If a
true frequency function has sharp peak, you should specify higher M values.
3-12
Identifying Frequency-Response Models
In case of etfe and spa, the frequency response is defined over a uniform frequency
range, 0-Fs/2 radians per second, where Fs is the sampling frequency—equal to twice
the Nyquist frequency. In contrast, spafdr lets you increase the resolution in a specific
frequency range, such as near a resonance frequency. Conversely, you can make the
frequency grid coarser in the region where the noise dominates—at higher frequencies,
for example. Such customizing of the frequency grid assists in the estimation process by
achieving high fidelity in the frequency range of interest.
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:
• Scalar value of the constant frequency resolution value in radians per second.
Note: The scalar R is inversely related to the M value used for etfe and spa.
• Vector of frequency values the same size as the frequency vector.
• Expression using MATLAB workspace variables and evaluates to a resolution vector
that is the same size as the frequency vector.
The default value of the resolution for spafdr is twice the difference between
neighboring frequencies in the frequency vector.
If the input data is marked as periodic and contains an integer number of periods
(data.Period is an integer), etfe computes the frequency response at frequencies
2 pk
(k
T Period ) 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
F y (w) = T Â Ry ( kT ) e-iwT WM ( k)
k= - M
3-13
3 Linear Model Identification
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 l =1
y( lT - kT) y(lT )
The scaling factor of T is necessary to preserve the energy density of the spectrum after
interpolation or decimation.
By Parseval's theorem, the average energy of the signal must equal the average energy in
the estimated spectrum, as follows:
1 p/T
Ey2 (t) = Ú
2 p - p/ T
F y (w) dw
S1 ∫ Ey2 (t)
1 p/T
S2 ∫ Ú F ( w) dw
2p -p / T y
To compare the left side of the equation (S1) to the right side (S2), enter the following
commands. In this code, phiy contains F y (w) between w = 0 and w = p T with the
frequency step given as follows:
Ê p ˆ
Á ˜
Ë T ◊ length(phiy) ¯
load iddata1
% Create a time-series iddata object.
y = z1(:,1,[]);
% Define sample interval from the data.
T = y.Ts;
% Estimate the frequency response.
sp = spa(y);
3-14
Identifying Frequency-Response Models
S1 =
19.2076
S2 =
19.4646
Thus, the average energy of the signal approximately equals the average energy in the
estimated spectrum.
3-15
3 Linear Model Identification
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
The response to an input u(t) is equal to the convolution of the impulse response, as
follows:
t
y( t) = Ú0 h ( t - z ) ◊ u(z)dz
3-16
Identifying Impulse-Response Models
Time-domain data must be regularly sampled. You cannot use time-series data for
correlation analysis.
• Imported data into the System Identification app. See “Import Time-Domain Data
into the App” on page 2-16. For supported data formats, see “Data Supported by
Correlation Analysis”.
• Performed any required data preprocessing operations. To improve the accuracy of
your model, you should detrend your data. See “Ways to Prepare Data for System
Identification” on page 2-6.
1 In the System Identification app, select Estimate > Correlation models to open
the Correlation Model dialog box.
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].
3 In the Order of whitening filter field, specify the filter order.
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
app.
3-17
3 Linear Model Identification
Next Steps
• Export the model to the MATLAB workspace for further analysis by dragging it to the
To Workspace rectangle in the System Identification app.
• View the transient response plot by selecting the Transient resp check box in the
System Identification app. For more information about working with this plot and
selecting to view impulse- versus step-response, see “Impulse and Step Response
Plots” on page 10-31.
To estimate the model m and plot the impulse or step response, use the following syntax:
m=impulseest(data,N);
impulse(m,Time);
step(m,Time);
You can also specify estimation options, such as regularizing kernel, pre-whitening
filter order and data offsets, using impulseestOptions and pass them as an input to
impulseest. For example:
opt = impulseestOptions('RegulKernel','TC'));
3-18
Identifying Impulse-Response Models
m = impulseest(data,N,opt);
To view the confidence region for the estimated response, use impulseplot and
stepplot to create the plot. Then use showConfidence.
For example:
h = stepplot(m,Time);
showConfidence(h,3) % 3 std confidence region
Note: cra is an alternative method for computing impulse response from time-domain
data only.
Next Steps
where y is the response data, t is the time vector, and ysd is the standard deviations
of the response.
3-19
3 Linear Model Identification
In the System Identification app. To view the transient response plot, select the
Transient resp check box in the System Identification app. For example, the following
step response plot shows a time delay of about 0.25 s before the system responds to the
input.
At the command line. You can use impulseplot to plot the impulse response. The
time delay is equal to the first positive peak in the transient response magnitude that is
greater than the confidence region for positive time values.
For example, the following commands create an impulse-response plot with a 1-standard-
deviation confidence region:
load dry2
ze = dry2(1:500);
opt = impulseestOptions('RegulKernel','TC');
sys = impulseest(ze,40,opt);
h = impulseplot(sys);
showConfidence(h,1);
3-20
Identifying Impulse-Response Models
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.
Instead of using showConfidence, you can plot the confidence interval interactively, by
right-clicking on the plot and selecting Characteristics > Confidence Region.
3-21
3 Linear Model Identification
The impulse response, g, is the system's output when the input is an impulse signal. The
output response to a general input, u(t), is obtained as the convolution with the impulse
response. In continuous time:
t
y( t) = Ú-• g (t ) u (t - t )dt
In discrete-time:
•
y (t ) = Â g (k) u ( t - k)
k= 1
The values of g(k) are the discrete time impulse response coefficients.
You can estimate the values from observed input-output data in several different ways.
impulseest estimates the first n coefficients using the least-squares method to obtain a
finite impulse response (FIR) model of order n.
uf = Au, yf = Ay
3 The filtered signals uf and yf are used for estimation.
3-22
Identifying Impulse-Response Models
This option is essential because, often, the model order n can be quite large. In
cases where there is no regularization, n can be automatically decreased to secure a
reasonable variance.
You can specify the regularizing kernel using the RegulKernel Name-Value pair
argument of impulseestOptions.
• Autoregressive Parameters — The basic underlying FIR model can be
complemented by NA autoregressive parameters, making it an ARX model.
n NA
y (t ) = Â g (k) u ( t - k) - Â ak y (t - k)
k= 1 k=1
This gives both better results for small n and allows unbiased estimates when
data are generated in closed loop. impulseest uses NA = 5 for t>0 and NA = 0 (no
autoregressive component) for t<0.
• Noncausal effects — Response for negative lags. It may happen that the data has
been generated partly by output feedback:
•
u(t) = Â h(k) y( t - k) + r (t )
k= 0
aligned so that it corresponds to lags [ nk, nk + 1,.., 0,1, 2,..., nb + nk] . This is achieved
because the input delay (InputDelay) of model mi is nk.
For a multi-input multi-output system, the impulse response g(k) is an ny-by-nu matrix,
where ny is the number of outputs and nu is the number of inputs. The i–j element of the
matrix g(k) describes the behavior of the ith output after an impulse in the jth input.
3-23
3 Linear Model Identification
Process models are popular for describing system dynamics in many industries and apply
to various production environments. The advantages of these models are that they are
simple, support transport delay estimation, and the model coefficients have an easy
interpretation as poles and zeros.
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).
3-24
Identifying Process Models
Kp
G ( s) = e- sTd
1 + sTp1
You must import your data into the MATLAB workspace, as described in “Data
Preparation”.
• Imported data into the System Identification app. See “Import Time-Domain Data
into the App” on page 2-16. For supported data formats, see “Data Supported by
Process Models” on page 3-25.
• 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 Prepare Data for System Identification” on page 2-6.
1 In the System Identification app, select Estimate > Process models to open the
Process Models dialog box.
3-25
3 Linear Model Identification
To learn more about the options in the dialog box, click Help.
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
“Estimating Multiple-Input, Multi-Output Process Models” on page 3-36.
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.
Note: You need at least two poles to allow underdamped modes (complex-
conjugate pair).
• 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.
3-26
Identifying Process Models
• 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.
The Parameter area shows as many active parameters as you included in the model
structure.
Note: By default, the model Name is set to the acronym that reflects the model
structure, as described in “Process Model Structure Specification” on page 3-35.
4 In the Initial Guess area, select Auto-selected to calculate the initial parameter
values for the estimation. The Initial Guess column in the 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.
5 (Optional) If you approximately know a parameter value, enter this value in the
Initial Guess column of the Parameter table. The estimation algorithm uses this
value as a starting point. If you know a parameter value exactly, enter this value in
the Initial Guess column, and also select the corresponding Known check box in
the table to fix its value.
3-27
3 Linear Model Identification
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.
6 In the Disturbance Model list, select one of the available options. For more
information about each option, see “Disturbance Model Structure for Process Models”
on page 3-37.
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 “Assigning Estimation
Weightings” on page 3-37.
8 In the Initial state list, specify how you want the algorithm to treat initial states.
For more information about the available options, see “Specifying Initial Conditions
for Iterative Estimation Algorithms” on page 3-38.
Tip If you get a bad fit, you might try setting a specific method for handling initial
states, rather than choosing it automatically.
3-28
Identifying Process Models
9 In the Covariance list, select Estimate if you want the algorithm to compute
parameter uncertainties. Effects of such uncertainties are displayed on plots as
model confidence regions.
Next Steps
• Validate the model by selecting the appropriate check box in the Model Views area
of the System Identification app. For more information about validating models, see
“Validating Models After Estimation” on page 10-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 Name field, and click
Estimate.
• Export the model to the MATLAB workspace for further analysis by dragging it to the
To Workspace rectangle in the System Identification app.
3-29
3 Linear Model Identification
Prerequisites
You can estimate process models using the iterative estimation method procest that
minimizes the prediction errors to obtain maximum likelihood estimates. The resulting
models are stored as idproc model objects.
You can use the following general syntax to both configure and estimate process models:
m = procest(data,mod_struc,opt)
• A string that represents the process model structure, as described in “Process Model
Structure Specification” on page 3-35.
• A template idproc model. opt is an option set for configuring the estimation of
the process model, such as handling of initial conditions, input offset and numerical
search method.
Tip You do not need to construct the model object using idproc before estimation unless
you want to specify initial parameter guesses, minimum/maximum bounds, or fixed
parameter values, as described in “Estimate Process Models with Fixed Parameters” on
page 3-32.
For more information about validating a process model, see “Validating Models After
Estimation” on page 10-2.
3-30
Identifying Process Models
You can use procest to refine parameter estimates of an existing process model, as
described in “Refining Linear Parametric Models” on page 3-86.
This example shows how to estimate the parameters of a first-order process model:
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.
load co2data
% Sampling interval is 0.5 min (known)
Ts = 0.5;
% Split data set into estimation data ze and validation data zv
ze = iddata(Output_exp1,Input_exp1,Ts,...
'TimeUnit','min');
zv = iddata(Output_exp2,Input_exp2,Ts,...
'TimeUnit','min');
Estimate model with one pole, a delay, and a first-order disturbance component. The
data contains known offsets. Specify them using the InputOffset and OutputOffset
options.
opt = procestOptions;
opt.InputOffset = [170;50];
opt.OutputOffset = -45;
opt.Display = 'on';
opt.DisturbanceModel = 'arma1';
m = procest(ze,'p1d',opt)
m =
Process model with 2 inputs: y = G11(s)u1 + G12(s)u2
From input "u1" to output "y1":
Kp
G11(s) = ---------- * exp(-Td*s)
1+Tp1*s
Kp = 2.6542
3-31
3 Linear Model Identification
Tp1 = 0.15451
Td = 2.3185
Kp = 9.9754
Tp1 = 2.0653
Td = 4.9195
C(s) = s + 2.677
D(s) = s + 0.6237
Parameterization:
'P1D' 'P1D'
Number of free coefficients: 8
Use "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using PROCEST on time domain data "ze".
Fit to estimation data: 91.07% (prediction focus)
FPE: 2.431, MSE: 2.412
Use dot notation to get the value of any model parameter. For example, get the value of
dc gain parameter Kp .
m.Kp
ans =
2.6542 9.9754
This example shows how to estimate a process model with fixed parameters.
When you know the values of certain parameters in the model and want to estimate only
the values you do not know, you must specify the fixed parameters after creating the
3-32
Identifying Process Models
idproc model object. Use the following commands to prepare the data and construct a
process model with one pole and a delay:
% Load data
load co2data
% Sampling interval is 0.5 min (known)
Ts = 0.5;
% Split data set into estimation data ze and validation data zv
ze = iddata(Output_exp1,Input_exp1,Ts,...
'TimeUnit','min');
zv = iddata(Output_exp2,Input_exp2,Ts,...
'TimeUnit','min');
mod = idproc({'p1d','p1d'},'TimeUnit','min')
mod =
Process model with 2 inputs: y = G11(s)u1 + G12(s)u2
From input 1 to output 1:
Kp
G11(s) = ---------- * exp(-Td*s)
1+Tp1*s
Kp = NaN
Tp1 = NaN
Td = NaN
Kp = NaN
Tp1 = NaN
Td = NaN
Parameterization:
'P1D' 'P1D'
Number of free coefficients: 6
Use "getpvec", "getcov" for parameters and their uncertainties.
Status:
Created by direct construction or transformation. Not estimated.
The model parameters Kp , Tp1 , and Td are assigned NaN values, which means that the
parameters have not yet been estimated from the data.
3-33
3 Linear Model Identification
Use the Structure model property to specify the initial guesses for unknown
parameters, minimum/maximum parameter bounds and fix known parameters.
Set the value of Kp for the second transfer function to 10 and specify it as a fixed
parameter. Initialize the delay values for the two transfer functions to 2 and 5 minutes,
respectively. Specify them as free estimation parameters.
mod.Structure(2).Kp.Value = 10;
mod.Structure(2).Kp.Free = false;
mod.Structure(1).Tp1.Value = 2;
mod.Structure(2).Td.Value = 5;
mod_proc =
Process model with 2 inputs: y = G11(s)u1 + G12(s)u2
From input "u1" to output "y1":
Kp
G11(s) = ---------- * exp(-Td*s)
1+Tp1*s
Kp = -3.2213
Tp1 = 2.522
Td = 3.8285
Kp = 10
Tp1 = 2.4382
Td = 4.111
Parameterization:
'P1D' 'P1D'
Number of free coefficients: 5
Use "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using PROCEST on time domain data "ze".
3-34
Identifying Process Models
In this case, the value of Kp is fixed, but Tp1 and Td are estimated.
In the System Identification app. Specify the model structure by selecting the
number of real or complex poles, and whether to include a zero, delay, and integrator.
The resulting transfer function is displayed in the Process Models dialog box.
At the command line. Specify the model structure using an acronym that includes the
following letters and numbers:
Kp
G ( s) = e- sTd
1 + sTp1
K p (1 + sTz )
G ( s) =
1 + 2 sz Tw + s2Tw2
3-35
3 Linear Model Identification
K p -sT
G ( s) = e d
s
• procest(data,'P3Z') to estimate the following structure:
K p (1 + sTz )
G ( s) =
(1 + sTp1 ) (1 + sT p2 )(1 + sTp3 )
For more information about estimating models, see “Estimate Process Models at the
Command Line” on page 3-29.
In the System Identification app. To fit a data set with multiple inputs, or multiple
outputs, or both, in the Process Models dialog box, configure the process model settings
for one input-output pair at a time. Use the input and output selection lists to switch to a
different input/output pair.
If you want the same transfer function to apply to all input/output pairs, select the All
same 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 procest. 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 = procest(data,m)
To apply the same structure to all inputs, define a single structure in idproc.
3-36
Identifying Process Models
In addition to the transfer function G, a linear system can include an additive noise term
He, as follows:
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.
In the app. To specify whether to include or exclude a noise model in the Process Models
dialog box, select one of the following options from the Disturbance Model list:
• 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.
At the command line. Specify the disturbance model using the procestOptions
option set. For example, use this command to estimate a first-order transfer function and
a first-order noise model:
opt = procestOptions;
opt.DisturbanceModel = 'arma1';
model = procest(data, 'P1D', opt);
For a complete list of values for the DisturbanceModel model property, see the
procestOptions reference page.
3-37
3 Linear Model Identification
App” on page 3-25 and “Estimate Process Models at the Command Line” on page
3-29.
In the System Identification app. 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 — 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 10-88.
• 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-128 or
“Defining a Custom Filter” on page 2-129. This prefiltering applies only for estimating
the dynamics from input to output. The disturbance model is determined from the
estimation data.
At the command line. Specify the focus using the procestOptions option set. For
example, use this command to optimize the fit for simulation and estimate a disturbance
model:
In the System Identification app. Set Initial condition to one of the following
options:
3-38
Identifying Process Models
At the command line. Specify the initial conditions using the InitialCondition
model estimation option, configured using the procestOptions command. For example,
use this command to estimate a first-order transfer function and set the initial states to
zero:
opt = procestOptions('InitialCondition','zero');
model = procest(data, 'P1D', opt)
3-39
3 Linear Model Identification
3-40
Identifying Input-Output Polynomial Models
In practice, not all the polynomials are simultaneously active. Often, simpler forms, such
as ARX, ARMAX, Output-Error, and Box-Jenkins are employed. You also have the option
of introducing an integrator in the noise source so that the general model takes the form:
nu
B (q) C( q) 1
A( q) y( t) = Â Fii(q) ui (t - nki ) + D(q) 1 - q-1 e(t)
i=1
You can estimate polynomial models using time or frequency domain data.
For estimation, 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.
The general polynomial equation is written in terms of the time-shift operator q–1. To
understand this time-shift operator, consider the following discrete-time difference
equation:
y( t) + a1 y(t - T) + a2 y(t - 2T ) =
b1u(t - T ) + b2 u( t - 2 T)
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 using
q-1u(t) = u( t - T ) :
3-41
3 Linear Model Identification
These model structures are subsets of the following general polynomial equation:
nu
B (q) C( q)
A( q) y( t) = Â Fii(q) ui (t - nki ) + D(q) e(t)
i=1
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.
The following table summarizes common linear polynomial model structures supported
by the System Identification Toolbox product. If you have a specific structure in mind for
your application, you can decide whether the dynamics and the noise have common or
different poles. A(q) corresponds to poles that are common for the dynamic model and the
noise model. Using common poles for dynamics and noise is useful when the disturbances
enter the system at the input. F i determines the poles unique to the system dynamics,
and D determines the poles unique to the disturbances.
3-42
Identifying Input-Output Polynomial Models
3-43
3 Linear Model Identification
The polynomial models can contain one or more outputs and zero or more inputs.
The System Identification app supports direct estimation of ARX, ARMAX, OE and BJ
models. You can add a noise integrator to the ARX, ARMAX and BJ forms. However,
you can use polyest to estimate all five polynomial or any subset of polynomials in the
general equation. For more information about working with pem, see “Using polyest to
Estimate Polynomial Models” on page 3-59.
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
You can only estimate continuous-time polynomial models directly using continuous-time
frequency-domain data. In this case, you must set the Ts data property to 0 to indicate
that you have continuous-time frequency-domain data, and use the oe command to
estimate an Output-Error polynomial model. Continuous-time models of other structures
3-44
Identifying Input-Output Polynomial Models
such as ARMAX or BJ cannot be estimated. You can obtain those forms only by direct
construction (using idpoly), conversion from other model types, or by converting a
discrete-time model into continuous-time (d2c). Note that the OE form represents a
transfer function expressed as a ratio of numerator (B) and denominator (F) polynomials.
For such forms consider using the transfer function models, represented by idtf models.
You can estimate transfer function models using both time and frequency domain data.
In addition to the numerator and denominator polynomials, you can also estimate
transport delays. See idtf and tfest for more information.
You can create multi-output polynomial models by using the idpoly command or
estimate them using ar, arx, bj, oe, armax, and polyest. In the app, you can estimate
such models by choosing a multi-output data set and setting the orders appropriately
in the Polynomial Models dialog box. For more details on the orders of multi-output
models, see “Polynomial Sizes and Orders of Multi-Output Polynomial Models” on page
3-61.
You can estimate linear, black-box polynomial models from data with the following
characteristics:
Note: For frequency-domain data, you can only estimate ARX and OE models.
3-45
3 Linear Model Identification
You must import your data into the MATLAB workspace, as described in “Data
Preparation”.
To get a linear, continuous-time model of arbitrary structure for time-domain data, you
can estimate a discrete-time model, and then use d2c to transform it to a continuous-
time model.
For continuous-time frequency-domain data, you can estimate directly only Output-
Error (OE) continuous-time models. Other structures include noise models, which is not
supported for frequency-domain data.
Tip To denote continuous-time frequency-domain data, set the data sampling interval
to 0. You can set the sampling interval when you import data into the app or set the Ts
property of the data object at the command line.
You can estimate arbitrary-order, linear state-space models for both time- or frequency-
domain data.
Tip You can set the sampling interval when you import data into the app or set the Ts
property of the data object at the command line.
3-46
Identifying Input-Output Polynomial Models
To estimate polynomial models, you must provide input delays and model orders. If you
already have insight into the physics of your system, you can specify the number of poles
and zeros.
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
10-23.
The following procedure assumes that you have already imported your data into the
app and performed any necessary preprocessing operations. For more information, see
“Represent Data”.
To estimate model orders and input delays in the System Identification app:
1 In the System Identification app, select Estimate > Polynomial Models to open
the Polynomials Models dialog box.
3-47
3 Linear Model Identification
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 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.
3-48
Identifying Input-Output Polynomial Models
4 Select a rectangle that represents the optimum parameter combination and click
Insert to estimates a model with these parameters. For information about using this
plot, see “Selecting Model Orders from the Best ARX Structure” on page 3-52.
This action adds a new model to the Model Board in the System Identification app.
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.
5 Click Close to close the ARX Model Structure Selection window.
Note: You cannot estimate model orders when using multi-output data.
After estimating model orders and delays, use these values as initial guesses for
estimating other model structures, as described in “Estimate Polynomial Models in the
App” on page 3-54.
3-49
3 Linear Model Identification
You can estimate model orders using the struc, arxstruc, and selstruc commands in
combination.
If you are working with a multiple-output system, you must use the struc, arxstruc,
and selstruc commands one output at a time. 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 “Select Data Channels, I/O Data and Experiments in iddata Objects” on page 2-55
and “Select I/O Channels and Data in idfrd Objects” on page 2-85.
For an example of estimating model orders for a multiple-input system, see “Estimating
Delays in the Multiple-Input System” in System Identification Toolbox Getting Started
Guide.
struc
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)
3-50
Identifying Input-Output Polynomial Models
[na nb nk]
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-52.
To find the structure that minimizes Akaike's Information Criterion, use the following
command:
nn = selstruc(V,'AIC')
Similarly, to find the structure that minimizes the Rissanen's Minimum Description
Length (MDL), use the following command:
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 polyest to Estimate Polynomial
Models” on page 3-59.
The delayest command estimates the time delay in a dynamic system by estimating a
low-order, discrete-time ARX model and treating the delay as an unknown parameter.
By default, delayest assumes that na=nb=2 and that there is a good signal-to-noise
ratio, and uses this information to estimate nk.
3-51
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-50.
You generate the ARX Model Structure Selection window for your data to select the best-
fit model.
For a procedure on generating this plot in the System Identification app, see “Estimating
Orders and Delays in the App” on page 3-47. To open this plot at the command line,
see “Estimating Model Orders at the Command Line” on page 3-50.
The following figure shows a sample plot in the ARX Model Structure Selection window.
3-52
Identifying Input-Output Polynomial Models
The prediction error is the sum of the squares of the differences between the
validation data output and the model one-step-ahead predicted output.
• nk is the delay.
Three rectangles are highlighted on the plot in green, blue, and red. Each color indicates
a type of best-fit criterion, as follows:
• Red — Best fit minimizes the sum of the squares of the difference between the
validation data output and the model output. This rectangle indicates the overall best
fit.
• Green — Best fit minimizes Rissanen MDL criterion.
• Blue — Best fit minimizes Akaike AIC criterion.
3-53
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 10-80.
Prerequisites
Before you can perform this task, you must have:
• Imported data into the System Identification app. See “Import Time-Domain Data
into the App” on page 2-16. For supported data formats, see “Data Supported by
Polynomial Models”.
• 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 Prepare Data for System Identification” on page 2-6.
• Select a model structure, model orders, and delays. For a list of available structures,
see “What Are Polynomial Models?” on page 3-40 For more information about how
to estimate model orders and delays, see “Estimating Orders and Delays in the App”
on page 3-47. For multiple-output models, you must specify order matrices in the
MATLAB workspace, as described in “Polynomial Sizes and Orders of Multi-Output
Polynomial Models” on page 3-61.
1 In the System Identification app, select Estimate > Polynomial Models to open
the Polynomial Models dialog box.
3-54
Prerequisites
For more information on the options in the dialog box, click Help.
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 Polynomial Models dialog box to correspond
with this model structure. For information about each model structure, see “What
Are Polynomial Models?” on page 3-40.
3-55
3 Linear Model Identification
Note: For time-series data, only AR and ARMA models are available. For more
information about estimating time-series models, see “Time-Series Model
Identification”.
3 In the Orders field, specify the model orders and delays, as follows:
• For single-output polynomial models. Enter the model orders and delays
according to the sequence displayed in the Structure field. For multiple-input
models, specify nb and nk as row vectors with as many elements as there are
inputs. If you are estimating BJ and OE models, you must also specify nf as a
vector.
For example, for a three-input system, nb can be [1 2 4], where each element
corresponds to an input.
• For multiple-output models. Enter the model orders, as described in
“Polynomial Sizes and Orders of Multi-Output Polynomial Models” on page
3-61.
Tip To enter model orders and delays using the Order Editor dialog box, click Order
Editor.
4 (ARX models only) Select the estimation Method as ARX or IV (instrumental
variable method). For information about the algorithms, see “Polynomial Model
Estimation Algorithms” on page 3-66.
5 (ARX, ARMAX, and BJ models only) Check the Add noise integration check box to
add an integrator to the noise source, e.
6 Specify the delay using the Input delay edit box. The value must be a vector
of length equal to the number of input channels in the data. For discrete-time
estimations (any estimation using data with nonzero sample-time), the delay must
be expressed in the number of lags. These delays are separate from the “in-model”
delays specified by the nk order in the Orders edit box.
7 In the Name field, edit the name of the model or keep the default.
8 In the Focus list, select how to weigh the relative importance of the fit at different
frequencies. For more information about each option, see “Assigning Estimation
Weightings” on page 3-65.
3-56
Prerequisites
9 In the Initial state list, specify how you want the algorithm to treat initial
conditions. For more information about the available options, see “Specifying Initial
Conditions for Iterative Estimation Algorithms” on page 3-38.
Tip If you get an inaccurate fit, try setting a specific method for handling initial
states rather than choosing it automatically.
10 In the Covariance list, select Estimate if you want the algorithm to compute
parameter uncertainties. Effects of such uncertainties are displayed on plots as
model confidence regions.
Next Steps
• Validate the model by selecting the appropriate check box in the Model Views area
of the System Identification app. For more information about validating models, see
“Validating Models After Estimation” on page 10-2.
• Export the model to the MATLAB workspace for further analysis by dragging it to the
To Workspace rectangle in the System Identification app.
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 5-28,
and “Using Linear Model for Hammerstein-Wiener Estimation” on page 5-64.
3-57
3 Linear Model Identification
Prerequisites
Before you can perform this task, you must have
You can estimate single-output and multiple-output ARX models using the arx and iv4
commands. For information about the algorithms, see “Polynomial Model Estimation
Algorithms” on page 3-66.
You can use the following general syntax to both configure and estimate ARX models:
3-58
Prerequisites
data is the estimation data and [na nb nk] specifies the model orders, as discussed in
“What Are Polynomial Models?” on page 3-40.
The third input argument opt contains the options for configuring the estimation of the
ARX model, such as handling of initial conditions and input offsets. You can create and
configure the option set opt using the arxOptions and iv4Options commands. The
three input arguments can also be followed by name and value pairs to specify optional
model structure attributes such as InputDelay, ioDelay, and IntegrateNoise.
For more information about validating you model, see “Validating Models After
Estimation” on page 10-2.
You can use pem or polyest to refine parameter estimates of an existing polynomial
model, as described in “Refining Linear Parametric Models” on page 3-86.
For detailed information about these commands, see the corresponding reference page.
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 5-28.
You can estimate any polynomial model using the iterative prediction-error estimation
method polyest. For Gaussian disturbances of unknown variance, this method gives the
maximum likelihood estimate. The resulting models are stored as idpoly model objects.
Use the following general syntax to both configure and estimate polynomial models:
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.For more information about
model orders, see “What Are Polynomial Models?” on page 3-40.
3-59
3 Linear Model Identification
Tip You do not need to construct the model object using idpoly before estimation.
If you want to estimate the coefficients of all five polynomials, A, B, C, D, and F, you
must specify an integer order for each polynomial. However, if you want to specify an
ARMAX model for example, which includes only the A, B, and C polynomials, you must
set nd and nf to zero matrices of the appropriate size. For some simpler configurations,
there are dedicated estimation commands such as arx, armax, bj, and oe, which deliver
the required model by using just the required orders. For example, oe(data, [nb nf
nk],opt) estimates an output-error structure polynomial model.
Note: To get faster estimation of ARX models, use arx or iv4 instead of polyest.
In addition to the polynomial models listed in “What Are Polynomial Models?” on page
3-40, you can use polyest to model the ARARX structure—called the generalized
least-squares model—by setting nc=nf=0. You can also model the ARARMAX structure—
called the extended matrix model—by setting nf=0.
The third input argument, opt, contains the options for configuring the estimation of
the polynomial model, such as handling of initial conditions, input offsets and search
algorithm. You can create and configure the option set opt using the polyestOptions
command. The three input arguments can also be followed by name and value pairs
to specify optional model structure attributes such as InputDelay, ioDelay, and
IntegrateNoise.
For ARMAX, Box-Jenkins, and Output-Error models—which can only be estimated using
the iterative prediction-error method—use the armax, bj, and oe estimation commands,
respectively. These commands are versions of polyest with simplified syntax for these
specific model structures, as follows:
m = armax(Data,[na nb nc nk])
m = oe(Data,[nb nf nk])
m = bj(Data,[nb nc nd nf nk])
Similar to polyest, you can specify as input arguments the option set configured using
commands armaxOptions, oeOptions, and bjOptions for the estimators armax, oe,
and bj respectively. You can also use name and value pairs to configure additional model
structure attributes.
3-60
Prerequisites
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 “Validating Models After
Estimation” on page 10-2.
You can use pem or polyest to refine parameter estimates of an existing polynomial
model (of any configuration), as described in “Refining Linear Parametric Models” on
page 3-86.
3-61
3 Linear Model Identification
nb: Ny-
by-Nu
matrix
such
nb(i,j)
=
length(B{i,j})-
nk(i,j).
C,D Ny-by-1 array of row vectors C{i} and D{i} contain coefficients nc and
of relations between output yi and nd are
noise ei Ny-by-1
matrices
such that
each entry
contains
the degree
of the
corresponding
C and D
polynomial,
respectively.
3-62
Prerequisites
For example, consider the ARMAX set of equations for a 2 output, 1 input model:
y1 (t) + 0.5 y1 (t-1) + 0.9 y 2 (t-1) + 0.1 y 2 (t-2) = u(t) + 5 u(t-1) + 2 u(t-2) + e1 (t) + 0.01 e1 (t-1)
y2 (t) + 0.05 y 2 (t-1) + 0.3 y 2 (t-2) = 10 u(t-2) + e2 (t) + 0.1 e2 (t-1) + 0.02 e2 (t-2)
y1 andy2 represent the two outputs and u represents the input variable. e1 and e2
represent the white noise disturbances on the outputs, y1 and y2, respectively. To
represent these equations as an ARMAX form polynomial using idpoly, configure the A,
B, and C polynomials as follows:
A = cell(2,2);
A{1,1} = [1 0.5];
A{1,2} = [0 0.9 0.1];
A{2,1} = [0];
A{2,2} = [1 0.05 0.3];
B = cell(2,1);
B{1,1} = [1 5 2];
B{2,1} = [0 0 10];
C = cell(2,1);
C{1} = [1 0.01];
C{2} = [1 0.1 0.02];
model = idpoly(A,B,C)
3-63
3 Linear Model Identification
model =
Discrete-time ARMAX model:
Model for output number 1: A(z)y_1(t) = - A_i(z)y_i(t) + B(z)u(t) + C(z)e_1(t)
A(z) = 1 + 0.5 z^-1
B(z) = 10 z^-2
Parameterization:
Polynomial orders: na=[1 2;0 2] nb=[3;1] nc=[1;2]
nk=[0;2]
Number of free coefficients: 12
Use "polydata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Created by direct construction or transformation. Not estimated.
In the System Identification app. 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.
Tip To simplify entering large matrices orders in the System Identification app, define
the variable NN=[NA NB NK] at the command line. You can specify this variable in the
Orders field.
3-64
Prerequisites
In the System Identification app. 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 10-88.
• 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-128 or
“Defining a Custom Filter” on page 2-129. This prefiltering applies only for estimating
the dynamics from input to output. The disturbance model is determined from the
unfiltered estimation data.
At the command line. Specify the focus as an estimation option (created using
polyestOptions, oeOptions etc.) using the same options as in the app. For example,
use this command to estimate an ARX model and emphasize the frequency content
related to the input spectrum only:
opt = arxOptions('Focus', 'simulation');
m = arx(data,[2 2 3],opt)
This Focus setting might produce more accurate simulation results, provided the orders
picked are optimal for the given data..
3-65
3 Linear Model Identification
In the System Identification app. For ARMAX, OE, and BJ models, set Initial state
to one of the following options:
At the command line. Specify the initial conditions as an estimation option. Use
polyestOptions to configure options for the polyest command, armaxOptions for
the armax command etc. Set the InitialCondition option to the desired value in the
option set. For example, use this command to estimate an ARMAX model and set the
initial states to zero:
opt = armaxOptions('InitialCondition','zero')
m = armax(data,[2 2 2 3],opt)
For a complete list of values for the InitialCondition estimation option, see the
armaxOptions reference page.
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.
3-66
Prerequisites
Note: AR models apply to time-series data, which has no input. For more information,
see “Time-Series Model Identification”. For more information about working with AR and
ARX models, see “Identifying Input-Output Polynomial Models” on page 3-40.
Load a sample data set z8 with three inputs and one output, measured at 1 -second
intervals and containing 500 data samples.
load iddata8
Use armax to both construct the idpoly model object, and estimate the parameters:
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.
opt = armaxOptions;
opt.Focus = 'simulation';
opt.SearchOption.MaxIter = 50;
opt.SearchOption.Tolerance = 1e-5;
na = 4;
nb = [3 2 3];
nc = 4;
nk = [0 0 0];
m_armax = armax(z8, [na nb nc nk], opt);
Focus, Tolerance, and MaxIter are estimation options that configure the estimation
objective function and the attributes of the search algorithm. The Focus option specifies
whether the model is optimized for simulation or prediction applications. The Tolerance
3-67
3 Linear Model Identification
and MaxIter search options specify when to stop estimation. For more information about
these properties, see the armaxOptions reference page.
armax is a version of polyest with simplified syntax for the ARMAX model structure.
The armax method both constructs the idpoly model object and estimates its
parameters.
m_armax =
Discrete-time ARMAX model: A(z)y(t) = B(z)u(t) + C(z)e(t)
A(z) = 1 - 1.284 z^-1 + 0.3048 z^-2 + 0.2648 z^-3 - 0.05708 z^-4
Parameterization:
Polynomial orders: na=4 nb=[3 2 3] nc=4 nk=[0 0 0]
Number of free coefficients: 16
Use "polydata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using ARMAX on time domain data "z8".
Fit to estimation data: 80.86% (simulation focus)
FPE: 1.056, MSE: 0.9868
3-68
Prerequisites
The Report model property contains detailed information on the estimation results. To
view the properties and values inside Report, use dot notation. For example:
m_armax.Report
This action displays the contents of estimation report such as model quality measures
(Fit), search termination criterion (Termination), and a record of estimation data
(DataUsed) and options (OptionsUsed).
3-69
3 Linear Model Identification
Transfer function models describe the relationship between the inputs and outputs
of a system using a ratio of polynomials. The model order is equal to the order of the
denominator polynomial. The roots of the denominator polynomial are referred to as the
model poles. The roots of the numerator polynomial are referred to as the model zeros.
The parameters of a transfer function model are its poles, zeros and transport delays.
Continuous-Time Representation
num( s)
Y ( s) = U ( s) + E( s)
den(s)
3-70
Identifying Transfer Function Models
Where, Y(s), U(s) and E(s) represent the Laplace transforms of the output, input and
noise, respectively. num(s) and den(s) represent the numerator and denominator
polynomials that define the relationship between the input and the output.
Discrete-Time Representation
num( q -1 )
y( t) = u(t) + e(t)
den(q -1 )
num( q -1) = b0 + b1 q -1 + b2 q-2 + º
den(q -1 ) = 1 + a1q -1 + a2 q -2 + º
The roots of num(q^-1) and den(q^-1) are expressed in terms of the lag variable q^-1.
Delays
num( s) - st
Y ( s) = e U ( s) + E( s)
den(s)
In discrete-time:
num
y( t) = u(t - t ) + e( t)
den
where num and den are polynomials in the lag operator q^(-1).
Note that you cannot use time-series data for transfer function model identification.
3-71
3 Linear Model Identification
You must first import your data into the MATLAB workspace, as described in “Data
Preparation”.
Prerequisites
• Import data into the System Identification app. See “Represent Data”. For supported
data formats, see “Data Supported by Transfer Function Models” on page 3-71.
• Perform any required data preprocessing operations. If input and/or output signals
contain nonzero offsets, consider detrending your data. See “Ways to Prepare Data for
System Identification” on page 2-6.
1 In the System Identification app, select Estimate > Transfer Function Models
3-72
Multi-Input, Multi-Output Models
Tip For more information on the options in the dialog box, click Help.
2 In the Number of poles and Number of zeros fields, specify the number of poles
and zeros of the transfer function as nonnegative integers.
• To use the same number of poles or zeros for all the input/output pairs, specify a
scalar.
• To use a different number of poles and zeros for the input/output pairs, specify an
ny-by-nu matrix. ny is the number of outputs and nu is the number of inputs.
Alternatively, click .
The Model Orders dialog box opens where you specify the number of poles and
zeros for each input/output pair. Use the Output list to select an output.
3-73
3 Linear Model Identification
For discrete-time models, the number of poles and zeros refers to the roots of the
numerator and denominator polynomials expressed in terms of the lag variable
q^-1.
4 (For discrete-time models only) Specify whether to estimate the model feedthrough.
Select the Feedthrough check box.
A discrete-time model with 2 poles and 3 zeros takes the following form:
When the model has direct feedthrough, b0 is a free parameter whose value is
estimated along with the rest of the model parameters b1, b2, b3, a1, a2. When the
model has no feedthrough, b0 is fixed to zero.
3-74
Multi-Input, Multi-Output Models
The Model Orders dialog box opens, where you specify to estimate the feedthrough
for each input/output pair separately. Use the Output list to select an output.
5 Expand the I/O Delay section to specify nominal values and constraints for
transport delays for different input/output pairs.
Use the Output list to select an output. Select the Fixed check box to specify a
transport delay as a fixed value. Specify its nominal value in the Delay field.
6 Expand the Estimation Options section to specify estimation options.
3-75
3 Linear Model Identification
• Set the range slider to the desired passband to specify the frequency range
over which the transfer function model must fit the data. By default the entire
frequency range (0 to Nyquist frequency) is covered.
• Select Display progress to view the progress of the optimization.
• Select Estimate covariance to estimate the covariance of the transfer function
parameters.
• (For frequency-domain data only) Specify whether to allow the estimation process
to use parameter values that may lead to unstable models. Select the Allow
unstable models option.
3-76
Iteration Options
Iteration Options
In the Options for Iterative Minimization dialog box, you can specify the following
iteration options:
3-77
3 Linear Model Identification
Next Steps
• Validate the model by selecting the appropriate check box in the Model Views area
of the System Identification app. For more information about validating models, see
“Validating Models After Estimation” on page 10-2.
• Export the model to the MATLAB workspace for further analysis. Drag the model to
the To Workspace rectangle in the System Identification app.
3-78
Next Steps
Alternatively, you can specify the input/output offset for the data using an estimation
option set. Use tfestOptions to create the estimation option set. Use the
InputOffset and OutputOffset name and value pairs to specify the input/output
offset.
Estimate continuous-time and discrete-time transfer function models using tfest. The
output of tfest is an idtf object, which represents the identified transfer function.
1 Create a data object (iddata or idfrd) that captures the experimental data.
2 (Optional) Specify estimation options using tfestOptions.
3 (Optional) Create a transfer function model that specifies the expected model
structure and any constraints on the estimation parameters.
4 Use tfest to identify the transfer function model, based on the data.
5 Validate the model. See “Model Validation”.
For example, specify a third-order transfer function model that contains an integrator
and has a transport delay of at most 1.5 seconds:
int_sys is an idtf model with three poles and one zero. The denominator coefficient for
the s^0 term is zero and implies that one of the poles is an integrator.
3-79
3 Linear Model Identification
Load time-domain system response data and use it to estimate a transfer function for the
system.
To see the numerator and denominator coefficients of the resulting estimated model sys,
enter:
sys.num
sys.den
To view the uncertainty in the estimates of the numerator and denominator and other
information, use tfdata.
For this example, use bode to obtain the magnitude and phase response data for the
following system:
3-80
Next Steps
s + 0 .2
H ( s) = e-.5s
s + 2s2 + s + 1
3
Use 100 frequency points, ranging from 0.1 rad/s to 10 rad/s, to obtain the frequency
response data. Use frd to create a frequency response data object.
freq = logspace(-1,1,100);
[mag, phase] = bode(tf([1 .2],[1 2 1 1],'InputDelay',.5),freq);
data = frd(mag.*exp(1j*phase*pi/180),freq);
data is an iddata object that contains frequency response data for the described system.
Estimate a transfer function using data. Specify an unknown transport delay for the
identified transfer function.
np = 3;
nz = 1;
iodelay = NaN;
sys = tfest(data,np,nz,iodelay)
np and nz specify the number of poles and zeros in the identified transfer function,
respectively.
iodelay specifies an unknown transport delay for the identified transfer function.
cumsum integrates the output data of z1. The estimated transfer function should
therefore contain an integrator.
3-81
3 Linear Model Identification
int_sys is an idtf model with three poles and one zero. The denominator coefficient for
the s^0 term is zero. Therefore, int_sys contains an integrator.
The constraints specify that the numerator and denominator coefficients are
nonnegative. Additionally, the last element of the denominator coefficients (associated
with the s^0 term) is not an estimable parameter. This constraint forces one of the
estimated poles to be at s = 0.
Create an estimation option set that specifies using the Levenberg–Marquardt search
method.
opt = tfestOptions('SearchMethod', 'lm');
Estimate a transfer function for z1 using init_sys and the estimation option set.
sys = tfest(z1,init_sys,opt);
tfest uses the coefficients of init_sys to initialize the estimation of sys. Additionally,
the estimation is constrained by the constraints you specify in the Structure property
of init_sys. The resulting idtf model sys contains the parameter values that result
from the estimation.
Create a transfer function model with the expected numerator and denominator
structure and delay constraints.
For this example, the experiment data consists of two inputs and one output. Both
transport delays are unknown and have an identical upper bound. Additionally, the
transfer functions from both inputs to the output are identical in structure.
3-82
Next Steps
init_sys is an idtf model describing the structure of the transfer function from
one input to the output. The transfer function consists of one zero, three poles and a
transport delay. The use of NaN indicates unknown coefficients.
load co2data;
Ts = 0.5;
data = iddata(Output_exp1,Input_exp1,Ts);
T = getTrend(data);
T.InputOffset = [170, 50];
T.OutputOffset = mean(data.y(1:75));
data = detrend(data, T);
Identify a transfer function for the measured data using the specified delay constraints.
sys = tfest(data,init_sys);
The tfest command supports estimation of IO delays. In the simplest case, if you
specify NaN as the value for the ioDelay input argument, tfest estimates the
corresponding delay value.
3-83
3 Linear Model Identification
load iddata1 z1
sys = tfest(z1, 2, 2, NaN); % 2 poles, 2 zeros, unknown transport delay
If you want to assign an initial guess to the value of delay or prescribe bounds for its
value, you must first create a template idtf model and configure ioDelay using the
model's Structure property:
sys0 = idtf([nan nan nan],[1 nan nan]);
sys0.Structure.ioDelay.Value = 0.1; % initial guess
sys0.Structure.ioDelay.Maximum = 1; % maximum allowable value for delay
sys0.Structure.ioDelay.Free = true; % treat delay as estimatable quantity
sys = tfest(z1, sys0);
If estimation data is in the time-domain, the delays are not estimated iteratively. If a
finite initial value is specified, that value is retained as is with no iterative updates. The
same is true of discrete-time frequency domain data. Thus in the example above, if data
has a nonzero sample time, the estimated value of delay in the returned model sys is 0.1
(same as the initial guess specified for sys0 ). The delays are updated iteratively only
for continuos-time frequency domain data. If, on the other hand, a finite initial value for
delay is not specified (e.g., sys0.Structure.ioDelay.Value = NaN ), then a value for
delay is determined using the delayest function, regardless of the nature of the data.
In the System Identification app, set Initial condition to one of the following options:
3-84
Next Steps
At the command line. Specify the initial conditions by using an estimation option set.
Use tfestOptions to create the estimation option set. For example, create an options
set that sets the initial conditions to zero:
opt = tfestOptions('InitialCondition','zero);
3-85
3 Linear Model Identification
In the first situation, you have already estimated a parametric model and wish to update
the values of its free parameters to improve the fit to the estimation data. This is useful
if your previous estimation terminated because of search algorithm constraints such as
maximum number of iterations or function evaluations allowed reached. 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-22.
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-86
Refining Linear Parametric Models
or imported the model from the MATLAB workspace. For information about importing
models into the app, see “Importing Models into the App” on page 14-7.
1 In the System Identification app, 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 “Specify Estimation and Validation Data in the App”
on page 2-30.
2 Select Estimate > Refine Existing Models to open the Linear Model Refinement
dialog box.
For more information on the options in the dialog box, click Help.
3 Select the model you want to refine in the Initial Model drop-down list or type
the model name.
3-87
3 Linear Model Identification
The model name must be in the Model Board of the System Identification app or a
variable in the MATLAB workspace. The model can be a state-space, polynomial,
process, transfer function or linear grey-box model. The input-output dimensions of
the model must match that of the working data.
4 (Optional) Modify the Estimation Options.
When you enter the model name, the estimation options in the Linear Model
Refinement dialog box override the initial model settings.
5 Click Regularization to obtain regularized estimates of model parameters. Specify
the regularization constants in the Regularization Options dialog box. To learn more,
see “Regularized Estimates of Model Parameters”.
6 Click Estimate to refine the model.
7 Validate the new model. See “Ways to Validate Models” on page 10-2.
You can also specify the estimation options configuring the objective function and search
algorithm settings. For more information, see the reference page of the estimating
function.
3-88
Refine ARMAX Model with Initial Parameter Guesses at Command Line
Estimate an ARMAX model for the data by initializing the A , B , and C polynomials.
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 armax , polyest , or pem ,
which refine the initial parameter guesses using the data.
load iddata8
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;
init_model = idpoly(A,B,C,'Ts',1);
model = polyest(z8,init_model);
compare(z8,init_model,model)
3-89
3 Linear Model Identification
Related Examples
• “Identifying Input-Output Polynomial Models” on page 3-40
3-90
Refine Initial ARMAX Model at Command Line
load iddata8;
Split the data into an initial estimation data set and a refinement data set.
init_data = z8(1:100);
refine_data = z8(101:end);
init_data is an iddata object containing the first 100 samples from z8 and
refine_data is an iddata object representing the remaining data in z8.
na=4;
nb=[3 2 3];
nc=2;
nk=[0 0 0];
Refine the estimated model by specifying the estimation algorithm options. Specify
stricter tolerance and increase the maximum iterations.
opt = armaxOptions;
opt.SearchOption.Tolerance = 1e-5;
opt.SearchOption.MaxIter = 50;
refine_sys = pem(refine_data,sys,opt);
compare(refine_data,sys,refine_sys);
3-91
3 Linear Model Identification
You can similarly use polyest or armax to refine the estimated model.
See Also
Functions
armax | pem | polyest
3-92
Extracting Numerical Model Data
For example, extract state-space matrices (A, B, C, D and K) for state-space models, or
polynomials (a, b, c, d and f) for polynomial models.
If you estimated model uncertainty data, this information is stored in the model in the
form of the parameter covariance matrix. You can fetch the covariance matrix (in its
raw or factored form) using the getcov command. The covariance matrix represents
uncertainties in parameter estimates and is used to compute:
• Confidence bounds on model output plots, Bode plots, residual plots, and pole-zero
plots
• Standard deviation in individual parameter values. For example, one standard
deviation in the estimated value of the A polynomial in an ARX model, returned by
the polydata command and displayed by the present command.
The following table summarizes the commands for extracting model coefficients and
uncertainty.
3-93
3 Linear Model Identification
You can also extract numerical model data by using 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').
3-94
Extracting Numerical Model Data
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, also called the measured model. 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 for each output in
your system.
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.
3-95
3 Linear Model Identification
You can use c2d and d2c to transform any linear identified model between continuous-
time and discrete-time representations. d2d is useful is you want to change the sampling
interval of a discrete-time model. All of these operations change the sampling interval,
which is called resampling the model.
These commands do not transform the estimated model uncertainty. If you want to
translate the estimated parameter covariance during the conversion, use translatecov.
Note: c2d and d2d correctly approximate the transformation of the noise model only
when the sampling interval T is small compared to the bandwidth of the noise.
3-96
Transforming Between Discrete-Time and Continuous-Time Representations
The following commands compare estimated model m and its continuous-time counterpart
mc on a Bode plot:
3-97
3 Linear Model Identification
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:
y( t) = H ( q) e(t)
Ee2 = l
2
F v (w) = lT H eiw T ( )
where l is the variance of the white noise e(t), and lT represents the spectral density of
e(t). Resampling the noise model preserves the spectral density l T . The spectral density
l T is invariant up to the Nyquist frequency. For more information about spectrum
normalization, see “Spectrum Normalization” on page 3-13.
3-98
Transforming Between Discrete-Time and Continuous-Time Representations
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 underlying continuous-time model being
subject to continuous-time white noise disturbances, which have infinite, instantaneous
variance. In this case, the underlying continuous-time model is the unique representation
for discrete-time models. To maintain the same level of noise after interpolating the noise
3-99
3 Linear Model Identification
In this section...
“Choosing a Conversion Method” on page 3-100
“Zero-Order Hold” on page 3-101
“First-Order Hold” on page 3-102
“Impulse-Invariant Mapping” on page 3-103
“Tustin Approximation” on page 3-104
“Zero-Pole Matching Equivalents” on page 3-108
3-100
Continuous-Discrete Conversion Methods
Zero-Order Hold
The Zero-Order Hold (ZOH) method provides an exact match between the continuous-
and discrete-time systems in the time domain for staircase inputs.
The ZOH block generates the continuous-time input signal u(t) by holding each sample
value u(k) constant over one sample period:
u ( t ) = u [ k] , kTs £ t £ ( k + 1 ) Ts
The signal u(t) is the input to the continuous system H(s). The output y[k] results from
sampling y(t) every Ts seconds.
Conversely, given a discrete system Hd(z), d2c produces a continuous system H(s). The
ZOH discretization of H(s) coincides with Hd(z).
3-101
3 Linear Model Identification
For systems with internal delays (delays in feedback loops), the ZOH method results in
approximate discretizations. The following figure illustrates a system with an internal
delay.
H(s)
e-ts
For such systems, c2d performs the following actions to compute an approximate ZOH
discretization:
H(z)
H(s) e-sr
z-k
First-Order Hold
The First-Order Hold (FOH) method provides an exact match between the continuous-
and discrete-time systems in the time domain for piecewise linear inputs.
FOH differs from ZOH by the underlying hold mechanism. To turn the input samples
u[k] into a continuous input u(t), FOH uses linear interpolation between samples:
3-102
Continuous-Discrete Conversion Methods
t - kTs
u ( t ) = u [ k] +
Ts
(u [k + 1] - u [k]) , kTs £ t £ (k + 1) Ts
This method is generally more accurate than ZOH for systems driven by smooth inputs.
This FOH method differs from standard causal FOH and is more appropriately called
triangle approximation (see [2], p. 228). The method is also known as ramp-invariant
approximation.
You can use the FOH method to discretize SISO or MIMO continuous-time models with
time delays. The FOH method handles time delays in the same way as the ZOH method.
See “ZOH Method for Systems with Time Delays” on page 3-101.
Impulse-Invariant Mapping
The impulse-invariant mapping produces a discrete-time model with the same impulse
response as the continuous time system. For example, compare the impulse response of a
first-order continuous system with the impulse-invariant discretization:
G = tf(1,[1,1]);
Gd1 = c2d(G,0.01,'impulse');
impulse(G,Gd1)
3-103
3 Linear Model Identification
The impulse response plot shows that the impulse responses of the continuous and
discretized systems match.
Tustin Approximation
The Tustin or bilinear approximation yields the best frequency-domain match between
the continuous-time and discretized systems. This method relates the s-domain and z-
domain transfer functions using the approximation:
3-104
Continuous-Discrete Conversion Methods
sTs 1 + sTs / 2
z=e ª .
1 - sTs / 2
In c2d conversions, the discretization Hd(z) of a continuous transfer function H(s) is:
2 z-1
H d ( z ) = H ( s¢ ) , s¢ =
Ts z + 1
1 + sTs / 2
H ( s ) = Hd ( z¢ ) , z¢ =
1 - sTs / 2
When you convert a state-space model using the Tustin method, the states are not
preserved. The state transformation depends upon the state-space matrices and whether
the system has time delays. For example, for an explicit (E = I) continuous-time model
with no time delays, the state vector w[k] of the discretized model is related to the
continuous-time state vector x(t) by:
Ê T ˆ T T
w [ kTs ] = Á I - A s ˜ x ( kTs ) - s Bu ( kTs ) = x ( kTs ) - s ( Ax ( kTs ) + Bu ( kTs ) ) .
Ë 2 ¯ 2 2
Ts is the sampling time of the discrete-time model. A and B are state-space matrices of
the continuous-time model.
If your system has important dynamics at a particular frequency that you want the
transformation to preserve, you can use the Tustin method with frequency prewarping.
This method ensures a match between the continuous- and discrete-time responses at the
prewarp frequency.
The Tustin approximation with frequency prewarping uses the following transformation
of variables:
w z-1
H d ( z ) = H ( s¢ ) , s¢ =
tan (w Ts / 2 ) z + 1
3-105
3 Linear Model Identification
This change of variable ensures the matching of the continuous- and discrete-
time frequency responses at the prewarp frequency ω, because of the following
correspondence:
(
H ( jw ) = H d e jw Ts )
Tustin Approximation for Systems with Time Delays
You can use the Tustin approximation to discretize SISO or MIMO continuous-time
models with time delays.
By default, the Tustin method rounds any time delay to the nearest multiple of the
sampling time. Therefore, for any time delay tau, the integer portion of the delay, k*Ts,
maps to a delay of k sampling periods in the discretized model. This approach ignores the
residual fractional delay, tau - k*Ts.
You can to approximate the fractional portion of the delay by a discrete all-pass filter
(Thiran filter) of specified order. To do so, use the FractDelayApproxOrder option of
c2dOptions.
To understand how the Tustin method handles systems with time delays, consider the
following SISO state-space model G(s). The model has input delay τi, output delay τo, and
internal delay τ.
G(s)
e-tis e-tos
H(s)
e-ts
The following figure shows the general result of discretizing G(s) using the Tustin
method.
3-106
Continuous-Discrete Conversion Methods
Gd(z)
z-m F(z)
By default, c2d converts the time delays to pure integer time delays. The c2d command
computes the integer delays by rounding each time delay to the nearest multiple of
the sample time Ts. Thus, in the default case, mi = round(τi /Ts), mo = round(τo/Ts), and
m = round(τ/Ts).. Also in this case, Fi(z) = Fo(z) = F(z) = 1.
The Thiran filters add additional states to the model. The maximum number of
additional states for each delay is FractDelayApproxOrder.
For example, for the input delay τi, the order of the Thiran filter Fi(z) is:
order(Fi(z)) = max(ceil(τi /Ts), FractDelayApproxOrder).
If ceil(τi /Ts) < FractDelayApproxOrder, the Thiran filter Fi(z) approximates the
entire input delay τi. If ceil(τi/Ts) > FractDelayApproxOrder, the Thiran filter only
approximates a portion of the input delay. In that case, c2d represents the remainder of
the input delay as a chain of unit delays z–mi, where
mi = ceil(τi /Ts) – FractDelayApproxOrder.
When you discretizetf and zpk models using the Tustin method, c2d first aggregates all
input, output, and transfer delays into a single transfer delay τTOT for each channel. c2d
then approximates τTOT as a Thiran filter and a chain of unit delays in the same way as
described for each of the time delays in ss models.
3-107
3 Linear Model Identification
For more information about Thiran filters, see the thiran reference page and [4].
zi = esi Ts
where:
You can use zero-pole matching to discretize SISO continuous-time models with time
delay, except that the method does not support ss models with internal delays. The zero-
pole matching method handles time delays in the same way as the Tustin approximation.
See “Tustin Approximation for Systems with Time Delays” on page 3-106.
References
[1] Åström, K.J. and B. Wittenmark, Computer-Controlled Systems: Theory and Design,
Prentice-Hall, 1990, pp. 48-52.
[2] Franklin, G.F., Powell, D.J., and Workman, M.L., Digital Control of Dynamic Systems
(3rd Edition), Prentice Hall, 1997.
[3] Smith, J.O. III, “Impulse Invariant Method”, Physical Audio Signal
Processing, August 2007. http://www.dsprelated.com/dspbooks/pasp/
Impulse_Invariant_Method.html.
[4] T. Laakso, V. Valimaki, “Splitting the Unit Delay”, IEEE Signal Processing Magazine,
Vol. 13, No. 1, p.30-60, 1996.
3-108
Continuous-Discrete Conversion Methods
See Also
c2d | c2dOptions | d2c | d2cOptions | d2d | thiran
3-109
3 Linear Model Identification
The iddata and idfrd objects have an InterSample property which stores how the
input behaves between the sampling instants. You can specify the behavior between the
samples to be piecewise constant (zero-order hold), linearly interpolated between the
samples (first-order hold) or band-limited. A band-limited intersample behavior of the
input signal means:
• A filtered input signal (an input of finite bandwidth) was used to excite the system
dynamics
• The input was measured using a sampling device (A/D converter with antialiasing)
that reported it to be band-limited even though the true input entering the system
was piecewise constant or linear. In this case, the sampling devices can be assumed to
be a part of the system being modeled.
• Time-domain data is converted into frequency domain data using fft and the sample
time of the data is set to zero.
• Discrete-time frequency domain data (iddata with domain = 'frequency' or
idfrd with sample time Ts≠0) is treated as continuous-time data by setting the
sample time Ts to zero.
The resulting continuous-time frequency domain data is used for model estimation. For
more information, see Pintelon, R. and J. Schoukens, System Identification. A Frequency
Domain Approach, section 10.2, pp-352-356,Wiley-IEEE Press, New York, 2001.
Similarly, the intersample behavior of the input data affects the results of simulation
and prediction of continuous-time models. sim and predict commands use the
InterSample property to choose the right algorithm for computing model response.
The following example simulates a system using first-order hold ( foh ) intersample
behavior for input signal.
sys = idtf([-1 -2],[1 2 1 0.5]);
3-110
Effect of Input Intersample Behavior on Continuous-Time Models
rng('default')
u = idinput([100 1 5],'sine',[],[],[5 10 1]);
Ts = 2;
y = lsim(sys, u, (0:Ts:999)', 'foh');
data = iddata(y,u,Ts);
data.InterSample
ans =
zoh
np = 3; % number of poles
nz = 1; % number of zeros
opt = tfestOptions('InitMethod','all','Display','on');
opt.SearchOption.MaxIter = 100;
modelZOH = tfest(data,np,nz,opt)
modelZOH =
Parameterization:
Number of poles: 3 Number of zeros: 1
Number of free coefficients: 5
Use "tfdata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using TFEST on time domain data "data".
3-111
3 Linear Model Identification
The model gives about 80% fit to data. The sample time of the data is large enough that
intersample inaccuracy (using zoh rather than foh ) leads to significant modeling errors.
data.InterSample = 'foh';
modelFOH = tfest(data, np, nz,opt)
modelFOH =
Parameterization:
Number of poles: 3 Number of zeros: 1
Number of free coefficients: 5
Use "tfdata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using TFEST on time domain data "data".
Fit to estimation data: 97.7% (simulation focus)
FPE: 0.001747, MSE: 0.001693
3-112
Effect of Input Intersample Behavior on Continuous-Time Models
modelZOH is compared to data whose intersample behavior is foh. Therefore, its fit
decreases to around 70%.
3-113
3 Linear Model Identification
If you used the System Identification app 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.
3-114
Transforming Between Linear Model Representations
Note: Most transformations among identified models (among idss, idtf, idpoly)
causes the parameter covariance information to be lost, with few exceptions:
If you want to translate the estimated parameter covariance during conversion, use
translatecov.
3-115
3 Linear Model Identification
Subreferencing Models
In this section...
“What Is Subreferencing?” on page 3-116
“Limitation on Supported Models” on page 3-116
“Subreferencing Specific Measured Channels” on page 3-116
“Separation of Measured and Noise Components of Models” on page 3-117
“Treating Noise Channels as Measured Inputs” on page 3-118
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.
The toolbox supports subreferencing operations for idtf, idpoly, idproc, idss, and
idfrd model objects.
Subreferencing is not supported for idgrey models. If you want to analyze the sub-
model, convert it into an idss model first, and then subreference the I/Os of the idss
model. If you want a grey-box representation of a subset of I/Os, create a new idgrey
model that uses an ODE function returning the desired I/O dynamics.
In addition to subreferencing the model for specific combinations of measured inputs and
output, you can subreference dynamic and noise models individually.
model(outputs,inputs)
3-116
Subreferencing Models
In this syntax, outputs and inputs specify channel indexes or channel names.
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.
H is an operator that describes the properties of the additive output disturbance and
takes the hypothetical (unmeasured) noise source inputs to the outputs. H represents the
noise model. When you specify to estimate a noise model, the resulting model include one
noise channel e at the input for each output in your system.
Thus, linear, parametric models represent input-output relationships for two kinds of
input channels: measured inputs and (unmeasured) noise inputs. For example, consider
the ARX model given by one of the following equations:
3-117
3 Linear Model Identification
A( q) y( t) = B(q) u ( t - nk ) + e( t)
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 input u and
output y, G = B( q) A ( q) . The noise model is the contribution of the input noise e to the
output y, given by H = 1 A ( q) .
Suppose that the model m contains both a dynamic model G and a noise model H.
To create a new model that only has G and no noise contribution, simply set its
NoiseVariance property value to zero value.
To create a new model by subreferencing H due to unmeasured inputs, use the following
syntax:
m_H = m(:,[])
This operation creates a time-series model from m by ignoring the measured input.
The covariance matrix of e is given by the model property NoiseVariance, which is the
matrix L :
L = LLT
e = Lv
where v is white noise with an identity covariance matrix representing independent noise
sources with unit variances.
3-118
Subreferencing Models
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.
Converting noise channels to measured inputs loses information about the variance of
the innovations e. For example, step response due to the noise channels does not take
into consideration the magnitude of the noise contributions. To include this variance
information, normalize e such that v becomes white noise with an identity covariance
matrix, where
e = Lv
This command creates a model where u and v are treated as measured signals, as
follows:
È 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'.
If you want to create a model that has only the noise channels of an identified model as
its measured inputs, use the noise2meas command. It results in a model with y(t) = He
or y(t) = HLv, where e or v is treated as a measured input.
Note: When you plot models in the app 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 14-14.
3-119
3 Linear Model Identification
Concatenating Models
In this section...
“About Concatenating Models” on page 3-120
“Limitation on Supported Models” on page 3-120
“Horizontal Concatenation of Model Objects” on page 3-121
“Vertical Concatenation of Model Objects” on page 3-121
“Concatenating Noise Spectrum Data of idfrd Objects” on page 3-122
“See Also” on page 3-123
When you concatenate identified models, such as idtf, idpoly, idproc, and idss
model objects, the resulting model combines the parameters of the individual models.
However, the estimated parameter covariance is lost. If you want to translate the
covariance information during concatenation, use translatecov.
Concatenation is not supported for idgrey models; convert them to idss models first if
you want to perform concatenation.
You can also concatenate nonparametric models, which contain the estimated impulse-
response (idtf object) and frequency-response (idfrd object) of a system.
3-120
Concatenating Models
The following syntax creates a new model object m that contains the horizontal
concatenation of m1,m2,...,mN:
m = [m1,m2,...,mN]
m takes all of the inputs of m1,m2,...,mN to the same outputs as in the original models.
The following diagram is a graphical representation of horizontal concatenation of the
models.
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
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.
3-121
3 Linear Model Identification
u1 y1 u1
Model 1 Model 2 y3
u2 y2 u2
y1
Same u1 Vertical Concatenation Combined
y2
Inputs u2 of Model 1 and Model 2 Outputs
y3
When the SpectrumData property of individual idfrd objects is not empty, horizontal
and vertical concatenation handle SpectrumData, as follows.
Ê m1.s
Á 0 ˆ˜
m.s = Á O ˜
ÁÁ ˜
Ë 0 mN .s ˜¯
3-122
Concatenating Models
See Also
If you have the Control System Toolbox product, see “Combining Model Objects” on page
12-5 about additional functionality for combining models.
3-123
3 Linear Model Identification
Merging Models
You can merge models of the same structure to obtain a single model with parameters
that are statistically weighed means of the parameters of the individual models. When
computing the merged model, the covariance matrices of the individual models determine
the weights of the parameters.
You can perform the merge operation for the idtf, 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 “Create
Multiexperiment Data at the Command Line” on page 2-60.
For more information about merging models, see the merge reference page.
3-124
Building and Estimating Process Models Using System Identification Toolbox™
Introduction
This example illustrates how to build simple process models often used in process
industry. Simple, low-order continuous-time transfer functions are usually employed to
describe process behavior. Such models are described by IDPROC objects which represent
the transfer function in a pole-zero-gain form.
Process models are of the basic type 'Static Gain + Time Constant + Time Delay'. They
may be represented as:
or as an integrating process:
where the user can determine the number of real poles (0, 1, 2 or 3), as well as the
presence of a zero in the numerator, the presence of an integrator term (1/s) and the
presence of a time delay (Td). In addition, an underdamped (complex) pair of poles may
replace the real poles.
IDPROC objects define process models by using the letters P (for process model), D (for
time delay), Z (for a zero) and I (for integrator). An integer will denote the number of
poles. The models are generated by calling idproc with a string identifier using these
letters.
3-125
3 Linear Model Identification
idproc('P1') % transfer function with only one pole (no zeros or delay)
idproc('P2DIZ') % model with 2 poles, delay integrator and delay
idproc('P0ID') % model with no poles, but an integrator and a delay
ans =
Process model with transfer function:
Kp
G(s) = ----------
1+Tp1*s
Kp = NaN
Tp1 = NaN
Parameterization:
'P1'
Number of free coefficients: 2
Use "getpvec", "getcov" for parameters and their uncertainties.
Status:
Created by direct construction or transformation. Not estimated.
ans =
Process model with transfer function:
1+Tz*s
G(s) = Kp * ------------------- * exp(-Td*s)
s(1+Tp1*s)(1+Tp2*s)
Kp = NaN
Tp1 = NaN
Tp2 = NaN
Td = NaN
Tz = NaN
Parameterization:
'P2DIZ'
Number of free coefficients: 5
Use "getpvec", "getcov" for parameters and their uncertainties.
Status:
Created by direct construction or transformation. Not estimated.
ans =
Process model with transfer function:
Kp
3-126
Building and Estimating Process Models Using System Identification Toolbox™
Kp = NaN
Td = NaN
Parameterization:
'P0DI'
Number of free coefficients: 2
Use "getpvec", "getcov" for parameters and their uncertainties.
Status:
Created by direct construction or transformation. Not estimated.
open_system('iddempr1')
set_param('iddempr1/Random Number','seed','0')
The red part is the system, the blue part is the controller and the reference signal is a
swept sinusoid (a chirp signal). The data sampling time is set to 0.5 seconds. As observed,
the system is a continuous-time transfer function, and can hence be described using
model objects in System Identification Toolbox, such as idss, idpoly or idproc.
Let us describe the system using idpoly and idproc objects. Using idpoly object, the
system may be described as:
m0 = idpoly(1,0.1,1,1,[1 0.5],'Ts',0,'InputDelay',1.57,'NoiseVariance',0.01);
3-127
3 Linear Model Identification
The IDPOLY form used above is useful for describing transfer functions of arbitrary
orders. Since the system we are considering here is quite simple (one pole and no zeros),
and is continuous-time, we may use the simpler IDPROC object to capture its dynamics:
m0p =
Process model with transfer function:
Kp
G(s) = ---------- * exp(-Td*s)
1+Tp1*s
Kp = 0.2
Tp1 = 2
Td = 1.57
Parameterization:
'P1D'
Number of free coefficients: 3
Use "getpvec", "getcov" for parameters and their uncertainties.
Status:
Created by direct construction or transformation. Not estimated.
Once a system is described by a model object, such as IDPROC, it may be used for
estimation of its parameters using measurement data. As an example, we consider the
problem of estimation of parameters of the Simulink model's system (red portion) using
simulation data. We begin by acquiring data for estimation:
sim('iddempr1')
dat1e = iddata(y,u,0.5); % The IDDATA object for storing measurement data
plot(dat1e)
3-128
Building and Estimating Process Models Using System Identification Toolbox™
We can identify a process model using procest command, by providing the same
structure information specified to create IDPROC models. For example, the 1-pole+delay
model may be estimated by calling procest as follows:
m1 = procest(dat1e,'p1d'); % estimation of idproc model using data 'dat1e'.
m1 =
Process model with transfer function:
Kp
G(s) = ---------- * exp(-Td*s)
1+Tp1*s
3-129
3 Linear Model Identification
Kp = 0.20045
Tp1 = 2.0431
Td = 1.499
Parameterization:
'P1D'
Number of free coefficients: 3
Use "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using PROCEST on time domain data "dat1e".
Fit to estimation data: 87.34%
FPE: 0.01068, MSE: 0.01062
present(m1)
m1 =
Process model with transfer function:
Kp
G(s) = ---------- * exp(-Td*s)
1+Tp1*s
Parameterization:
'P1D'
Number of free coefficients: 3
Use "getpvec", "getcov" for parameters and their uncertainties.
Status:
Termination condition: Near (local) minimum, (norm(g) < tol).
Number of iterations: 4, Number of function evaluations: 9
3-130
Building and Estimating Process Models Using System Identification Toolbox™
The model parameters, K, Tp1 and Td are now shown with one standard deviation
uncertainty range.
The model m1 estimated above is an IDPROC model object to which all of the toolbox's
model commands can be applied:
3-131
3 Linear Model Identification
h = bodeplot(m1,m0);
showConfidence(h,3)
Similarly, the measurement data may be compared to the models outputs using compare
as follows:
compare(dat1e,m0,m1)
3-132
Building and Estimating Process Models Using System Identification Toolbox™
Other operations such as sim, impulse, c2d are also available, just as they are for other
model objects.
bdclose('iddempr1')
It may be important (at least for slow sampling) to consider the intersample behavior of
the input data. To illustrate this, let us study the same system as before, but without the
sample-and-hold circuit:
open_system('iddempr5')
3-133
3 Linear Model Identification
sim('iddempr5')
dat1f = iddata(y,u,0.5); % The IDDATA object for the simulated data
We estimate an IDPROC model using data1f while also imposing an upper bound on
the allowable value delay. We will use 'lm' as search method and also choose to view the
estimation progress.
m2_init = idproc('P1D');
m2_init.Structure.Td.Maximum = 2;
opt = procestOptions('SearchMethod','lm','Display','on');
m2 = procest(dat1f,m2_init,opt);
m2
m2 =
Process model with transfer function:
Kp
G(s) = ---------- * exp(-Td*s)
1+Tp1*s
Kp = 0.20038
Tp1 = 2.01
Td = 1.31
Parameterization:
'P1D'
Number of free coefficients: 3
3-134
Building and Estimating Process Models Using System Identification Toolbox™
Status:
Estimated using PROCEST on time domain data "dat1f".
Fit to estimation data: 87.26%
FPE: 0.01067, MSE: 0.01061
This model has a slightly less precise estimate of the delay than the previous one, m1:
ans =
3-135
3 Linear Model Identification
However, by telling the estimation process that the intersample behavior is first-order-
hold (an approximation to the true continuous) input, we do better:
dat1f.InterSample = 'foh';
m3 = procest(dat1f,m2_init,opt);
Compare the four models m0 (true) m1 (obtained from zoh input) m2 (obtained for
continuous input, with zoh assumption) and m3 (obtained for the same input, but with
foh assumption)
3-136
Building and Estimating Process Models Using System Identification Toolbox™
bdclose('iddempr5')
ans =
3-137
3 Linear Model Identification
Let us now consider a more complex process, with integration, that is operated in closed
loop:
open_system('iddempr2')
3-138
Building and Estimating Process Models Using System Identification Toolbox™
m0 = idproc('P2ZDI','Kp',1,'Tp1',1,'Tp2',5,'Tz',3,'Td',2.2);
The process is controlled by a PD regulator with limited input amplitude and a zero order
hold device. The sampling interval is 1 second.
set_param('iddempr2/Random Number','seed','0')
sim('iddempr2')
dat2 = iddata(y,u,1); % IDDATA object for estimation
Two different simulations are made, the first for estimation and the second one for
validation purposes.
set_param('iddempr2/Random Number','seed','13')
sim('iddempr2')
dat2v = iddata(y,u,1); % IDDATA object for validation purpose
plot(dat2,dat2v)
legend('dat2 (estimation)','dat2v (validation)')
3-139
3 Linear Model Identification
m2 =
Process model with transfer function:
1+Tz*s
G(s) = Kp * ------------------- * exp(-Td*s)
s(1+Tp1*s)(1+Tp2*s)
3-140
Building and Estimating Process Models Using System Identification Toolbox™
Kp = 1.0028
Tp1 = 1.1175
Tp2 = 5.9022
Td = 2.133
Tz = 3.8084
Parameterization:
'P2DIZ'
Number of free coefficients: 5
Use "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using PROCEST on time domain data "dat2".
Fit to estimation data: 91.86%
FPE: 0.1041, MSE: 0.1005
3-141
3 Linear Model Identification
bode(m2,m0)
legend({'m2 (est)','m0 (actual)'},'location','west')
3-142
Building and Estimating Process Models Using System Identification Toolbox™
impulse(m2,m0)
legend({'m2 (est)','m0 (actual)'})
3-143
3 Linear Model Identification
m2 =
Process model with transfer function:
1+Tz*s
G(s) = Kp * ------------------- * exp(-Td*s)
s(1+Tp1*s)(1+Tp2*s)
3-144
Building and Estimating Process Models Using System Identification Toolbox™
Parameterization:
'P2DIZ'
Number of free coefficients: 5
Use "getpvec", "getcov" for parameters and their uncertainties.
Status:
Termination condition: Change in cost was less than the specified tolerance.
Number of iterations: 32, Number of function evaluations: 33
ans =
1.0000 1.0028
1.0000 1.1175
5.0000 5.9022
2.2000 2.1330
3.0000 3.8084
A word of caution. Identification of several real time constants may sometimes be an ill-
conditioned problem, especially if the data are collected in closed loop.
m2v =
Process model with transfer function:
1+Tz*s
G(s) = Kp * ------------------- * exp(-Td*s)
s(1+Tp1*s)(1+Tp2*s)
Kp = 1.0059
Tp1 = 0.22619
Tp2 = 3.6898
Td = 0.943
3-145
3 Linear Model Identification
Tz = -0.33583
Parameterization:
'P2DIZ'
Number of free coefficients: 5
Use "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using PROCEST on time domain data "dat2v".
Fit to estimation data: 91.98%
FPE: 0.1032, MSE: 0.09958
ans =
This model has much worse parameter values. On the other hand, it performs nearly
identically to the true system m0 when tested on the other data set dat2:
compare(dat2,m0,m2,m2v)
3-146
Building and Estimating Process Models Using System Identification Toolbox™
m2v =
Process model with transfer function:
3-147
3 Linear Model Identification
1+Tz*s
G(s) = Kp * ------------------- * exp(-Td*s)
s(1+Tp1*s)(1+Tp2*s)
Kp = 1.0111
Tp1 = 1
Tp2 = 5.2957
Td = 2.194
Tz = 3.2249
Parameterization:
'P2DIZ'
Number of free coefficients: 4
Use "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using PROCEST on time domain data "dat2v".
Fit to estimation data: 92.05%
FPE: 0.09989, MSE: 0.09794
As observed, fixing Tp1 to its known value dramatically improves the estimates of the
remaining parameters in model m2v.
This also indicates that simple approximation should do well on the data:
m1x_init = idproc('P2D'); % simpler structure (no zero, no integrator)
m1x_init.Structure.Td.Maximum = 2;
m1x = procest(dat2v, m1x_init)
compare(dat2,m0,m2,m2v,m1x)
m1x =
Process model with transfer function:
Kp
G(s) = ----------------- * exp(-Td*s)
(1+Tp1*s)(1+Tp2*s)
Kp = 14815
Tp1 = 15070
Tp2 = 3.1505
Td = 1.833
Parameterization:
'P2D'
Number of free coefficients: 4
3-148
Building and Estimating Process Models Using System Identification Toolbox™
Status:
Estimated using PROCEST on time domain data "dat2v".
Fit to estimation data: 91.23%
FPE: 0.1209, MSE: 0.119
Thus, the simpler model is able to estimate system output pretty well. However, m1x
does not contain any integration, so the open loop long time range behavior will be quite
different:
step(m0,m2,m2v,m1x)
legend('m0','m2','m2v','m1x')
bdclose('iddempr2')
3-149
3 Linear Model Identification
Additional Information
3-150
Determining Model Order and Delay
• Guess their values by visually inspecting the data or based on the prior knowledge of
the system.
• Estimate delay as a part of idproc or idtf model estimation. These models
treat delay as an estimable parameter and you can determine their values by
the estimation commands procest and tfest, respectively. However automatic
estimation of delays can cause errors. Therefore, it is recommended that you analyze
the data for delays in advance.
• To estimate delays, you can also use one of the following tools:
• Estimate delay using delayest. The choice of the order of the underlying ARX
model and the lower/upper bound on the value of the delay to be estimated
influence the value returned by delayest.
• Compute impulse response using impulseest. Plot the impulse response with
a confidence interval of sufficient standard deviations (usually 3). The delay is
indicated by the number of response samples that are inside the statistically zero
region (marked by the confidence bound) before the response goes outside that
region.
• Select the model order in n4sid by specifying the model order as a vector.
• Choose the model order of an ARX model using arxstruc or ivstruc and
selstruc. These command select the number of poles, zeros and delay.
See “Model Structure Selection: Determining Model Order and Input Delay” on page
3-152 for an example of using these tools.
3-151
3 Linear Model Identification
Introduction
Choosing a model structure is usually the first step towards its estimation. There are
various possibilities for structure - state-space, transfer functions and polynomial forms
such as ARX, ARMAX, OE, BJ etc. If you do not have detailed prior knowledge of your
system, such as its noise characteristics and indication of feedback, the choice of a
reasonable structure may not be obvious. Also for a given choice of structure, the order
of the model needs to be specified before the corresponding parameters are estimated.
System Identification Toolbox™ offers some tools to assist in the task of model order
selection.
The choice of a model order is also influenced by the amount of delay. A good idea of
the input delay simplifies the task of figuring out the orders of other model coefficients.
Discussed below are some options for input delay determination and model structure and
order selection.
This example uses the hair dryer data, also used by iddemo1 ("Estimating Simple Models
from Real Laboratory Process Data"). The process consists of air being fanned through a
tube. The air is heated at the inlet of the tube, and the input is the voltage applied to the
heater. The output is the temperature at the outlet of the tube.
Let us begin by loading the measurement data and doing some basic preprocessing:
load dry2
Form a data set for estimation of the first half, and a reference set for validation
purposes of the second half:
ze = dry2(1:500);
3-152
Model Structure Selection: Determining Model Order and Input Delay
zr = dry2(501:1000);
There are various options available for determining the time delay from input to output.
These are:
3-153
3 Linear Model Identification
Using delayest:
Let us discuss the above options in detail. Function delayest returns an estimate of
the delay for a given choice of orders of numerator and denominator polynomials. This
function evaluates an ARX structure:
with various delays and chooses the delay value that seems to return the best fit. In this
process, chosen values of na and nb are used.
delay =
A value of 3 is returned by default. But this value may change a bit if the assumed orders
of numerator and denominator polynomials (2 here) is changed. For example:
delay = delayest(ze,5,4)
delay =
returns a value of 2. To gain insight into how delayest works, let us evaluate the
loss function for various choices of delays explicitly. We select a second order model
(na=nb=2), which is the default for delayest, and try out every time delay between 1
and 10. The loss function for the different models are computed using the validation data
set:
3-154
Model Structure Selection: Determining Model Order and Input Delay
V = arxstruc(ze,zr,struc(2,2,1:10));
We now select that delay that gives the best fit for the validation data:
nn
nn =
2 2 3
We can also check how the fit depends on the delay. This information is returned in the
second output Vm. The logarithms of a quadratic loss function are given as the first row,
while the indexes na, nb and nk are given as a column below the corresponding loss
function.
Vm
Vm =
Columns 1 through 7
Columns 8 through 10
3-155
3 Linear Model Identification
loss is minimum.
Using impulse
To gain a better insight into the dynamics, let us compute the impulse response of the
system. We will use the function impulseest to compute a non-parametric impulse
response model. We plot this response with a confidence interval represented by 3
standard deviations.
FIRModel = impulseest(ze);
clf
h = impulseplot(FIRModel);
showConfidence(h,3)
3-156
Model Structure Selection: Determining Model Order and Input Delay
The filled light-blue region shows the confidence interval for the insignificant response in
this estimation. There is a clear indication that the impulse response "takes off" (leaves
the uncertainty region) after 3 samples. This points to a delay of three intervals.
We may also estimate a family of parametric models to find the delay corresponding
to the "best" model. In case of state-space models, a range of orders may be evaluated
simultaneously and the best order picked from a Hankel Singular Value plot. Execute the
following command to invoke n4sid in an interactive mode:
3-157
3 Linear Model Identification
The plot indicates an order of 3 as the best value. For this choice, let us compute the
impulse response of the model m:
m = n4sid(ze, 3);
showConfidence(impulseplot(m),3)
As with non-parametric impulse response, there is a clear indication that the delay from
input to output is of three samples.
In lack of any prior knowledge, it is advisable to try out various available choices and
use the one that seems to work the best. State-space models may be a good starting point
3-158
Model Structure Selection: Determining Model Order and Input Delay
since only the number of states needs to be specified in order to estimate a model. Also,
a range of orders may be evaluated quickly, using n4sid, for determining the best order,
as described in the next section. For polynomial models, a similar advantage is realized
using the arx estimator. Output-error (OE) models may also be good choice for a starting
polynomial model because of their simplicity.
Once you have decided upon a model structure to use, the next task is to determine the
order(s). In general, the aim should be to not use a model order higher than necessary.
This can be determined by analyzing the improvement in %fit as a function of model
order. When doing this, it is advisable to use a separate, independent dataset for
validation. Choosing an independent validation data set (zr in our example) would
improve the detection of over-fitting.
V = arxstruc(ze,zr,struc(1:10,1:10,3));
The best fit for the validation data set is obtained for:
nn = selstruc(V,0)
nn =
10 4 3
Let us check how much the fit is improved for the higher order models. For this, we
use the function selstruc with only one input. In this case, a plot showing the fit as a
function of the number of parameters used is generated. The user is also prompted to
enter the number of parameters. The routine then selects a structure with these many
parameters that gives the best fit. Note that several different model structures use the
same number of parameters. Execute the following command to choose a model order
interactively:
3-159
3 Linear Model Identification
The best fit is thus obtained for nn = [4 4 3], while we see that the improved fit compared
to nn = [2 2 3] is rather marginal.
We may also approach this problem from the direction of reducing a higher order model.
If the order is higher than necessary, then the extra parameters are basically used to
"model" the measurement noise. These "extra" poles are estimated with a lower level of
accuracy (large confidence interval). If their are cancelled by a zero located nearby, then
it is an indication that this pole-zero pair may not be required to capture the essential
dynamics of the system.
3-160
Model Structure Selection: Determining Model Order and Input Delay
Let us check the pole-zero configuration for this model. We can also include confidence
regions for the poles and zeros corresponding to 3 standard deviations, in order to
determine how accurately they are estimated and also how close the poles and zeros are
to each other.
h = iopzplot(th4);
showConfidence(h,3)
The confidence intervals for the two complex-conjugate poles and zeros overlap,
indicating they are likely to cancel each other. Hence, a second order model might be
adequate. Based on this evidence, let us compute a 2nd order ARX model:
3-161
3 Linear Model Identification
We can test how well this model (th2) is capable of reproducing the validation data set.
To compare the simulated output from the two models with the actual output (plotting
the mid 200 data points) we use the compare utility:
compare(zr(150:350),th2,th4)
The plot indicates that there was no significant loss of accuracy in reducing the order
from 4 to 2. We can also check the residuals ("leftovers") of this model, i.e., what is left
unexplained by the model.
e = resid(ze,th2);
plot(e(:,1,[])), title('The residuals')
3-162
Model Structure Selection: Determining Model Order and Input Delay
We see that the residuals are quite small compared to the signal level of the output, that
they are reasonably well (although not perfectly) uncorrelated with the input and among
themselves. We can thus be (provisionally) satisfied with the model th2.
Let us now check if we can determine the model order for a state-space structure. As
before, we know the delay is 3 samples. We can try all orders from 1 to 15 with a total lag
of 3 samples in n4sid. Execute the following command to try various orders and choose
one interactively.
3-163
3 Linear Model Identification
The "InputDelay" was set to 2 because by default n4sid estimates a model with no
feedthrough (which accounts for one sample lag between input and output). The default
order, indicated in the figure above, is 3, that is in good agreement with our earlier
findings. Finally, we compare how the state-space model ms and the ARX model th2
compare in reproducing the measured output of the validation data:
ms = n4sid(ze,3,'InputDelay',2);
compare(zr,ms,th2)
3-164
Model Structure Selection: Determining Model Order and Input Delay
The comparison plot indicates that the two models are practically identical.
Conclusions
This example described some options for choosing a reasonable model order. Determining
delay in advance can simplify the task of choosing orders. With ARX and state-space
structures, we have some special tools (arx and n4sid estimators) for automatically
evaluating a whole set of model orders, and choosing the best one among them. The
information revealed by this exercise (using utilities such as arxstruc, selstruc,
n4sid and delayest) could be used as a starting point when estimating models of other
structures, such as BJ and ARMAX.
Additional Information
3-165
3 Linear Model Identification
3-166
Frequency Domain Identification: Estimating Models Using Frequency Domain Data
Frequency domain data can not be used for estimation or validation of nonlinear models.
Introduction
Frequency domain experimental data are common in many applications. It could be that
the data was collected as frequency response data (frequency functions: FRF) from the
process using a frequency analyzer. It could also be that it is more practical to work with
the input's and output's Fourier transforms (FFT of time-domain data), for example to
handle periodic or band-limited data. (A band-limited continuous time signal has no
frequency components above the Nyquist frequency). In System Identification Toolbox,
frequency domain I/O data are represented the same way as time-domain data, i.e.,
using iddata objects. The 'Domain' property of the object must be set to 'Frequency'.
Frequency response data are represented as complex vectors or as magnitude/phase
vectors as a function of frequency. IDFRD objects in the toolbox are used to encapsulate
FRFs, where a user specifies the complex response data and a frequency vector. Such
IDDATA or IDFRD objects (and also FRD objects of Control System Toolbox) may be
used seamlessly with any estimation routine (such as procest, tfest etc).
load demofr
This MAT-file contains frequency response data at frequencies W, with the amplitude
response AMP and the phase response PHA. Let us first have a look at the data:
3-167
3 Linear Model Identification
This experimental data will now be stored as an IDFRD object. First transform
amplitude and phase to a complex valued response:
zfr = AMP.*exp(1i*PHA*pi/180);
Ts = 0.1;
gfr = idfrd(zfr,W,Ts);
Ts is the sampling interval of the underlying data. If the data corresponds to continuous
time, for example since the input has been band-limited, use Ts = 0.
Note: If you have the Control System Toolbox™, you could use an FRD object instead of
the IDFRD object. IDFRD has options for more information, like disturbance spectra and
uncertainty measures which are not available in FRD objects.
3-168
Frequency Domain Identification: Estimating Models Using Frequency Domain Data
The IDFRD object gfr now contains the data, and it can be plotted and analyzed in
different ways. To view the data, we may use plot or bode:
clf
bode(gfr), legend('gfr')
To estimate models, you can now use gfr as a data set with all the commands of the
toolbox in a transparent fashion. The only restriction is that noise models cannot be built.
This means that for polynomial models only OE (output-error models) apply, and for
state-space models, you have to fix K = 0.
m1 = oe(gfr,[2 2 1]) % Discrete-time Output error (transfer function) model
ms = ssest(gfr) % Continuous-time state-space model with default choice of order
3-169
3 Linear Model Identification
m1 =
Discrete-time OE model: y(t) = [B(z)/F(z)]u(t) + e(t)
B(z) = 0.9986 z^-1 + 0.4968 z^-2
Parameterization:
Polynomial orders: nb=2 nf=2 nk=1
Number of free coefficients: 4
Use "polydata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using OE on frequency response data "gfr".
Fit to estimation data: 88.04%
FPE: 0.2492, MSE: 0.2492
ms =
Continuous-time identified state-space model:
dx/dt = A x(t) + B u(t) + K e(t)
y(t) = C x(t) + D u(t) + e(t)
A =
x1 x2
x1 -0.9009 6.635
x2 -3.307 -2.668
B =
u1
x1 -32.9
x2 -28.33
C =
x1 x2
y1 -0.5073 0.499
D =
u1
y1 0
3-170
Frequency Domain Identification: Estimating Models Using Frequency Domain Data
K =
y1
x1 0
x2 0
Parameterization:
FREE form (all coefficients in A, B, C free).
Feedthrough: none
Disturbance component: none
Number of free coefficients: 8
Use "idssdata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using SSEST on frequency response data "gfr".
Fit to estimation data: 73.16%
FPE: 0.2502, MSE: 1.254
mproc =
Process model with transfer function:
1+Tz*s
G(s) = Kp * ---------------------- * exp(-Td*s)
1+2*Zeta*Tw*s+(Tw*s)^2
Kp = 7.4619
Tw = 0.20245
Zeta = 0.36242
Td = 0
Tz = 0.013617
Parameterization:
'P2DUZ'
Number of free coefficients: 5
Use "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using PROCEST on frequency response data "gfr".
Fit to estimation data: 73.2%
FPE: 0.2495, MSE: 1.25
3-171
3 Linear Model Identification
As shown above a variety of linear model types may be estimated in both continuous and
discrete time domains, using spectral data. These models may be validated using, time-
domain data. The time-domain I/O data set ztime, for example, is collected from the
same system, and can be used for validation of m1, ms and mproc:
3-172
Frequency Domain Identification: Estimating Models Using Frequency Domain Data
We may also look at the residuals to affirm the quality of the model using the validation
data ztime. As observed, the residuals are almost white:
3-173
3 Linear Model Identification
An important reason to work with frequency response data is that it is easy to condense
the information with little loss. The command SPAFDR allows you to compute smoothed
response data over limited frequencies, for example with logarithmic spacing. Here is
an example where the gfr data is condensed to 100 logarithmically spaced frequency
values. With a similar technique, also the original time domain data can be condensed:
3-174
Frequency Domain Identification: Estimating Models Using Frequency Domain Data
sgfr =
IDFRD model.
Contains Frequency Response Data for 1 output(s) and 1 input(s), and the spectra for di
Response data and disturbance spectra are available at 100 frequency points, ranging fr
3-175
3 Linear Model Identification
The Bode plots show that the information in the smoothed data has been taken well care
of. Now, these data records with 100 points can very well be used for model estimation.
For example:
msm = oe(sgfr,[2 2 1]);
compare(ztime,msm,m1) % msm has the same accuracy as M1 (based on 1000 points)
It may be that the measurements are available as Fourier transforms of inputs and
output. Such frequency domain data from the system are given as the signals Y and U. In
loglog plots they look like
Wfd = (0:500)'*10*pi/500;
subplot(211),loglog(Wfd,abs(Y)),title('The amplitude of the output')
3-176
Frequency Domain Identification: Estimating Models Using Frequency Domain Data
The frequency response data is essentially the ratio between Y and U. To collect the
frequency domain data as an IDDATA object, do as follows:
ZFD = iddata(Y,U,'ts',0.1,'Domain','Frequency','Freq',Wfd)
ZFD =
3-177
3 Linear Model Identification
y1
Now, again the frequency domain data set ZFD can be used as data in all estimation
routines, just as time domain data and frequency response data:
mf = ssest(ZFD) % SSEST picks best order in 1:10 range when called this way
mfr = ssregest(ZFD) % an alternative regularized reduction based state-space estimator
compare(ztime,mf,mfr,m1)
mf =
Continuous-time identified state-space model:
dx/dt = A x(t) + B u(t) + K e(t)
y(t) = C x(t) + D u(t) + e(t)
A =
x1 x2
x1 -1.501 6.791
x2 -3.115 -2.059
B =
u1
x1 -28.11
x2 -33.39
C =
x1 x2
y1 -0.5844 0.4129
D =
u1
y1 0
K =
y1
x1 0
x2 0
Parameterization:
FREE form (all coefficients in A, B, C free).
Feedthrough: none
3-178
Frequency Domain Identification: Estimating Models Using Frequency Domain Data
Status:
Estimated using SSEST on frequency domain data "ZFD".
Fit to estimation data: 97.21%
FPE: 0.04263, MSE: 0.04179
mfr =
Discrete-time identified state-space model:
x(t+Ts) = A x(t) + B u(t) + K e(t)
y(t) = C x(t) + D u(t) + e(t)
A =
x1 x2 x3 x4 x5 x6
x1 0.6552 0.6194 -0.212 0.001125 0.05928 0.08817
x2 -0.189 0.3955 0.6197 0.1951 0.2022 -0.08355
x3 -0.3024 0.6054 -0.3126 0.02585 -0.1829 -0.162
x4 -0.06436 0.1201 0.07096 -0.679 0.5621 -0.06486
x5 -0.05577 0.00528 -0.09426 -0.08431 0.1222 0.5888
x6 0.005306 -0.05481 0.3242 -0.3403 -0.2923 -0.2853
x7 -0.0005408 0.1019 0.02489 -0.09813 -0.3741 0.05454
x8 0.01313 0.06723 -0.03633 0.07937 -0.2934 0.3659
x9 -0.01436 0.0138 -0.133 0.1117 0.259 -0.01073
x10 0.007467 -0.09578 0.09325 0.0836 0.2193 -0.5335
x7 x8 x9 x10
x1 0.06715 0.06958 0.06185 0.1452
x2 0.1775 0.1755 0.03826 0.05137
x3 -0.2076 0.06537 -0.17 0.06656
x4 -0.2574 -0.1622 0.0801 -0.3327
x5 0.7376 0.2966 -0.4042 0.499
x6 -0.06971 0.3705 -0.11 0.292
x7 0.1632 0.1927 0.3252 -0.7328
x8 -0.4043 -0.02296 -0.4008 -0.2135
x9 -0.463 0.822 -0.0677 0.02849
x10 0.1881 0.2637 -0.2241 -0.6783
B =
u1
x1 1.555
x2 0.3412
x3 -0.01226
3-179
3 Linear Model Identification
x4 0.01437
x5 0.08268
x6 0.03217
x7 0.06806
x8 0.02006
x9 -0.04152
x10 0.02122
C =
x1 x2 x3 x4 x5 x6 x7
y1 1.18 -2.337 -0.7734 -0.2832 0.2353 0.8738 -0.6108
x8 x9 x10
y1 0.653 1.103 -0.5883
D =
u1
y1 0
K =
y1
x1 -0.02321
x2 -0.07354
x3 -0.08669
x4 0.009556
x5 -0.03322
x6 -0.03809
x7 0.05905
x8 -0.02889
x9 0.009478
x10 0.0161
Parameterization:
FREE form (all coefficients in A, B, C free).
Feedthrough: none
Disturbance component: estimate
Number of free coefficients: 130
Use "idssdata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using SSREGEST on frequency domain data "ZFD".
Fit to estimation data: 66.73% (prediction focus)
3-180
Frequency Domain Identification: Estimating Models Using Frequency Domain Data
Time and frequency domain input-output data sets can be transformed to either domain
by using FFT and IFFT. These commands are adapted to IDDATA objects:
dataf = fft(ztime)
datat = ifft(dataf)
dataf =
3-181
3 Linear Model Identification
datat =
Time and frequency domain input-output data can be transformed to frequency response
data by SPAFDR, SPA and ETFE:
g1 = spafdr(ztime)
g2 = spafdr(ZFD);
clf;
bode(g1,g2)
g1 =
IDFRD model.
Contains Frequency Response Data for 1 output(s) and 1 input(s), and the spectra for di
Response data and disturbance spectra are available at 100 frequency points, ranging fr
3-182
Frequency Domain Identification: Estimating Models Using Frequency Domain Data
Frequency response data can also be transformed to more smoothed data (less resolution
and less data) by SPAFDR and SPA;
g3 = spafdr(gfr);
gfd = iddata(g3)
gfd =
3-183
3 Linear Model Identification
Time domain data can naturally only be stored and dealt with as discrete-time, sampled
data. Frequency domain data have the advantage that continuous time data can be
represented correctly. Suppose that the underlying continuous time signals have no
frequency information above the Nyquist frequency, e.g. because they are sampled
fast, or the input has no frequency component above the Nyquist frequency. Then the
Discrete Fourier transforms (DFT) of the data also are the Fourier transforms of the
continuous time signals, at the chosen frequencies. They can therefore be used to directly
fit continuous time models. In fact, this is the correct way of using band-limited data for
model fit.
m0 = idpoly(1,1,1,1,[1 1 1],'ts',0)
m0 =
Continuous-time OE model: y(t) = [B(s)/F(s)]u(t) + e(t)
B(s) = 1
F(s) = s^2 + s + 1
Parameterization:
Polynomial orders: nb=1 nf=2 nk=0
Number of free coefficients: 3
3-184
Frequency Domain Identification: Estimating Models Using Frequency Domain Data
Status:
Created by direct construction or transformation. Not estimated.
rng(235,'twister');
u = idinput(500,'sine',[0 0.2]);
u = iddata([],u,0.1,'intersamp','bl');
0.1 is the sampling interval, and 'bl' indicates that the input is band-limited, i.e.
in continuous time it consists of sinusoids with frequencies below half the sampling
frequency. Correct simulation of such a system should be done in the frequency domain:
uf = fft(u);
uf.ts = 0; % Denoting that the data is continuous time
yf = sim(m0,uf);
%
% Add some noise to the data:
yf.y = yf.y + 0.05*(randn(size(yf.y))+1i*randn(size(yf.y)));
dataf = [yf uf] % This is now a continuous time frequency domain data set.
dataf =
plot(dataf)
axis([0 10 0 2.5])
3-185
3 Linear Model Identification
Using dataf for estimation will by default give continuous time models: State-space:
nb = 2;
nf = 2;
m5 = oe(dataf,[nb nf])
m5 =
Continuous-time OE model: y(t) = [B(s)/F(s)]u(t) + e(t)
3-186
Frequency Domain Identification: Estimating Models Using Frequency Domain Data
B(s) = -0.01761 s + 1
Parameterization:
Polynomial orders: nb=2 nf=2 nk=0
Number of free coefficients: 4
Use "polydata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using OE on frequency domain data "dataf".
Fit to estimation data: 70.15%
FPE: 0.00482, MSE: 0.004713
Compare step responses with uncertainty of the true system m0 and the models m4 and
m5. The confidence intervals are shown with patches in the plot.
clf
h = stepplot(m0,m4,m5);
showConfidence(h,1)
legend('show','location','southeast')
3-187
3 Linear Model Identification
Although it was not necessary in this case, it is generally advised to focus the fit to a
limited frequency band (low pass filter the data) when estimating using continuous time
data. The system has a bandwidth of about 3 rad/s, and was excited by sinusoids up to
6.2 rad/s. A reasonable frequency range to focus the fit to is then [0 7] rad/s:
m6 =
Continuous-time identified state-space model:
dx/dt = A x(t) + B u(t) + K e(t)
y(t) = C x(t) + D u(t) + e(t)
A =
3-188
Frequency Domain Identification: Estimating Models Using Frequency Domain Data
x1 x2
x1 -0.2714 -1.809
x2 0.4407 -0.7282
B =
u1
x1 0.5873
x2 -0.3025
C =
x1 x2
y1 0.7565 1.526
D =
u1
y1 0
K =
y1
x1 0
x2 0
Parameterization:
FREE form (all coefficients in A, B, C free).
Feedthrough: none
Disturbance component: none
Number of free coefficients: 8
Use "idssdata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using SSEST on frequency domain data "dataf".
Fit to estimation data: 87.08% (filter focus)
FPE: 0.004213, MSE: 0.003682
m7 =
Continuous-time OE model: y(t) = [B(s)/F(s)]u(t) + e(t)
B(s) = 0.9866
Parameterization:
Polynomial orders: nb=1 nf=2 nk=0
3-189
3 Linear Model Identification
Status:
Estimated using OE on frequency domain data "dataf".
Fit to estimation data: 87.04% (filter focus)
FPE: 0.004008, MSE: 0.003708
m8 =
Process model with transfer function:
1+Tz*s
G(s) = Kp * ----------------------
1+2*Zeta*Tw*s+(Tw*s)^2
Kp = 1.0124
Tw = 1.0019
Zeta = 0.5021
Tz = -0.017474
Parameterization:
'P2UZ'
Number of free coefficients: 4
Use "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using PROCEST on frequency domain data "dataf".
Fit to estimation data: 87.08% (filter focus)
FPE: 0.003947, MSE: 0.003682
m9 =
3-190
Frequency Domain Identification: Estimating Models Using Frequency Domain Data
Parameterization:
Number of poles: 2 Number of zeros: 1
Number of free coefficients: 4
Use "tfdata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using TFEST on frequency domain data "dataf".
Fit to estimation data: 87.08% (filter focus)
FPE: 0.004067, MSE: 0.003684
h = stepplot(m0,m6,m7,m8,m9);
showConfidence(h,1)
legend('show')
3-191
3 Linear Model Identification
Conclusions
We saw how time, frequency and spectral data can seamlessly be used to estimate a
variety of linear models in both continuous and discrete time domains. The models may
be validated and compared in domains different from the ones they were estimated in.
The data formats (time, frequency and spectrum) are interconvertible, using methods
such as fft, ifft, spafdr and spa. Furthermore, direct, continuous-time estimation
is achievable by using tfest, ssest and procest estimation routines. The seamless
use of data in any domain for estimation and analysis is an important feature of System
Identification Toolbox.
Additional Information
3-192
Building Structured and User-Defined Models Using System Identification Toolbox™
Experiment Data
We shall investigate data produced by a (simulated) dc-motor. We first load the data:
load dcmdata
who
text u y
The matrix y contains the two outputs: y1 is the angular position of the motor shaft and
y2 is the angular velocity. There are 400 data samples and the sampling interval is 0.1
seconds. The input is contained in the vector u. It is the input voltage to the motor.
3-193
3 Linear Model Identification
plot(z(:,2,:))
3-194
Building Structured and User-Defined Models Using System Identification Toolbox™
d/dt x = A x + B u + K e
y = C x + D u + e
We shall build a model of the dc-motor. The dynamics of the motor is well known. If we
choose x1 as the angular position and x2 as the angular velocity it is easy to set up a
state-space model of the following character neglecting disturbances: (see Example 4.1 in
Ljung(1999):
| 0 1 | | 0 |
d/dt x = | | x + | | u
3-195
3 Linear Model Identification
| 0 -th1 | | th2 |
| 1 0 |
y = | | x
| 0 1 |
The parameter th1 is here the inverse time-constant of the motor and th2 is such that
th2/th1 is the static gain from input to the angular velocity. (See Ljung(1987) for how
th1 and th2 relate to the physical parameters of the motor). We shall estimate these
two parameters from the observed data. The model structure (parameterized state space)
described above can be represented in MATLAB® using IDSS and IDGREY models.
These models let you perform estimation of parameters using experimental data.
If we guess that th1=1 and th2 = 0.28 we obtain the nominal or initial model
ms = idss(A,B,C,D);
The model is characterized by its matrices, their values, which elements are free (to be
estimated) and upper and lower limits of those:
ms.Structure.a
ans =
Name: 'a'
Value: [2x2 double]
Minimum: [2x2 double]
Maximum: [2x2 double]
Free: [2x2 logical]
Scale: [2x2 double]
Info: [2x2 struct]
1x1 param.Continuous
3-196
Building Structured and User-Defined Models Using System Identification Toolbox™
ms.Structure.a.Value
ms.Structure.a.Free
ans =
0 1
0 -1
ans =
1 1
1 1
So we should now mark that it is only A(2,2) and B(2,1) that are free parameters to be
estimated.
ms.Structure.a.Free = [0 0; 0 1];
ms.Structure.b.Free = [0; 1];
ms.Structure.c.Free = 0; % scalar expansion used
ms.Structure.d.Free = 0;
ms.Ts = 0; % This defines the model to be continuous
ms % Initial model
ms =
Continuous-time identified state-space model:
dx/dt = A x(t) + B u(t) + K e(t)
y(t) = C x(t) + D u(t) + e(t)
A =
x1 x2
x1 0 1
x2 0 -1
B =
3-197
3 Linear Model Identification
u1
x1 0
x2 0.28
C =
x1 x2
y1 1 0
y2 0 1
D =
u1
y1 0
y2 0
K =
y1 y2
x1 0 0
x2 0 0
Parameterization:
STRUCTURED form (some fixed coefficients in A, B, C).
Feedthrough: none
Disturbance component: none
Number of free coefficients: 2
Use "idssdata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Created by direct construction or transformation. Not estimated.
The prediction error (maximum likelihood) estimate of the parameters is now computed
by:
dcmodel = ssest(z,ms,ssestOptions('Display','on'));
dcmodel
dcmodel =
Continuous-time identified state-space model:
dx/dt = A x(t) + B u(t) + K e(t)
y(t) = C x(t) + D u(t) + e(t)
A =
x1 x2
3-198
Building Structured and User-Defined Models Using System Identification Toolbox™
x1 0 1
x2 0 -4.013
B =
Voltage
x1 0
x2 1.002
C =
x1 x2
Angle 1 0
AngVel 0 1
D =
Voltage
Angle 0
AngVel 0
K =
Angle AngVel
x1 0 0
x2 0 0
Parameterization:
STRUCTURED form (some fixed coefficients in A, B, C).
Feedthrough: none
Disturbance component: none
Number of free coefficients: 2
Use "idssdata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using SSEST on time domain data "z".
Fit to estimation data: [98.35;84.42]%
FPE: 0.001071, MSE: 0.1192
The estimated values of the parameters are quite close to those used when the data were
simulated (-4 and 1). To evaluate the model's quality we can simulate the model with the
actual input by and compare it with the actual output.
compare(z,dcmodel);
3-199
3 Linear Model Identification
We can now, for example plot zeros and poles and their uncertainty regions. We will
draw the regions corresponding to 3 standard deviations, since the model is quite
accurate. Note that the pole at the origin is absolutely certain, since it is part of the
model structure; the integrator from angular velocity to position.
clf
showConfidence(iopzplot(dcmodel),3)
3-200
Building Structured and User-Defined Models Using System Identification Toolbox™
Now, we may make various modifications. The 1,2-element of the A-matrix (fixed to 1)
tells us that x2 is the derivative of x1. Suppose that the sensors are not calibrated, so
that there may be an unknown proportionality constant. To include the estimation of
such a constant we just "let loose" A(1,2) and re-estimate:
dcmodel2 = dcmodel;
dcmodel2.Structure.a.Free(1,2) = 1;
dcmodel2 = pem(z,dcmodel2,ssestOptions('Display','on'));
dcmodel2 =
3-201
3 Linear Model Identification
A =
x1 x2
x1 0 0.9975
x2 0 -4.011
B =
Voltage
x1 0
x2 1.004
C =
x1 x2
Angle 1 0
AngVel 0 1
D =
Voltage
Angle 0
AngVel 0
K =
Angle AngVel
x1 0 0
x2 0 0
Parameterization:
STRUCTURED form (some fixed coefficients in A, B, C).
Feedthrough: none
Disturbance component: none
Number of free coefficients: 3
Use "idssdata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using SSEST on time domain data "z".
Fit to estimation data: [98.35;84.42]%
FPE: 0.001076, MSE: 0.1192
We find that the estimated A(1,2) is close to 1. To compare the two model we use the
compare command:
compare(z,dcmodel,dcmodel2)
3-202
Building Structured and User-Defined Models Using System Identification Toolbox™
Suppose that we accurately know the static gain of the dc-motor (from input voltage to
angular velocity, e.g. from a previous step-response experiment. If the static gain is G,
and the time constant of the motor is t, then the state-space model becomes
|0 1| | 0 |
d/dt x = | |x + | | u
|0 -1/t| | G/t |
|1 0|
y = | | x
|0 1|
3-203
3 Linear Model Identification
With G known, there is a dependence between the entries in the different matrices. In
order to describe that, the earlier used way with "Free" parameters will not be sufficient.
We thus have to write a MATLAB file which produces the A, B, C, and D, and optionally
also the K and X0 matrices as outputs, for each given parameter vector as input. It also
takes auxiliary arguments as inputs, so that the user can change certain things in the
model structure, without having to edit the file. In this case we let the known static gain
G be entered as such an argument. The file that has been written has the name 'motor.m'.
type motor
% L. Ljung
% Copyright 1986-2011 The MathWorks, Inc.
t = par(1);
G = aux(1);
A = [0 1;0 -1/t];
B = [0;G/t];
C = eye(2);
D = [0;0];
K = zeros(2);
X0 = [0;0];
if ts>0 % Sample the model with sample time Ts
s = expm([[A B]*ts; zeros(1,3)]);
A = s(1:2,1:2);
B = s(1:2,3);
3-204
Building Structured and User-Defined Models Using System Identification Toolbox™
end
We now create an IDGREY model object corresponding to this model structure: The
assumed time constant will be
par_guess = 1;
We also give the value 0.25 to the auxiliary variable G (gain) and sampling interval.
aux = 0.25;
dcmm = idgrey('motor',par_guess,'cd',aux,0);
dcmm = greyest(z,dcmm,greyestOptions('Display','on'));
We have thus now estimated the time constant of the motor directly. Its value is in good
agreement with the previous estimate.
dcmm
dcmm =
Continuous-time linear grey box model defined by "motor" function:
dx/dt = A x(t) + B u(t) + K e(t)
y(t) = C x(t) + D u(t) + e(t)
A =
x1 x2
x1 0 1
x2 0 -4.006
B =
Voltage
x1 0
x2 1.001
C =
x1 x2
Angle 1 0
AngVel 0 1
D =
Voltage
3-205
3 Linear Model Identification
Angle 0
AngVel 0
K =
Angle AngVel
x1 0 0
x2 0 0
Model parameters:
Par1 = 0.2496
Parameterization:
ODE Function: motor
(parameterizes both continuous- and discrete-time equations)
Disturbance component: parameterized by the ODE function
Initial state: parameterized by the ODE function
Number of free coefficients: 1
Use "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using GREYEST on time domain data "z".
Fit to estimation data: [98.35;84.42]%
FPE: 0.00107, MSE: 0.1193
With this model we can now proceed to test various aspects as before. The syntax of all
the commands is identical to the previous case. For example, we can compare the idgrey
model with the other state-space model:
compare(z,dcmm,dcmodel)
3-206
Building Structured and User-Defined Models Using System Identification Toolbox™
The state-space part of the toolbox also handles multivariate (several outputs) ARX
models. By a multivariate ARX-model we mean the following:
Here A(q) is a ny | ny matrix whose entries are polynomials in the delay operator 1/q.
The k-l element is denoted by:
3-207
3 Linear Model Identification
where:
There is thus a delay of nkkj from input number j to output number k. The most
common way to create those would be to use the ARX-command. The orders are specified
as: nn = [na nb nk] with na being a ny-by-ny matrix whose kj-entry is nakj; nb
and nk are defined similarly.
Let's test some ARX-models on the dc-data. First we could simply build a general second
order model:
dcarx1 = arx(z,'na',[2,2;2,2],'nb',[2;2],'nk',[1;1])
dcarx1 =
Discrete-time ARX model:
Model for output "Angle": A(z)y_1(t) = - A_i(z)y_i(t) + B(z)u(t) + e_1(t)
A(z) = 1 - 0.5545 z^-1 - 0.4454 z^-2
Parameterization:
Polynomial orders: na=[2 2;2 2] nb=[2;2] nk=[1;1]
Number of free coefficients: 12
Use "polydata", "getpvec", "getcov" for parameters and their uncertainties.
3-208
Building Structured and User-Defined Models Using System Identification Toolbox™
Status:
Estimated using ARX on time domain data "z".
Fit to estimation data: [97.87;83.44]% (prediction focus)
FPE: 0.002197, MSE: 0.1398
The result, dcarx1, is stored as an IDPOLY model, and all previous commands apply.
We could for example explicitly list the ARX-polynomials by:
dcarx1.a
ans =
as cell arrays where e.g. the {1,2} element of dcarx1.a is the polynomial A(1,2) described
earlier, relating y2 to y1.
We could also test a structure, where we know that y1 is obtained by filtering y2 through
a first order filter. (The angle is the integral of the angular velocity). We could then also
postulate a first order dynamics from input to output number 2:
na = [1 1; 0 1];
nb = [0 ; 1];
nk = [1 ; 1];
dcarx2 = arx(z,[na nb nk])
dcarx2 =
Discrete-time ARX model:
Model for output "Angle": A(z)y_1(t) = - A_i(z)y_i(t) + B(z)u(t) + e_1(t)
A(z) = 1 - 0.9992 z^-1
B(z) = 0
3-209
3 Linear Model Identification
Parameterization:
Polynomial orders: na=[1 1;0 1] nb=[0;1] nk=[1;1]
Number of free coefficients: 4
Use "polydata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using ARX on time domain data "z".
Fit to estimation data: [97.52;81.46]% (prediction focus)
FPE: 0.003468, MSE: 0.177
3-210
Building Structured and User-Defined Models Using System Identification Toolbox™
Finally, we could compare the bodeplots obtained from the input to output one for the
different models by using bode: First output:
Second output:
bode(dcmodel(2,1),'r',dcmm2(2,1),'b',dcarx2(2,1),'g')
3-211
3 Linear Model Identification
The two first models are more or less in exact agreement. The ARX-models are not
so good, due to the bias caused by the non-white equation error noise. (We had white
measurement noise in the simulations).
Conclusions
3-212
Building Structured and User-Defined Models Using System Identification Toolbox™
Additional Information
3-213
3-214
4
In this section...
“Definition of State-Space Models” on page 4-2
“Continuous-Time Representation” on page 4-2
“Discrete-Time Representation” on page 4-3
“Relationship Between Continuous-Time and Discrete-Time State Matrices” on page
4-3
“State-Space Representation of Transfer Functions” on page 4-4
The state-space model structure is a good choice for quick estimation because it requires
you to specify only one input, the model order, n. The model order is an integer equal to
the dimension of x(t) and relates to, but is not necessarily equal to, the number of delayed
inputs and outputs used in the corresponding linear difference equation.
Continuous-Time Representation
It is often easier to define a parameterized state-space model in continuous time because
physical laws are most often described in terms of differential equations. 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
4-2
What Are State-Space Models?
You can estimate continuous-time state-space model using both time- and frequency-
domain data.
Discrete-Time Representation
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.
Note: K=0 gives the state-space representation of an Output-Error model. For more
information about Output-Error models, see “What Are Polynomial Models?” on page
3-40.
Discrete-time state-space models provide the same type of linear difference relationship
between the inputs and outputs as the “linear ARX model”, but are rearranged such that
there is only one delay in the expressions.
4-3
4 Identifying State-Space Models
A = e FT
T
Ft
B= Úe Gdt
0
C=H
These relationships assume that the input is piece-wise-constant over time intervals
kT £ t < (k + 1) T .
The exact relationship between K and K% is complicated. However, for short sampling
intervals T, the following approximation works well:
T
Ft
K= Úe % t
Kd
0
y = Gu + He
G is a transfer function that takes the input u to the output y. H is a transfer function
that describes the properties of the additive output noise model.
The relationships between the transfer functions and the discrete-time state-space
matrices are given by the following equations:
G ( q) = C( qInx - A) -1 B + D
H ( q) = C(qI nx - A) -1 K + I ny
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. The state-space representation in the continuous-time case is
similar.
4-4
Data Supported by State-Space Models
To estimate state-space models, you must first import your data into the MATLAB
workspace, as described in “Data Preparation”.
4-5
4 Identifying State-Space Models
See Also
• “Estimate State-Space Models with Free-Parameterization” on page 4-27
• “Estimate State-Space Models with Canonical Parameterization” on page 4-28
• “Estimate State-Space Models with Structured Parameterization” on page 4-30
4-6
Estimate State-Space Model With Order Selection
In this section...
“Estimate Model With Selected Order in the App” on page 4-7
“Estimate Model With Selected Order at the Command Line” on page 4-10
“Using the Model Order Selection Window” on page 4-10
To estimate a state-space model, you must provide a value of its order, which represents
the number of states. When you do not know the order, you can search and select an
order using the following procedures.
1 In the System Identification app, select Estimate > State Space Models to open
the State Space Models dialog box.
2 Select the Pick best value in the range option and specify a range in the adjacent
field. The default range is 1:10.
4-7
4 Identifying State-Space Models
This action opens the Model Order Selection window, which displays the relative
measure of how much each state contributes to the input-output behavior of the
model (log of singular values of the covariance matrix). The following figure shows an
example plot.
4-8
Estimate State-Space Model With Order Selection
6 Select the rectangle that represents the cutoff for the states on the left that provide a
significant contribution to the input-output behavior.
In the previous figure, states 1 and 2 provide the most significant contribution. The
contributions to the right of state 2 drop significantly. Click Insert to estimate a
model with this order. Red indicates the recommended choice. For information about
using the Model Order Selection window, see “Using the Model Order Selection
Window” on page 4-10.
This action adds a new model to the Model Board in the System Identification app.
The default name of the model is ss1. You can use this model as an initial guess for
estimating other state-space models, as described in “Estimate State-Space Models
in System Identification App” on page 4-12.
7 Click Close to close the window.
4-9
4 Identifying State-Space Models
Use the following syntax to specify the range of model orders to try for a specific input
delay:
m = n4sid(data,n1:n2);
where data is the estimation data set, n1 and n2 specify the range of orders.
The command opens the Model Order Selection window. For information about using this
plot, see “Using the Model Order Selection Window” on page 4-10.
m1 = ssest(data,nn)
m2 = ssregest(data,nn)
where nn = [n1,n2,...,nN] specifies the vector or range of orders you want to try.
n4sid and ssregest estimate a model whose sample time matches that of data
by default, hence a discrete-time model for time-domain data. ssest estimates a
continuous-time model by default. You can change the default setting by including the Ts
name-value pair input arguments in the estimation command. For example, to estimate a
discrete-time model of optimal order, assuming Data.Ts>0, type:
model = ssest(data,nn,'Ts',data.Ts);
or
model = ssregest(data,nn,'Ts',data.Ts);
To automatically select the best order without opening the Model Order Selection
window, type m = n4sid(data,'best'), m = ssest(data,'best') or m =
ssregest(data,'best').
4-10
Estimate State-Space Model With Order Selection
You use this plot to decide which states provide a significant relative contribution to
the input-output behavior, and which states provide the smallest contribution. 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 shown in red. To learn how to generate this plot, see “Estimate Model With Selected
Order in the App” on page 4-7 or “Estimate Model With Selected Order at the
Command Line” on page 4-10.
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.
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.
4-11
4 Identifying State-Space Models
Prerequisites
• Import data into the System Identification app. See “Represent Data”. For supported
data formats, see “Data Supported by State-Space Models” on page 4-5.
• Perform data preprocessing. To improve the accuracy of your model, you should
detrend your data. See “Ways to Prepare Data for System Identification” on page 2-6.
4-12
Prerequisites
Tip For more information on the options in the dialog box, click Help.
2
Specify a model name by clicking adjacent to Model name. The name of the
model must be unique in the Model Board.
3 Select the Specify value option (if not already selected) and specify the model order
in the edit field. Model order refers to the number of states in the state-space model.
Tip When you do not know the model order, search and select for an order. For more
information, see “Estimate Model With Selected Order in the App” on page 4-7.
4 Select the Continuous-time or Discrete-time option to specify whether to estimate
a continuous- or discrete-time model.
4-13
4 Identifying State-Space Models
For more information about the type of state-space parameterization, see “Supported
State-Space Parameterizations” on page 4-6.
6 Expand the Estimation Options section to select the estimation method, and
configure the cost function.
Select one of the following Estimation Method from the drop-down list and
configure the options. For more information about these methods, see “State-Space
Model Estimation Methods” on page 4-41.
4-14
Subspace (N4SID)
Subspace (N4SID)
a In the N4Weight drop-down list, specify the weighting scheme used for
singular-value decomposition by the N4SID algorithm.
The N4SID algorithm is used both by the subspace and Prediction Error
Minimization (PEM) methods.
b In the N4Horizon field, specify the forward and backward prediction horizons
used by the N4SID algorithm.
The N4SID algorithm is used both by the subspace and PEM methods.
c In the Focus drop-down list, select how to weigh the relative importance of
the fit at different frequencies. For more information about each option, see
“Assigning Estimation Weightings” on page 4-39.
d Select the Allow unstable models check box to specify whether to allow the
estimation process to use parameter values that may lead to unstable models.
4-15
4 Identifying State-Space Models
produces a better fit to the data than other stable models computed during the
estimation process.
e Select the Estimate covariance check box if you want the algorithm to
compute parameter uncertainties.
• In the N4Weight drop-down list, specify the weighting scheme used for singular-
value decomposition by the N4SID algorithm.
The N4SID algorithm is used both by the subspace and Prediction Error
Minimization (PEM) methods.
4-16
Prediction Error Minimization (PEM)
• In the N4Horizon field, specify the forward and backward prediction horizons
used by the N4SID algorithm.
The N4SID algorithm is used both by the subspace and PEM methods.
• In the Focus drop-down list, select how to weigh the relative importance of the fit
at different frequencies. For more information about each option, see “Assigning
Estimation Weightings” on page 4-39.
• Select the Allow unstable models check box to specify whether to allow the
estimation process to use parameter values that may lead to unstable models.
Tip If you get an inaccurate fit, try setting a specific method for handling initial
states rather than choosing it automatically.
• Click Regularization to obtain regularized estimates of model parameters.
Specify the regularization constants in the Regularization Options dialog box. To
learn more, see “Regularized Estimates of Model Parameters”.
• Specify Iteration Options to specify options for controlling the iterations. The
Options for Iterative Minimization dialog box opens.
4-17
4 Identifying State-Space Models
Iteration Options
In the Options for Iterative Minimization dialog box, you can specify the following
iteration options:
4-18
Regularized Reduction
Regularized Reduction
4-19
4 Identifying State-Space Models
Tip If you get an inaccurate fit, try setting a specific method for handling initial
states rather than choosing it automatically.
The estimation process uses parameter values that always lead to a stable model.
7 Click Estimate to estimate the model. A new model gets added to the System
Identification app.
Next Steps
• Validate the model by selecting the appropriate response type in the Model Views
area of the app. For more information about validating models, see “Validating
Models After Estimation” on page 10-2.
• Export the model to the MATLAB workspace for further analysis by dragging it to the
To Workspace rectangle in the app.
4-20
Estimate State-Space Models at the Command Line
In this approach, you specify the model order, and, optionally, additional model structure
attributes that configure the overall structure of the state-space matrices. You call
ssest, ssregest or n4sid with data and model order as primary input arguments, and
use name-value pairs to specify any additional attributes, such as model sample time,
presence of feedthrough, absence of noise component, etc. You do not work directly with
the coefficients of the A, B, C, D, K, and X0 matrices.
Structured Estimation
In this approach, you create and configure an idss model that contains the initial values
for all the system matrices. You use the Structure property of the idss model to
specify all the parameter constraints. For example, you can designate certain coefficients
of system matrices as fixed and impose minimum/maximum bounds on the values of
the others. For quick configuration of the parameterization and whether to estimate
feedthrough and disturbance dynamics, use ssform.
After configuring the idss model with desired constraints, you specify this model as
an input argument to the ssest command. You cannot use n4sid or ssregest for
structured estimation.
4-21
4 Identifying State-Space Models
Note:
• Using the structured estimation approach, you cannot specify relationships among
state-space coefficients. Each coefficient is essentially considered to be independent of
others. For imposing dependencies, or to use more complex forms of parameterization,
use the idgrey model and greyest estimator.
Prerequisites
• Represent input-output data as an iddata object or frequency-response data as an
frd or idfrd object. See “Representing Time- and Frequency-Domain Data Using
iddata Objects” on page 2-50. For supported data formats, see “Data Supported by
State-Space Models” on page 4-5.
• Perform data preprocessing. To improve the accuracy of results when using time-
domain data, you can detrend the data or specify the input/output offset levels as
estimation options. See “Ways to Prepare Data for System Identification” on page 2-6.
• Select a model order. When you do not know the model order, search and select for
an order. For more information, see “Estimate Model With Selected Order at the
Command Line” on page 4-10.
You can estimate continuous-time and discrete-time state-space models using the
iterative estimation command ssest that minimizes the prediction errors to obtain
maximum-likelihood values.
Use the following general syntax to both configure and estimate state-space models:
m = ssest(data,n,opt,Name,Value)
where data is the estimation data, n is the model order. opt contains the options for
configuring the estimation of the state-space models. These options include the handling
of the initial conditions, input and output offsets, estimation focus and search algorithm
options. opt can be followed by name and value pair input arguments that specify
4-22
Prerequisites
optional model structure attributes such as the presence of feedthrough, the canonical
form of the model, and input delay.
As an alternative to ssest, you can use the noniterative subspace estimators n4sid or
ssregest:
m = n4sid(data,n,opt,Name,Value)
m = ssregest(data,n,opt,Name,Value)
Unless you specify the sample time as a name-value pair input argument, n4sid and
ssregest estimate a discrete-time model, while ssest estimates a continuous-time
model.
Note: ssest uses n4sid to initialize the state-space matrices, and takes longer than
n4sid to estimate a model but typically provides better fit to data.
For information about validating your model, see “Validating Models After Estimation”
on page 10-2
4-23
4 Identifying State-Space Models
• By default, ssest estimates a continuous-time model. If you are using data set
with nonzero sample time, data, which includes all time domain data, you can also
estimate a discrete-time model by using:
model = ssest(data,nx,'Ts',data.Ts);
model = n4sid(data,nx,'Ts',0);
or
model = ssregest(data,nx,'Ts',0);
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 'Feedthrough' name and value pair input
argument.
D Matrix
By default, the D matrix is not estimated and its value is fixed to zero, except for static
models.
• Black box estimation: Use the Feedthrough name and value pair input argument
to denote the presence or absence of feedthrough from individual inputs. For example,
in case of a two input model such that there is feedthrough from only the second
input, use model = n4sid(data,n,'Feedthrough',[false true]);.
• Structured estimation: Configure the values of the init_sys.Structure.d,
where init_sys is an idss model that represents the desired model structure. To
force no feedthrough for the i-th input, set:
4-24
Prerequisites
init_sys.Structure.d.Value(:,i) = 0;
init_sys.Structure.d.Free = true;
init_sys.Structure.d.Free(:,i) = false;
The first line specifies the value of the i-th column of D as zero. The next line specifies
all the elements of D as free, estimable parameters. The last line specifies that the i-
th column of the D matrix is fixed for estimation.
K Matrix
K represents the noise matrix of the model, such that the noise component of the model
is:.
x& = Ax + Ke
yn = Cx + e
For frequency-domain data, no noise model is estimated and K is set to 0. For time-
domain data, K is estimated by default in the black box estimation setup. yn is the
contribution of the disturbances to the model output.
• Black box estimation: Use the DisturbanceModel name and value pair input
argument to indicate if the disturbance component is fixed to zero (specify Value
= ‘none’) or estimated as a free parameter (specify Value = ‘estimate’). For
example, use model = n4sid(data,n,'DisturbanceModel','none').
• Structured estimation: Configure the value of the init_sys.Structure.k
parameter, where init_sys is an idss model that represents the desired model
structure. You can fix some K matrix coefficients to known values and prescribe
minimum/maximum bounds for free coefficients. For example, to estimate only the
first column of the K matrix for a two output model:
kpar = init_sys.Structure.k;
kpar.Free(:,1) = true;
kpar.Free(:,2) = false;
kpar.Value(:,2) = 0; % second column value is fixed to zero
init_sys.Structure.k = kpar;
4-25
4 Identifying State-Space Models
When not sure how to easily fix or free all coefficients of K, initially you can omit
estimating the noise parameters in K to focus on achieving a reasonable model for the
system dynamics. After estimating the dynamic model, you can use ssest to refine the
model while configuring the K parameters to be free. For example:
init_sys = ssest(data, n,'DisturbanceModel','none');
init_sys.Structure.k.Free = true;
sys = ssest(data, init_sys);
To set K to zero in an existing model, you can set its Value to 0 and Free flag to false:
m.Structure.k.Value = 0;
m.Structure.k.Free = false;
X0 Matrices
The initial state vector X0 is obtained as the by-product of model estimation. The
n4sid, ssest and ssregest commands return the value of X0 as their second output
arguments. You can choose how to handle initial conditions during model estimation
by using the InitialState estimation option. Use n4sidOptions (for n4sid),
ssestOptions (for ssest) or ssregestOptions (for ssregest) to create the
estimation option set. For example, in order to hold the initial states to zero during
estimation using n4sid:
opt = n4sidOptions;
opt.InitialState = 'zero';
[m,X0] = n4sid(data,n,opt);
When you estimate models using multiexperiment data, the X0 matrix contains as many
columns as data experiments.
For a complete list of values for the InitialStates option, see “Specifying Initial
States for Iterative Estimation Algorithms” on page 4-40.
4-26
Estimate State-Space Models with Free-Parameterization
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 = ssest(data)
or
m = ssregest(data)
m = ssest(data,n)
or
m = ssregest(dat,n)
The iterative algorithm ssest is initialized by the subspace method n4sid. You can use
n4sid directly, as an alternative to ssest:
m = n4sid(data)
which automatically estimates a discrete-time model of the best order in the 1:10 range.
4-27
4 Identifying State-Space Models
Note: The modal form has a certain symmetry in its block diagonal elements. If you
update the parameters of a model of this form (as a structured estimation using
ssest), the symmetry is not preserved, even though the updated model is still block-
diagonal.
• Observability canonical form: The free parameters appear only in select rows of
the A matrix and in the B and K matrices.
For more information about the distribution of free parameters in the observability
canonical form, see the Appendix 4A, pp 132-134, on identifiability of black-box
multivariable model structures in System Identification: Theory for the User, Second
Edition, by Lennart Ljung, Prentice Hall PTR, 1999 (equation 4A.16).
4-28
Estimate State-Space Models with Canonical Parameterization
For example, to specify an observability canonical form, use the 'Form' name and value
pair input argument, as follows:
m = ssest(data,n,'Form','canonical')
If you have continuous-time frequency-domain data, you can only estimate a continuous-
time model.
4-29
4 Identifying State-Space Models
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.
Note: To estimate structured state-space models in the System Identification app, define
the corresponding model structures at the command line and import them into the
System Identification app.
4-30
More about Structure
A = [0 1; 0 -1];
B = [0; 0.28];
C = eye(2);
D = zeros(2,1);
m = idss(A,B,C,D,K,'Ts',T)
Each property sys.a, sys.b, sys.c, and sys.d is an alias to the corresponding
Value entry in the Structure property of sys. For example, sys.a is an alias to
the value of the property sys.Structure.a.Value
• Minimum — Minimum value that the parameter can assume during estimation.
For example, sys.Structure.k.Minimum = 0 constrains all entries in the K
matrix to be greater than or equal to zero.
• Maximum — Maximum value that the parameter can assume during estimation.
• Free — Boolean specifying whether the parameter is a free estimation
variable. If you want to fix the value of a parameter during estimation, set
the corresponding Free = false. For example, if A is a 3-by-3 matrix,
sys.Structure.a.Free = eyes(3) fixes all of the off-diagonal entries in A, to
the values specified in sys.Structure.a.Value. In this case, only the diagonal
entries in A are estimable.
• Scale — Scale of the parameter’s value. Scale is not used in estimation.
4-31
4 Identifying State-Space Models
• Info — Structure array for storing parameter units and labels. The structure
has Label and Unit fields.
Use these fields for your convenience, to store strings that describe parameter
units and labels.
m.Structure.a.Value(1,2) = 0;
m.Structure.a.Value(2,1) = 0;
m.Structure.a.Free(1,2) = false;
m.Structure.a.Free(2,1) = false;
Use physical insight, whenever possible, to initialize the parameters for the iterative
search algorithm. Because it is possible that the numerical minimization gets stuck
in a local minimum, try several different initialization values for the parameters.
For random initialization, use init. When the model structure contains parameters
with different orders of magnitude, try to scale the variables so that the parameters
are all roughly the same magnitude.
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
MATLAB file.
4-32
More about Structure
modeling" terminology is used only when referring to idgrey and idnlgrey models.
In these models, you can specify complete linear or nonlinear models with complicated
relationships between the unknown parameters.
Suppose that the nominal values of the unknown parameters ( ) are -1, 2,
3, 4,and 5, respectively.
Construct the parameter matrices and initialize the parameter values using the nominal
parameter values.
A = [1,-1;0,1];
B = [2;3];
C = [1,0];
D = 0;
K = [4;5];
4-33
4 Identifying State-Space Models
m = idss(A,B,C,D,K);
Specify the parameter values in the structure matrices that you do not want to estimate.
S = m.Structure;
S.a.Free(1,1) = false;
S.a.Free(2,:) = false;
S.c.Free = false;
m.Structure = S;
D is initialized, by default, as a fixed value, and K and B are initialized as free values.
Suppose you want to fix the initial states to known zero values. To enforce this, configure
the InitialState estimation option.
opt = ssestOptions;
opt.InitialState = 'zero';
where z1 is name of the iddata object. The data can be time-domain or frequency-
domain data. The iterative search starts with the nominal values in the A, B, C, D, and K
matrices.
4-34
More about Structure
The motor is at rest at t=0 , but its angular position is unknown. Suppose that the
approximate nominal values of the unknown parameters are and .
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.
Construct the parameter matrices and initialize the parameter values using the nominal
parameter values.
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,'Ts',0);
Specify the parameter values in the structure matrices that you do not want to estimate.
S = m.Structure;
S.a.Free(1,:) = false;
S.a.Free(2,1) = false;
4-35
4 Identifying State-Space Models
S.b.Free(1) = false;
S.c.Free = false;
S.d.Free = false;
S.k.Free = false;
m.Structure = S;
m.NoiseVariance = [0.01 0; 0 0.1];
The initial state is partially unknown. Use the InitialState option of the
ssestOptions option set to configure the estimation behavior of X0.
opt = ssestOptions;
opt.InitialState = idpar(x0);
opt.InitialState.Free(2) = false;
The iterative search for a minimum is initialized by the parameters in the nominal model
m . The continuous-time model is sampled using the same sampling interval as the data
during estimation.
Simulate this system using the sampling interval T=0.1 for input u and the noise
realization e.
e = randn(300,2);
u1 = idinput(300);
simdat = iddata([],u1,'Ts',0.1);
simopt = simOptions('AddNoise', true, 'NoiseData', e);
y1 = sim(m,simdat,simopt);
The continuous system is sampled using Ts=0.1 for simulation purposes. The noise
sequence is scaled according to the matrix m.NoiseVariance .
If you discover that the motor was not initially at rest, you can estimate by setting
the second element of the InitialState parameter to be free.
opt.InitialState.Free(2) = true;
m_new = ssest(z, m, opt);
4-36
Estimate the State-Space Equivalent of ARMAX and OE Models
You can estimate the equivalent of multiple-output ARMAX and Output-Error (OE)
models using state-space model structures:
• For an “ARMAX” model, specify to estimate the K matrix for the state-space model
• For an “OE” model, set K = 0
Convert the resulting model into idpoly models to see them in the commonly defined
ARMAX or Output-Error forms.
mss_noK is a second order state-space model with no disturbance model used during
estimation. mss is also a second order state-space model, but with an estimated noise
component. Both models use the measured data set z1 for estimation.
Converting to polynomial models results in the parameter covariance information for mOE
and mARMAX to be lost.
Reestimate mOE and mARMAX for the parameters of the polynomial model using a zero
iteration update.
4-37
4 Identifying State-Space Models
opt = polyestOptions;
opt.SearchOption.MaxIter = 0;
mOE = polyest(z1,mOE);
mARMAX = polyest(z1,mARMAX);
The options object, opt, specifies a zero iteration update for mOE and mARMAX.
Consequently, the model parameters remain unchanged and only their covariance
information is updated.
Alternatively, you can use translatecov to convert the estimated models into
polynomial form.
fcn = @(x)idpoly(x);
mOE = translatecov(fcn, mss_noK);
mARMAX = translatecov(fcn, mss);
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 5-64.
For more information about ARMAX and OE models, see “Identifying Input-Output
Polynomial Models” on page 3-40.
4-38
Assigning Estimation Weightings
In the System Identification app. 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 10-88.
• 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-128 or
“Defining a Custom Filter” on page 2-129. This prefiltering applies only for estimating
the dynamics from input to output. The disturbance model is determined from the
estimation data.
At the command line. Specify the focus as an estimation option using the same options
as in the app. For example, use this command to emphasize the fit between the 5 and 8
rad/s:
opt = ssestOptions;
opt.Focus = [5 8];
model = ssest(data,4,opt);
For more information on the 'Focus' option, see the reference page for ssestOptions
and ssregestOptions.
4-39
4 Identifying State-Space Models
In the System Identification app. Set Initial state to one of the following options:
At the command line. Specify the method for handling initial states using the
InitialState estimation option. For example, to estimate a fourth-order state-space
model and set the initial states to be estimated from the data:
opt = ssestOptions('InitialState','estimate');
m = ssest(data, 4, opt)
For a complete list of values for the InitialState model property, see the
ssestOptions, n4sidOptions and ssregestOptions reference pages.
Note: For the n4sid algorithm, 'auto' and 'backcast' are equivalent to
'estimate'.
4-40
State-Space Model Estimation Methods
• N4SID — This is a noniterative, subspace method. The method works on both time-
domain and frequency-domain data and is typically faster than the SSEST algorithm.
You can choose the subspace algorithms such as CVA, SSARX, or MOESP using the
n4Weight option. You can also use this method to get an initial model (see n4sid),
and then refine the initial estimate using the iterative prediction-error method
ssest.
With all the estimation methods, you have the option of specifying how to handle initial
state, delays, feedthrough behavior and disturbance component of the model.
References
[1] van Overschee, P., and B. De Moor. Subspace Identification of Linear Systems: Theory,
Implementation, Applications. Springer Publishing: 1996.
[2] Ljung, L. System Identification: Theory For the User, Second Edition, Upper Saddle
River, N.J: Prentice Hall, 1999.
[3] T. Chen, H. Ohlsson, and L. Ljung. “On the Estimation of Transfer Functions,
Regularizations and Gaussian Processes - Revisited”, Automatica, Volume 48,
August 2012.
4-41
4-42
5
Here are some scenarios when you might need the additional flexibility of nonlinear
models:
You might need nonlinear models when a linear model provides a poor fit to the
measured output signals and cannot be improved by changing the model structure or
5-2
About Nonlinear Model Identification
order. Nonlinear models have more flexibility in capturing complex phenomena than the
linear models of similar orders.
From physical insight or data analysis, you might know that a system is weakly
nonlinear. In such cases, you can estimate a linear model and then use this model as an
initial model for nonlinear estimation. Nonlinear estimation can improve the fit by using
nonlinear components of the model structure to capture the dynamics not explained
by the linear model. For more information, see “Using Linear Model for Nonlinear
ARX Estimation” on page 5-28 and “Using Linear Model for Hammerstein-Wiener
Estimation” on page 5-64.
You might have physical insight that your system is nonlinear. Certain phenomena are
inherently nonlinear in nature, including dry friction in mechanical systems, actuator
power saturation, and sensor nonlinearities in electro-mechanical systems. You can
try modeling such systems using the Hammerstein-Wiener model structure, which lets
you interconnect linear models with static nonlinearities. For more information, see
“Identifying Hammerstein-Wiener Models” on page 5-48.
Nonlinear models might be necessary to represent systems that operate over a range of
operating points. In some cases, you might fit several linear models, where each model
is accurate at specific operating conditions. You can also try using the nonlinear ARX
model structure with tree partitions to model such systems. For more information, see
“Identifying Nonlinear ARX Models” on page 5-7.
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
“Grey-Box Model Estimation”.
Before fitting a nonlinear model, try transforming your input and output variables
such that the relationship between the transformed variables becomes 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.
5-3
5 Nonlinear Black-Box Model Identification
You might have multiple data sets that capture the linear and nonlinear dynamics
separately. For example, one data set with low amplitude input (excites the linear
dynamics only) and another data set with high amplitude input (excites the nonlinear
dynamics). In such cases, first estimate a linear model using the first data set. Next,
use the model as an initial model to estimate a nonlinear model using the second data
set. For more information, see “Using Linear Model for Nonlinear ARX Estimation” on
page 5-28 and “Using Linear Model for Hammerstein-Wiener Estimation” on page
5-64.
Nonlinear ARX models extend the linear ARX models to the nonlinear case and have this
structure:
y(t) = f(y(t - 1), ..., y(t - na), u(t - nk), ..., u(t -nk -nb + 1))
where the function f depends on a finite number of previous inputs u and outputs y. na
is the number of past output terms and nb is the number of past input terms used to
predict the current output. nk is the delay from the input to the output, specified as the
number of samples.
Typically, you use nonlinear ARX models as black-box structures. The nonlinear function
of the nonlinear ARX model is a flexible nonlinearity estimator with parameters that
need not have physical significance.
System Identification Toolbox software uses idnlarx objects to represent nonlinear ARX
models. For more information about estimation, see “Nonlinear ARX Models”.
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.
5-4
About Nonlinear Model Identification
You can use the Hammerstein-Wiener structure to capture physical nonlinear effects in
sensors and actuators that affect the input and output of a linear system, such as dead
zones and saturation. Alternatively, use Hammerstein-Wiener structures as black box
structures that do not represent physical insight into system processes.
x& ( t ) = F ( x ( t ) , u ( t ) )
y ( t ) = H ( x ( t) ,u ( t ) )
For more information about estimating nonlinear state-space models, see “Grey-Box
Model Estimation”.
5-5
5 Nonlinear Black-Box Model 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 app. Import data into the app, as described in
“Represent Data”.
• 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 sample
time (see “Ways to Prepare Data for System Identification” on page 2-6).
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.
5-6
Identifying Nonlinear ARX Models
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:
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 thus predicts the current output yp as
a weighted sum of its regressors.
5-7
5 Nonlinear Black-Box Model Identification
• Instead of the weighted sum that represents a linear mapping, the nonlinear ARX
model has a more flexible nonlinear mapping function:
where f is a nonlinear function. Inputs to f are model regressors. When you specify
the nonlinear ARX model structure, you can choose one of several available nonlinear
mapping functions in this toolbox (see “Nonlinearity Estimators for Nonlinear ARX
Models” on page 5-9).
• Nonlinear ARX regressors can be both delayed input-output variables and more
complex, nonlinear expressions of delayed input and output variables. Examples of
such nonlinear regressors are y(t-1)2, u(t-1)*y(t-2), tan(u(t-1)), and u(t-1)*y(t-3).
Nonlinearity Estimator
u Nonlinear
Regressors Function y
u(t),u(t-1),y(t-1), ...
Linear
Function
1 Computes regressors from the current and past input values and past output data.
In the simplest case, regressors are delayed inputs and outputs, such as u(t-1) and
y(t-3)—called standard regressors. You can also specify custom regressors, which
are nonlinear functions of delayed inputs and outputs. For example, tan(u(t-1)) or
u(t-1)*y(t-3).
5-8
Identifying Nonlinear ARX Models
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) )
x is a vector of the regressors. LT ( x) + d is the output of the linear function block and is
affine when d≠0. d is a scalar offset. g ( Q( x - r) ) represents the output of the nonlinear
function block. r is the mean of the regressors x. Q is a projection matrix that makes
the calculations well conditioned. The exact form of F(x) depends on your choice of the
nonlinearity estimator.
Estimating a nonlinear ARX model computes the model parameter values, such as L, r,
d, Q, and other parameters specifying g. Resulting models are idnlarx objects that store
all model data, including model regressors and parameters of the nonlinearity estimator.
See the idnlarx reference page for more information.
Each nonlinearity estimator corresponds to an object class in this toolbox. When you
estimate nonlinear ARX models in the app, System Identification Toolbox creates and
configures objects based on these classes. You can also create and configure nonlinearity
estimators at the command line.
5-9
5 Nonlinear Black-Box Model Identification
number of nonlinear units n for estimation. For a detailed description of each estimator,
see the references page of the corresponding nonlinearity class.
-1
where k ( s) = e s + 1
( ) is the sigmoid
5-10
Identifying Nonlinear ARX Models
You can adjust various elements of the nonlinear ARX model structure and fit different
models to your data.
• Specifying model order and delay, which creates the set of standard regressors.
For a definition, see “Nonlinear ARX Order and Delay” on page 5-13.
• 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.
5-11
5 Nonlinear Black-Box Model Identification
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 5-28.
• Specifying and configuring the nonlinear function, including the number of units.
• Excluding the nonlinear function from the nonlinear estimator such that
F(x)= LT ( x) + d .
• Excluding the linear function from the nonlinear estimator such that
F(x)= g ( Q( x - r) ) .
Note: You cannot exclude the linear function from tree partitions and neural
networks.
See these topics for detailed steps to change the model structure:
• “How to Estimate Nonlinear ARX Models in the System Identification App” on page
5-14
• “How to Estimate Nonlinear ARX Models at the Command Line” on page 5-17
Estimate a nonlinear ARX model with default configuration by one of the following:
• 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:
• The nonlinearity estimator is a wavelet network (see the wavenet reference page).
This nonlinearity often provides satisfactory results and uses a fast estimation
method.
5-12
Identifying Nonlinear ARX Models
• All of the standard regressors are inputs to the linear and nonlinear functions of the
wavelet network.
The order and delay of nonlinear ARX models are positive integers:
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-46. 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:
na=2, nb=3, and nk=5
the toolbox computes standard regressors y(t-2), y(t-1), u(t-5), u(t-6), and u(t-7).
The estimation algorithm depends on your choice of nonlinearity estimator and other
properties of the idnlarx class. You can set algorithm properties both in the app and at
the command line.
Focus property of idnlarx class
5-13
5 Nonlinear Black-Box Model Identification
If you want a model that is optimized for reproducing simulation behavior, try setting
the Focus value to Simulation. In this case, you cannot use treepartition and
neuralnet because these nonlinearity estimators are not differentiable. Minimization
of simulation error requires differentiable nonlinear functions. Simulation error
minimization takes more time than one-step-ahead prediction error minimization.
Common algorithm properties of idnlarx class
Prerequisites
• Learn about the nonlinear ARX model structure (see “Structure of Nonlinear ARX
Models” on page 5-8).
• Import data into the System Identification app (see “Preparing Data for Nonlinear
Identification” on page 5-6).
• (Optional) Choose a nonlinearity estimator in “Nonlinearity Estimators for Nonlinear
ARX Models” on page 5-9.
1 In the System Identification app, select Estimate > Nonlinear models to open the
Nonlinear Models dialog box.
2 In the Configure tab, verify that Nonlinear ARX is selected in the Model type
list.
3 (Optional) Edit the Model name by clicking . The name of the model should be
unique to all nonlinear ARX models in the System Identification app.
4 (Optional) If you want to refine the parameters of a previously estimated model or
configure the model structure to match that of an existing model:
5-14
Prerequisites
The model must be in the Model Board of the System Identification app and the
input/output dimensions of this initial model must match that of the estimation
data, selected as Working Data in the app.
c Click OK.
The model structure as well as the parameter values are updated to match that
of the selected model.
Clicking Estimate causes the estimation to use the parameters of the initial model
as the starting point.
Note: When you select an initial model, you can optionally update the estimation
algorithm settings to match those used for the initial model by selecting the Inherit
the model’s algorithm properties option.
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 app help.
5-15
5 Nonlinear Black-Box Model Identification
If you get a poor fit, try changing the model structure or algorithm configuration in
step 5.
You can export the model to the MATLAB workspace by dragging it to To Workspace in
the System Identification app.
5-16
Prerequisites
Prerequisites
• Learn about the nonlinear ARX model structure in “Structure of Nonlinear ARX
Models” on page 5-8.
• Prepare your data, as described in “Preparing Data for Nonlinear Identification” on
page 5-6.
• (Optional) Estimate model orders and delays the same way you would for linear ARX
models. See “Preliminary Step – Estimating Model Orders and Input Delays” on page
3-46.
• (Optional) Choose a nonlinearity estimator in “Nonlinearity Estimators for Nonlinear
ARX Models” on page 5-9.
• (Optional) Estimate or construct an linear ARX model for initialization of nonlinear
ARX model. See “Using Linear Model for Nonlinear ARX Estimation” on page
5-28.
Basic Estimation
Start with the simplest estimation using m = nlarx(data,[na nb nk]). For example:
load iddata1;
% na = nb = 2 and nk = 1
m = nlarx(z1,[2 2 1])
m =
Nonlinear ARX model with 1 output and 1 input
Inputs: u1
Outputs: y1
Standard regressors corresponding to the orders
na = 2, nb = 2, nk = 1
5-17
5 Nonlinear Black-Box Model Identification
No custom regressor
Nonlinear regressors:
y1(t-1)
y1(t-2)
u1(t-1)
u1(t-2)
Nonlinearity: wavenet with 1 unit
Loss function: 1.8973
Sample time: 0.1
Estimated model (NLARX)
The second input argument [na nb nk] specify the model orders and delays. 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.
M = nlarx(z1,[2 2 1],'sigmoid');
Set the Focus property of the idnlarx object estimation to simulation error
minimization.
M = nlarx(z1,[2 2 1],'sigmoid','Focus','simulation');
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
Explore including custom regressors in the nonlinear ARX model structure. Custom
regressors are in addition to the standard model regressors (see “Nonlinear ARX Order
and Delay” on page 5-13).
5-18
Configure model 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)
Regressors:
y1(t-1)
y1(t-2)
u1(t-1)
u1(t-2)
4x1 array of Custom Regressors with fields: Function, Arguments, Delays, Vectorized.
m = addreg(m,reg);
getreg(m)
Regressors:
y1(t-1)
y1(t-2)
u1(t-1)
u1(t-2)
y1(t-1).^2
y1(t-2).^2
u1(t-1).^2
u1(t-2).^2
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
5-19
5 Nonlinear Black-Box Model Identification
Regressors:
y1(t-1)
y1(t-2)
u1(t-1)
u1(t-2)
y1(t-1)^2
y1(t-2)*u1(t-3)
m = addreg(m,reg);
getreg(m) % polynomial regressors
Regressors:
y1(t-1)
y1(t-2)
u1(t-1)
u1(t-2)
y1(t-1)^2
y1(t-2)*u1(t-3)
y1(t-1).^2
y1(t-2).^2
u1(t-1).^2
u1(t-2).^2
CReg1 = m.CustomReg(1).Function;
m.CustomReg(1).Display
ans =
y1(t-1)^2
You can exclude all standard regressors and use only custom regressors in the model
structure by setting na=nb=nk=0:
5-20
Linear and nonlinear regressors.
m = nlarx(z1,[0 0 0],'linear','CustomReg',{'y1(t-1)^2','y1(t-2)*u1(t-3)'});
In advanced applications, you can specify advanced estimation options for nonlinearity
estimators. For example, wavenet and treepartition classes provide the Options
property for setting such estimation options.
Regressors:
y1(t-1)
y1(t-2)
u1(t-1)
u1(t-2)
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. Alternatively, include only input regressors in the nonlinear function
block using:
m = nlarx(z1,[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(z1,[4 4 1],sigmoidnet,'nlreg','search');
This search typically takes a long time. You can display the search progress using m =
nlarx(z1,[4 4 1],sigmoidnet,'nlreg','search','Display','on') . After
5-21
5 Nonlinear Black-Box Model Identification
m.NonlinearRegressors
ans =
3 5 7 8
• A string of the nonlinearity name, which uses the default nonlinearity configuration.
m = nlarx(z1, [2 2 1],'sigmoidnet');
or
• Nonlinearity object.
m = nlarx(z1,[2 2 1],wavenet('num',5));
This estimation uses a nonlinear ARX model with a wavelet nonlinearity that has
5 units. To construct the nonlinearity object before providing it as an input to the
nonlinearity estimator:
w = wavenet('num', 5);
m = nlarx(z1,[2 2 1],w);
% or
w = wavenet;
w.NumberOfUnits = 5;
m = nlarx(z1,[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:
load iddata1 z1
load iddata2 z2
5-22
Include only nonlinear function in nonlinearity estimator.
If you want the same nonlinearity for all output channels, specify one nonlinearity.
M = nlarx(data,[[1 1;1 1] [2 1;1 1] [2 1;1 1]],sigmoidnet);
where NNet is the neural network object you create using the Neural Network Toolbox
software. See the neuralnet reference page.
5-23
5 Nonlinear Black-Box Model Identification
Nonlinearity Estimator
u
Regressors Nonlinear y
u(t),u(t-1),y(t-1), ... Function
For example:
SNL = sigmoidnet('LinearTerm','off');
m = nlarx(z1,[2 2 1],SNL);
Note: You cannot exclude the linear function from tree partition and neural network
nonlinearity estimators.
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:
5-24
Iteratively refine the model.
m = nlarx(z1,[2 2 1],'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 a system, use:
M = nlarx(z1,[0 0 0],'linear','CustomReg',{'y1(t-1)^2','y1(t-2)*u1(t-3)'});
M has no standard regressors and the nonlinearity in the model is described only by the
custom regressors.
m = nlarx(z1,[2 2 1],'sigmoidnet');
m2 = pem(z1,m);
m1 = nlarx(z1, [2 2 1],'sigmoidnet');
m2 = nlarx(z1,m1); % can repeatedly run this command
5-25
5 Nonlinear Black-Box Model Identification
You can also try perturbing the parameters of the last model using init (called
randomization) and refining the model using pem:
You can display the progress of the iterative search in the MATLAB Command Window
using the Display property of the idnlarx class:
M2= pem(z1,M1p,'Display','On');
Nonlinear black-box system identification usually requires more data than linear model
identification to gain enough information about the system.
This example shows how to use nlarx to estimate a nonlinear ARX model for measured
input/output data.
load twotankdata
5-26
What if you cannot get a satisfactory model?
z = iddata(y, u, 0.2);
ze = z(1:1000); zv = z(1001:3000);
Estimate several models using different model orders, delays, and nonlinearity settings.
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]);
An alternative way to perform the estimation is to configure the model structure first,
and then to estimate this model.
Compare the resulting models by plotting the model outputs with the measured output.
compare(zv, m1,m2,m3,m4,m5)
5-27
5 Nonlinear Black-Box Model Identification
You can use an ARX structure polynomial model (idpoly with only A and B as active
polynomials) for nonlinear ARX estimation.
5-28
What if you cannot get a satisfactory model?
Tip To learn more about when to use linear models, see “When to Fit Nonlinear Models”
on page 5-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.
During estimation, the estimation algorithm uses these values to further adjust the
nonlinear model to the data. The initialization always provides a better fit to the
estimation data than the linear ARX model.
m = nlarx(data,LinARXModel)
By default, the nonlinearity estimator is the wavelet network (wavenet object). This
network takes all standard regressors computed using orders and delay of LinARXModel
as inputs to its linear and nonlinear functions. The software computes the LinearCoef
parameter of the wavenet object using the A and B polynomials of the linear ARX model.
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.
5-29
5 Nonlinear Black-Box Model Identification
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')
After each estimation, validate the model by comparing the simulated response to the
data. To improve the fit of the nonlinear ARX model, adjust various elements of the
nonlinear ARX structure. For more information, see “Ways to Configure Nonlinear ARX
Estimation” on page 5-11.
This example shows how to estimate nonlinear ARX models by using linear ARX models.
load throttledata.mat
This command loads the data object ThrottleData into the 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)
5-30
What if you cannot get a satisfactory model?
In the normal operating range of 15-90 degrees, the input and output variables have a
linear relationship. You use a linear model of low order to model this relationship.
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.
Estimate an ARX model to model the linear behavior of this single-input single-output
system in the normal operating range.
5-31
5 Nonlinear Black-Box Model Identification
The linear model captures the rising and settling behavior in the linear operating range
but does not account for output saturation at 90 degrees.
5-32
What if you cannot get a satisfactory model?
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.
The model captures the nonlinear effects (output saturation) and improves the overall fit
to data.
5-33
5 Nonlinear Black-Box Model Identification
• “How to Plot Nonlinear ARX Plots Using the App” on page 5-34
• “How to Validate Nonlinear ARX Models at the Command Line” on page 5-35
• “Configuring the Nonlinear ARX Plot” on page 5-38
• “Axis Limits, Legend, and 3-D Rotation” on page 5-39
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 wavenet network and treepartition, 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.
• The regressors to use on the plot axes, and specify the center points for the other
regressors in the configuration panel. For multi-output models, each output is plotted
separately.
• The output to view from the drop-down list located at the top of the plot.
You can plot linear and nonlinear blocks of nonlinear ARX models.
To create a nonlinear ARX plot in the System Identification app, select the Nonlinear
ARX check box in the Model Views area. For general information about creating and
working with plots, see “Working with Plots” on page 14-11.
5-34
Compare Model Output to Measured Output
Note: The Nonlinear ARX check box is unavailable if you do not have a nonlinear ARX
model in the Model Board.
You can use the following approaches to validate nonlinear ARX models at the command
line:
For example, compare linear and nonlinear ARX models of same order:
5-35
5 Nonlinear Black-Box Model Identification
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
5-36
Simulate and Predict Model Response
Analyze Residuals
Residuals are differences between the one-step-ahead predicted output from the model
and the measured output from the validation data set. Thus, residuals represent the
portion of the validation data output not explained by the model. Use resid to compute
and plot the residuals.
Plot Nonlinearity
Use plot to view the shape of the nonlinearity. For example:
plot(M)
where M is the nonlinear ARX (idnlarx) model. The plot command opens the Nonlinear
ARX Model Plot window.
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:
5-37
5 Nonlinear Black-Box Model Identification
conditions. M is the estimated idnlarx model. For example, check the WhyStop field
of the EstimationInfo property, which describes why the estimation stopped—the
algorithm might have reached the maximum number of iterations or the required
tolerance value. For more information about iterative search, see “Estimation Algorithm
for Nonlinear ARX Models” on page 5-13.
To include or exclude a model on the plot, click the corresponding model icon in the
System Identification app. Active models display a thick line inside the Model Board
icon.
1 If your model contains multiple outputs, select the output channel in the Select
nonlinearity at output drop-down 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.
3 Select Regressor 1 from the list of available regressors. In the Range field, enter
the range of values to include on the plot for this regressor. The regressor values are
plotted on the Reg1 axis.
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 Click Apply to update the plot.
1 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.
5-38
Simulation and Prediction
For example, if the number of samples is 20, each regressor variable contains
20 points in its specified range. For a 3-D plots, this results in evaluating the
nonlinearity at 20 x 20 = 400 points.
The following table summarizes the commands to modify the appearance of the
Nonlinear ARX plot.
Simulation and prediction commands provide default handling of the model's initial
conditions, or initial state values. See the idnlarx reference page for a definition of the
nonlinear ARX model states.
This toolbox provides several options to facilitate how you specify initial states. For
example, you can use findstates(idnlarx) and data2state(idnlarx) to compute
5-39
5 Nonlinear Black-Box Model Identification
To learn more about how sim and predict compute the model output, see “How the
Software Computes Nonlinear ARX Model Output” on page 5-40.
Linearization
Compute linear approximation of nonlinear ARX models using linearize or linapp.
You can compute the operating point for linearization using findop(idnlarx).
After computing a linear approximation of a nonlinear model, you can perform linear
analysis and control design on your model using Control System Toolbox commands. For
more information, see “Using Identified Models for Control Design Applications” and
“Create and Plot Identified Models Using Control System Toolbox Software”.
The IDNLARX Model block supports code generation with Simulink Coder™ software,
using both generic and embedded targets. Code generation does not work when the model
contains customnet or neuralnet nonlinearity estimator, or custom regressors.
5-40
Estimating and Exploring a Nonlinear ARX Model
how the software evaluates the output of nonlinearity estimators and uses this output to
compute the model response.
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:
F = get(m,'Nonlinearity') % equivalent to F = m.nl
x = getreg(m,'all',data) % computes regressors
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])
This example shows how the software computes the simulated and predicted output
of the model as a result of evaluating the output of its nonlinearity estimator for given
regressor values.
M =
Nonlinear ARX model with 1 output and 1 input
5-41
5 Nonlinear Black-Box Model Identification
Inputs: u1
Outputs: y1
Standard regressors corresponding to the orders
na = 1, nb = 1, nk = 0
No custom regressor
Nonlinear regressors:
y1(t-1)
u1(t)
Nonlinearity: sigmoidnet with 10 units
Loss function: 4.5903e-05
Sample time: 0.2
Estimated model (NLARX)
This command provides information about input and output variables, regressors, and
nonlinearity estimator.
ans =
sigmoidnet
Sigmoid Network:
NumberOfUnits: 10
LinearTerm: 'on'
Parameters: [1x1 struct]
NL.Parameters;
Prediction of Output
The model output is:
5-42
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))
where yp(t) is the predicted value of the response at time t. y1_meas(t-1) and u1_meas(t)
are the measured output and input values at times t-1 and t, respectively.
To compute the predicted value of the response using initial conditions and current input:
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)).
5-43
5 Nonlinear Black-Box Model Identification
Perform one-step-ahead prediction at all time values for which data is available.
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.
These steps are equivalent to the predicted response computed in a single step using
predict:
yp = predict(M,estData,1,'InitialState',x0);
Simulation of Output
The model output is:
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.
• Computing regressor values from input-output data using simulated output values.
• Evaluating the nonlinearity for given regressor values.
To compute the simulated value of the response using initial conditions and current
input:
5-44
Simulation of Output
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)).
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
5-45
5 Nonlinear Black-Box Model Identification
the output samples required for forming the regressor vector are available iteratively,
one sample at a time.
These steps are equivalent to the simulated response computed in a single step using
sim(idnlarx):
ys = sim(M,estData,x0);
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. , , and 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)]:
5-46
Low-Level Nonlinearity Evaluation
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; ...]
y = yLinear + yNonlinear;
y is equal to evaluate(NL,x).
5-47
5 Nonlinear Black-Box Model Identification
You can use the Hammerstein-Wiener model as a black-box model structure because
it provides a flexible parameterization for nonlinear models. For example, you might
estimate a linear model and try to improve its fidelity by adding an input or output
nonlinearity to this model.
5-48
Identifying Hammerstein-Wiener Models
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).
For ny outputs and nu inputs, the linear block is a transfer function matrix containing
entries:
B j ,i (q)
Fj ,i ( q)
w(t) and x(t) are internal variables that define the input and output of the linear block,
respectively.
Because f acts on the input port of the linear block, this function is called the input
nonlinearity. Similarly, because h acts on the output port of the linear block, this function
is called the output nonlinearity. If system contains several inputs and outputs, you must
define the functions f and h for each input and output signal.
5-49
5 Nonlinear Black-Box Model Identification
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.
The input nonlinearity is a static (memoryless) function, where the value of the
output a given time t depends only on the input value at time t.
You can configure the input nonlinearity as a sigmoid network, wavelet network,
saturation, dead zone, piecewise linear function, one-dimensional polynomial, or a
custom network. You can also remove the input nonlinearity.
2 Computes the output of the linear block using w(t) and initial conditions: x(t) = (B/
F)w(t).
You can configure the linear block by specifying the numerator B and denominator F
orders.
3 Compute the model output by transforming the output of the linear block x(t) using
the nonlinear function h: y(t) = h(x(t)).
Resulting models are idnlhw objects that store all model data, including model
parameters and nonlinearity estimator. See the idnlhw reference page for more
information.
5-50
Identifying Hammerstein-Wiener Models
the input and output nonlinearities f and h, respectively. For more information about
F(x), see “Structure of Hammerstein-Wiener Models” on page 5-49.
Each nonlinearity estimator corresponds to an object class in this toolbox. When you
estimate Hammerstein-Wiener models in the app, System Identification Toolbox
creates and configures objects based on these classes. You can also create and configure
nonlinearity estimators at the command line. For a detailed description of each
estimator, see the references page of the corresponding nonlinearity class.
Saturation saturation Parameterize hard limits on the signal Use to model known
value as upper and lower saturation saturation effects on
limits. signal amplitudes.
Dead zone deadzone Parameterize dead zones in signals as the Use to model known
duration of zero response. dead zones in signal
amplitudes.
One- poly1d Single-variable polynomial of a degree By default, the
dimensional that you specify. polynomial degree is
polynomial 1.
5-51
5 Nonlinear Black-Box Model Identification
You can perform this operation only at the command line. The initialization
configures the Hammerstein-Wiener model to use orders and delay of the linear
5-52
Identifying Hammerstein-Wiener Models
model, and the B and F polynomials as the transfer function numerator and
denominator. See “Using Linear Model for Hammerstein-Wiener Estimation” on page
5-64.
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:
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.
5-53
5 Nonlinear Black-Box Model Identification
Prerequisites
• Learn about the Hammerstein-Wiener model structure (see “Structure of
Hammerstein-Wiener Models” on page 5-49).
• Import data into the System Identification app (see “Preparing Data for Nonlinear
Identification” on page 5-6).
• (Optional) Choose a nonlinearity estimator in “Nonlinearity Estimators for
Hammerstein-Wiener Models” on page 5-50.
• (Optional) Estimate or construct an OE or state-space model to use for initialization.
See “Using Linear Model for Hammerstein-Wiener Estimation” on page 5-64.
1 In the System Identification app, select Estimate > Nonlinear models to open the
Nonlinear Models dialog box.
2 In the Configure tab, select Hammerstein-Wiener from the Model type list.
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
app.
4 (Optional) If you want to refine a previously estimated model, click Initialize to
select a previously estimated model from the Initial Model list.
Note: Refining a previously estimated model starts with the parameter values of the
initial model and uses the same model structure. You can change these settings.
5-54
Prerequisites
Note: For more information about available options, click Help in the Nonlinear
Models dialog box to open the app help.
For multiple-input
and multiple-output
systems, you can assign
nonlinearities to specific
input and output channels.
Model order and delay In the Linear Block If you do not know the
tab, specify B Order, F input delay values, click
Order, and Input Delay. Infer Input Delay. This
For MIMO systems, select action opens the Infer
the output channel and Input Delay dialog box
specify the orders and which suggests possible
delays from each input delay values.
channel.
Estimation algorithm In the Estimate tab, click You can specify to estimate
Algorithm Options. initial states.
6 To obtain regularized estimates of model parameters, in the Estimate tab,
click Estimation Options. Specify the regularization constants in the
5-55
5 Nonlinear Black-Box Model Identification
If you get a poor fit, try changing the model structure or algorithm configuration in
step 5.
You can export the model to the MATLAB workspace by dragging it to To Workspace in
the System Identification app.
Prerequisites
• Learn about the Hammerstein-Wiener model structure described in “Structure of
Hammerstein-Wiener Models” on page 5-49.
• Prepare your data, as described in “Preparing Data for Nonlinear Identification” on
page 5-6.
• (Optional) Choose a nonlinearity estimator in “Nonlinearity Estimators for
Hammerstein-Wiener Models” on page 5-50.
• (Optional) Estimate or construct an input-output polynomial model of Output-Error
(OE) structure (idpoly) or a state-space model with no disturbance component (idss
with K=0) for initialization of Hammerstein-Wiener model. See “Using Linear Model
for Hammerstein-Wiener Estimation” on page 5-64.
Basic Estimation
5-56
Configure the nonlinearity estimator.
Start with the simplest estimation using m = nlhw(data,[nb nf nk]). For example:
load iddata3;
% nb = nf = 2 and nk = 1
m = nlhw(z3,[2 2 1])
m =
Hammerstein-Wiener model with 1 output and 1 input
Linear transfer function corresponding to the orders nb = 2, nf = 2, nk = 1
Input nonlinearity: pwlinear with 10 units
Output nonlinearity: pwlinear with 10 units
Loss function: 1.3593
Sampling interval: 1
Estimated model (NLHW)
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.
To use nonlinearity estimators with default settings, specify InputNL and OutputNL
using strings (such as 'wavenet' for wavelet network or 'sigmoidnet' for sigmoid
network).
load iddata3;
m = nlhw(z3,[2 2 1],'sigmoidnet','deadzone');
If you need to configure the properties of a nonlinearity estimator, use its object
representation. For example, to estimate a Hammerstein-Wiener model that uses
5-57
5 Nonlinear Black-Box Model Identification
m = nlhw(z3,[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.
Additional available nonlinearities include custom networks that you create. Specify
a custom network by defining a function called gaussunit.m, as described in the
customnet reference page. Define the custom network object CNetw as:
CNetw = customnet(@gaussunit);
m = nlhw(z3,[2 2 1],'saturation',CNetw);
5-58
Iteratively refine the model.
For more information about model estimation and properties, see the nlhw and idnlhw
reference pages.
load iddata3;
m1 = nlhw(z3, [2 2 1],'sigmoidnet','wavenet');
% can repeatedly run this command
m2 = pem(z3,m1);
m1 = nlhw(z3, [2 2 1],'sigmoidnet','wavenet');
% can repeatedly run this command
m2 = nlhw(z3,m1);
You can also try perturbing the parameters of the last model using init (called
randomization) and refining the model using pem:
% original model
5-59
5 Nonlinear Black-Box Model Identification
You can display the progress of the iterative search in the MATLAB Command Window
using the Display property of the idnlhw class.
M2= pem(z3,M1p,'Display','On');
load iddata3;
m = nlhw(z3,[2 2 1],sigmoidnet,[],'InitialState','e');
Nonlinear black-box system identification usually requires more data than linear model
identification to gain enough information about the system.
This example shows how to use nlhw to estimate a Hammerstein-Wiener model for
measured input/output data.
5-60
What if you cannot get a satisfactory model?
load twotankdata
z = iddata(y, u, 0.2);
ze = z(1:1000); zv = z(1001:3000);
Estimate several models using different model orders, delays, and nonlinearity settings.
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));
An alternative way to perform the estimation is to configure the model structure first,
and then to estimate this model.
Compare the resulting models by plotting the model outputs on top of the measured
output.
compare(zv,m1,m2,m3,m4,m5)
5-61
5 Nonlinear Black-Box Model Identification
This example shows how to use the Hammerstein-Wiener model structure to improve a
previously estimated linear model.
After estimating the linear model, insert it into the Hammerstein-Wiener structure that
includes input or output nonlinearities.
load iddata1
LM = arx(z1,[2 2 1]);
5-62
What if you cannot get a satisfactory model?
Create a Hammerstein-Wiener model, where you initialize the linear block properties B
and F using Num and Den, respectively.
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],[],'pwlinear');
M.b = Num;
M.f = Den;
Estimate the model coefficients, which refines the linear model coefficients in Num and
Den .
M = pem(z1, M);
compare(z1,LM,M);
5-63
5 Nonlinear Black-Box Model Identification
5-64
What if you cannot get a satisfactory model?
Tip To learn more about when to use linear models, see “When to Fit Nonlinear Models”
on page 5-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.
During estimation, the estimation algorithm uses these values to further adjust the
nonlinear model to the data.
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')
After each estimation, validate the model by comparing the simulated response to the
data. To improve the fit of the Hammerstein-Wiener model, adjust various elements
of the Hammerstein-Wiener structure. For more information, see “Ways to Configure
Hammerstein-Wiener Estimation” on page 5-52.
5-65
5 Nonlinear Black-Box Model Identification
load throttledata.mat
This command loads the data object ThrottleData into the workspace. The object
contains input and output samples collected from an engine throttle system, sampled at a
rate of 100Hz.
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)
5-66
What if you cannot get a satisfactory model?
In the normal operating range of 15-90 degrees, the input and output variables have a
linear relationship. You use a linear model of low order to model this relationship.
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.
5-67
5 Nonlinear Black-Box Model Identification
The linear model captures the rising and settling behavior in the linear operating range
but does not account for output saturation at 90 degrees.
5-68
What if you cannot get a satisfactory model?
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)
5-69
5 Nonlinear Black-Box Model Identification
A Hammerstein-Wiener plot displays the characteristics of the linear block and the static
nonlinearities of a Hammerstein-Wiener model.
Examining a Hammerstein-Wiener plot can help you determine whether you chose an
unnecessarily complicated nonlinearity for modeling your system. For example, if you
chose a piecewise-linear nonlinearity (which is very general), but the plot indicates
saturation behavior, then you can estimate a new model using the simpler saturation
nonlinearity instead.
For multivariable systems, you can use the Hammerstein-Wiener plot to determine
whether to exclude nonlinearities for specific channels. If the nonlinearity for a specific
input or output channel does not exhibit strong nonlinear behavior, you can estimate a
new model after setting the nonlinearity at that channel to unit gain.
Explore the various plots in the plot window by clicking one of the three blocks that
represent the model:
Note: The Hamm-Wiener check box is unavailable if you do not have a Hammerstein-
Wiener model in the Model Board.
5-70
What if you cannot get a satisfactory model?
To include or exclude a model on the plot, click the corresponding model icon in the
System Identification app. 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.
Hide or show
the top pane.
After you generate a plot, you can learn more about your model by:
You can use the following approaches to validate Hammerstein-Wiener models at the
command line:
5-71
5 Nonlinear Black-Box Model Identification
For example, compare Output Error (OE) and Hammerstein-Wiener models of same
order:
load iddata1;
% Estimate linear ARX model
LM = oe(z1,[2 2 1]);
% Estimate Hammerstein-Wiener model
M = nlhw(z1,[2 2 1],'unitgain',[]);
% Compare responses of LM and M against measured data
compare(z1,LM,M);
5-72
Compare Model Output to Measured Output
5-73
5 Nonlinear Black-Box Model Identification
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.
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:
5-74
Check Iterative Search Termination Conditions
property, which describes why the estimation was stopped. For example, the algorithm
might have reached the maximum number of iterations or the required tolerance value.
1
If the top pane is not visible, click to expand the Hammerstein-Wiener Model
Plot window.
2 Select the nonlinear block you want to plot:
• 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 Click Apply to update the plot.
1 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.
The Hammerstein-Wiener model contains one Linear Block that represents the
embedded linear model.
5-75
5 Nonlinear Black-Box Model Identification
1
If the top pane is not visible, click to expand the Hammerstein-Wiener Model
Plot window.
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 In the Choose plot type list, select the linear plot from the following options:
• Step
• Impulse
• Bode
• Pole-Zero Map
1 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.
The default frequency vector is 128 linearly distributed values, greater than zero and
less than or equal to the Nyquist frequency. To change the range, select Options
> Frequency range, and specify a new frequency vector in units of rad per model
time units.
5-76
Simulation and Prediction
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 “How the
Software Computes Hammerstein-Wiener Model Output” on page 5-78.
Linearization
Compute linear approximation of Hammerstein-Wiener models using linearize or
linapp.
You can compute the operating point for linearization using findop(idnlhw).
After computing a linear approximation of a nonlinear model, you can perform linear
analysis and control design on your model using Control System Toolbox commands. For
more information, see “Using Identified Models for Control Design Applications” and
“Create and Plot Identified Models Using Control System Toolbox Software”.
5-77
5 Nonlinear Black-Box Model Identification
Toolbox block library. After you bring the idnlhw object from the workspace into
Simulink, you can simulate the model output.
The IDNLHW Model block supports code generation with the Simulink Coder software,
using both generic and embedded targets. Code generation does not work when the model
contains customnet as the input or output nonlinearity.
Evaluating the predicted output of a nonlinearity for a input u requires that you first
extract the input or output nonlinearity F from the model:
F = M.InputNonlinearity % equivalent to F = M.unl
H = M.OutputNonlinearity % equivalent to F = M.ynl
Evaluate F(u):
w = evaluate(F,u)
where u is a scalar representing the value of the input signal at a given time.
You can evaluate predicted output values at multiple time instants by evaluating F for
several time values simultaneously using a column vector of input values:
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)
For MIMO models, F and H are vectors of length nu and ny, respectively. nu is the
number of inputs and ny is the number of outputs. In this case, you must evaluate the
predicted output of each nonlinearity separately.
5-78
Simulation and Code Generation Using Simulink
The total input to the linear block, w, is a vector of w1 and w2 (w = [w1 w2]).
This example shows how the software evaluates the simulated output by first computing
the output of the input and output nonlinearity estimators. For same initial conditions,
the prediction results match the simulation results.
Extract the input nonlinearity, linear model, and output nonlinearity as separate
variables.
uNL = M.InputNonlinearity;
linModel = M.LinearModel;
yNL = M.OutputNonlinearity;
5-79
5 Nonlinear Black-Box Model Identification
5-80
Linear Approximation of Nonlinear Black-Box Models
To compute a linear approximation of a nonlinear model for a given input signal, use the
linapp command. The resulting model is only valid for the same input that you use to
compute the linear approximation. For more information, see “Linear Approximation of
Nonlinear Black-Box Models for a Given Input” on page 5-81.
If you want a tangent approximation of the nonlinear dynamics that is accurate near the
system operating point, use the linearize command. The resulting model is a first-
order Taylor series approximation for the system about the operating point, which is
defined by a constant input and model state values. For more information, see “Tangent
Linearization of Nonlinear Black-Box Models” on page 5-82.
5-81
5 Nonlinear Black-Box Model Identification
input. The resulting linear model might only be valid for the same input signal as you the
one you used to generate the linear approximation.
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.
To compute a linear approximation of a nonlinear black-box model for a given input, you
must have these variables:
• 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.
5-82
Linear Approximation of Nonlinear Black-Box Models
• 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 5-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:
Construct an object that stores specifications for computing the operating point,
including input and output bounds, known values, and initial guesses. For more
information, see operspec(idnlarx) or operspec(idnlhw).
5-83
5 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.
5-84
6
The toolbox supports both continuous-time and discrete-time linear and nonlinear
models. However, because most laws of physics are expressed in continuous time, it
is easier to construct models with physical insight in continuous time, rather than in
discrete time.
In addition to dynamic input-output models, you can also create time-series models that
have no inputs and static models that have no states.
If it is too difficult to describe your system using known physical laws, you can use the
black-box modeling approach. For more information, see “Linear Model Identification”
and “Nonlinear Model Identification”.
You can also use the idss model object to perform structured model estimation by using
its Structure property 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 “Estimate State-Space Models with Structured
Parameterization”.
6-2
Data Supported by Grey-Box Models
You must first import your data into the MATLAB workspace. You must represent your
data as an iddata or idfrd object. For more information about preparing data for
identification, see “Data Preparation”.
6-3
6 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 6-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
6-15.
6-4
Choosing idgrey or idnlgrey Model Object
6-5
6 ODE Parameter Estimation (Grey-Box Modeling)
You must represent your system equations in state-space form. State-space models use
state variables x(t) to describe a system as a set of first-order differential equations,
rather than by one or more nth-order differential equations.
The first step in grey-box modeling is to write a function that returns state-space
matrices as a function of user-defined parameters and information about the model.
Use the following format to implement the linear grey-box model in the file:
[A,B,C,D] = myfunc(par1,par2,...,parN,Ts,aux1,aux2,...)
where the output arguments are the state-space matrices and myfunc is the name of
the file. par1,par2,...,parN are the N parameters of the model. Each entry may
be a scalar, vector or matrix.Ts is the sample time. aux1,aux2,... are the optional
input arguments that myfunc uses to compute the state-space matrices in addition to the
parameters and sample time.
aux contains auxiliary variables in your system. You use auxiliary variables to vary
system parameters at the input to the function, and avoid editing the file.
6-6
Estimating Linear Grey-Box Models
Where, A,B,C and D are matrices that are parameterized by the parameters
par1,par2,...,parN. The noise matrix K and initial state vector, x0, are not
parameterized by myfunc. They can still be estimated as additional quantities along with
the model parameters. To configure the handling of initial states, x0, and the disturbance
component, K, during estimation, use the greyestOptions option set.
Where, A,B,C and D are now the discrete-time matrices that are parameterized by the
parameters par1,par2,...,parN. K and x0 are not directly parameterized, but can be
estimated if required by configuring the corresponding estimation options.
In some applications, you may want to express K and x0 as quantities that are
parameterized by chosen parameters, just as the A, B, C and D matrices. To handle
such cases, you can write the ODE file, myfunc, to return K and x0 as additional output
arguments:
[A,B,C,D,K,x0] = myfunc(par1,par2,...,parN,Ts,aux1,aux2,...)
K and x0 are thus treated in the same way as the A, B, C and D matrices. They are all
functions of the parameters par1,par2,...,parN.
After creating the function or MEX-file with your model structure, you must define as
idgrey object. For information regarding creating this, see idgrey.
6-7
6 ODE Parameter Estimation (Grey-Box Modeling)
È0 1 ˘ È0˘
x& (t) = Í ˙ x(t) + Í ˙ u(t)
Î 0 q1 ˚ Îq2 ˚
È1 0 ˘
y( t) = Í ˙ x( t) + e(t)
Î0 1 ˚
Èq ˘
x(0) = Í 3 ˙
Î0 ˚
This equation represents an electrical motor, where y1 ( t) = x1 (t) is the angular position
of the motor shaft, and y2 (t) = x2 (t) is the angular velocity. The parameter -q1 is the
inverse time constant of the motor, and - q 2 q is the static gain from the input to the
1
angular velocity.
The motor is at rest at t=0, but its angular position q3 is unknown. Suppose that the
approximate nominal values of the unknown parameters are q1 = -1 , q2 = 0 .25 and
q3 = 0 . 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:
6-8
Estimating Linear Grey-Box Models
2 Use the following syntax to define an idgrey model object based on the myfunc file:
par = [-1; 0.25; 0];
aux = {};
T = 0;
m = idgrey('myfunc',par,'c',aux,T);
where par represents a vector of all the user-defined parameters and contains
their nominal (initial) values. In this example, all the scalar-valued parameters
are grouped in the par vector. The scalar-valued parameters could also have been
treated as independent input arguments to the ODE function myfunc.'c' specifies
that the underlying parameterization is in continuous time. aux represents optional
arguments. As myfunc does not have any optional arguments, use aux = {}. T
specifies the sample interval; T = 0 indicates a continuous-time model.
where data is the estimation data and m is an estimation initialization idgrey model.
m_est is the estimated idgrey model.
∂ x( t, x ) ∂ 2 x( t, x )
=k
∂t ∂x 2
6-9
6 ODE Parameter Estimation (Grey-Box Modeling)
∂ 2 x( t, x ) x ( t, x + D L) - 2 x(t, x) + x ( t, x - DL )
=
2 2
∂x ( DL )
where x = k ◊ DL
This transformation produces a state-space model of order n = DLL , where the state
variables x(t, k ◊ DL) are lumped representations for x(t, x) for the following range of
values:
k ◊ DL £ x < ( k + 1) DL
% (t)
x& (t) = Fx(t) + Gu(t) + Kw
y( t) = Hx(t) + Du( t) + w(t)
x(0) = x0
The state-space matrices are parameterized by the heat diffusion coefficient κ and the
heat transfer coefficient at the far end of the rod htf. The expressions also depend upon
the grid size, Ngrid, and the length of the rod L. The initial conditions x0 are a function
of the initial room temperature, treated as a known quantity in this example.
The following code describes the state-space equation for this model. The parameters
are κ and htf while the auxiliary variables are Ngrid, L and initial room temperature
temp. The grid size is supplied as an auxiliary variable so that the ODE function can
be easily adapted for various grid sizes.
function [A,B,C,D,K,x0] = heatd(kappa, htf, T, Ngrid, L, temp)
% ODE file parameterizing the heat diffusion model
6-10
Estimating Linear Grey-Box Models
% A matrix
A = zeros(Ngrid,Ngrid);
for kk = 2:Ngrid-1
A(kk,kk-1) = 1;
A(kk,kk) = -2;
A(kk,kk+1) = 1;
end
% B matrix
B = zeros(Ngrid,1);
B(Ngrid,1) = htf/deltaL;
% C matrix
C = zeros(1,Ngrid);
C(1,1) = 1;
6-11
6 ODE Parameter Estimation (Grey-Box Modeling)
This command specifies the auxiliary parameters as inputs to the function, include
the model order (grid size) 10, the rod length of 1 meter, and an initial temperature
of 22 degrees Celsius. The command also specifies the initial values for heat
conductivity as 0.27, and for the heat transfer coefficient as 1.
3 For given data, you can use greyest to estimate the grey-box parameter values:
me = greyest(data,m)
The following command shows how you can specify to estimate a new model with
different auxiliary variables:
m.Structure.ExtraArgs = {20,1,22};
me = greyest(data,m);
This syntax uses the ExtraArgs model structure attribute 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.
È par1 par 2 ˘ È1 ˘
x(kT + T ) = Í ˙ x( kT ) + Í ˙ u(kT ) + w(kT )
Î 1 0 ˚ Î0 ˚
y( kT ) = [ par3 par 4 ] x( kT) + e(kT )
x(0) = x0
where w and e are independent white-noise terms with covariance matrices R1 and R2,
respectively. R1=E{ww'} is a 2–by-2 matrix and R2=E{ee'} is a scalar. par1, par2, par3,
and par4 represent the unknown parameter values to be estimated.
6-12
Estimating Linear Grey-Box Models
Assume that you know the variance of the measurement noise R2 to be 1. R1(1,1) is
unknown and is treated as an additional parameter par5. The remaining elements of R1
are known to be zero.
You can represent the system described in “Description of the SISO System” on page
6-12 as an idgrey (grey-box) model using a function. Then, you can use this file and
the greyest command to estimate the model parameters based on initial parameter
guesses.
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-50
or “Representing Frequency-Response Data Using idfrd Objects” on page 2-83.
1 Create the file mynoise that computes the state-space matrices as a function of
the five unknown parameters and the auxiliary variable that represents the known
variance R2. The initial conditions are not parameterized; they are assumed to be
zero during this estimation.
Note: R2 is treated as an auxiliary variable rather than assigned a value in the file
to let you change this value directly at the command line and avoid editing the file.
6-13
6 ODE Parameter Estimation (Grey-Box Modeling)
Minit = idgrey('mynoise',Pvec,'d',auxVal);
6-14
Estimating Nonlinear Grey-Box Models
where x† (t) = dx( t) dt for continuous-time representation and x† (t) = x( t + Ts) for discrete-
time representation with Ts as the sampling interval. F and H are arbitrary linear or
nonlinear functions with Nx and Ny components, respectively. Nx is the number of states
and Ny is the number of outputs.
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 “MEX-File Creation API”.
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:
[dx,y] = MODFILENAME(t,x,u,p1,p2, ...,pN,FileArgument)
6-15
6 ODE Parameter Estimation (Grey-Box Modeling)
• dx — Represents the right side(s) of the state-space equation(s). A column vector with
Nx entries. For static models, dx=[].
For discrete-time models. dx is the value of the states at the next time step x(t
+Ts).
• y — Represents the right side(s) of the output equation(s). A column vector with Ny
entries.
• 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 Creating
idnlgrey Model Files.
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 is described in
files dcmotor_m and dcmotor_c.
6-16
Estimating Nonlinear Grey-Box Models
m = idnlgrey('filename',Order,Parameters,InitialStates)
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.
6-17
6 ODE Parameter Estimation (Grey-Box Modeling)
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 “Model Validation”.
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.
6-18
Estimating Nonlinear Grey-Box Models
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.
One category of methods consists of the minimization schemes that are based on line-
search methods, including Gauss-Newton type methods, steepest-descent methods, and
Levenberg-Marquardt methods.
By default, SearchMethod is set to Auto, which automatically selects a method from the
available minimizers. If the Optimization Toolbox product is installed, SearchMethod
is set to 'lsqnonlin'. Otherwise, SearchMethod is a combination of line-search based
schemes.
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.
You can specify the Algorithm fields directly in the estimation syntax, as property-value
pairs.
For example, you can specify the following properties as part of the pem syntax:
m = pem(data,init_model,'Search','gn',...
6-19
6 ODE Parameter Estimation (Grey-Box Modeling)
'MaxIter',5,...
'Display','On')
Nonlinear grey-box (idnlgrey) models are suitable for estimating parameters of systems
that are described by nonlinear state-space structures in continuous or discrete time.
You can use both idgrey (linear grey-box model) and idnlgrey objects to model linear
systems. However, you can only use idnlgrey to represent nonlinear dynamics. To
learn about linear grey-box modeling using idgrey, see “"Building Structured and User-
Defined Models Using System Identification Toolbox™"”.
In this example, you model the dynamics of a linear DC motor using the idnlgrey
object.
6-20
Estimating Nonlinear Grey-Box Models
If you ignore the disturbances and choose y(1) as the angular position [rad] and y(2)
as the angular velocity [rad/s] of the motor, you can set up a linear state-space structure
of the following form (see Ljung, L. System Identification: Theory for the User, Upper
Saddle River, NJ, Prentice-Hall PTR, 1999, 2nd ed., p. 95-97 for the derivation):
d | 0 1 | | 0 |
-- x(t) = | | x(t) + | | u(t)
dt | 0 -1/tau | | k/tau |
| 1 0 |
y(t) = | | x(t)
| 0 1 |
tau is the time-constant of the motor in [s] and k is the static gain from the input to the
angular velocity in [rad/(V*s)] . See Ljung (1999) for how tau and k relate to the physical
parameters of the motor.
3. Specify input and output signal names, start time and time units.
z.InputName = 'Voltage';
z.InputUnit = 'V';
z.OutputName = {'Angular position', 'Angular velocity'};
z.OutputUnit = {'rad', 'rad/s'};
z.Tstart = 0;
z.TimeUnit = 's';
6-21
6 ODE Parameter Estimation (Grey-Box Modeling)
6-22
Estimating Nonlinear Grey-Box Models
In this example, you use a MATLAB® file, but you can also use C MEX-files (to gain
computational speed), P-files or function handles. For more information, see “"Creating
IDNLGREY Model Files"”.
% Output equations.
6-23
6 ODE Parameter Estimation (Grey-Box Modeling)
% State equations.
dx = [x(2); ... % Angular velocity.
-(1/tau)*x(2)+(k/tau)*u(1) ... % Angular acceleration.
];
Output arguments:
• dx is the vector of state derivatives in continuous-time case, and state update values
in the discrete-time case.
Input arguments:
• The first three input arguments must be: t (time), x (state vector, [] for static
systems), u (input vector, [] for time-series).
• Ordered list of parameters follow. The parameters can be scalars, column vectors, or
2-dimensional matrices.
The model describes how the inputs generate the outputs using the state equation(s).
In practice, there are disturbances that affect the outputs. An idnlgrey model does not
explicitly model the disturbances, but assumes that these are just added to the output(s).
Thus, idnlgrey models are equivalent to Output-Error (OE) models. Without a noise
6-24
Estimating Nonlinear Grey-Box Models
model, past outputs do not influence prediction of future outputs, which means that
predicted output for any prediction horizon k coincide with simulated outputs.
You can also use setinit and setpar to assign values, minima, maxima, and
estimation status for all initial states or parameters simultaneously.
size(nlgr)
Nolinear grey-box model with 2 outputs, 1 inputs, 2 states and 2 parameters (2 free).
Both the initial states and parameters are structure arrays. The fields specify the
properties of an individual initial state or parameter. Type idprops idnlgrey
InitialStates and idprops idnlgrey Parameters for more information.
nlgr.InitialStates(1)
nlgr.Parameters(2)
ans =
6-25
6 ODE Parameter Estimation (Grey-Box Modeling)
Unit: 'rad'
Value: 0
Minimum: -Inf
Maximum: Inf
Fixed: 1
ans =
c. Retrieve information for all initial states or model parameters in one call.
For example, obtain information on initial states that are fixed (not estimated) and the
minima of all model parameters.
getinit(nlgr, 'Fixed')
getpar(nlgr, 'Min')
ans =
[1]
[1]
ans =
[-Inf]
[-Inf]
nlgr
nlgr =
Continuous-time nonlinear grey-box model defined by 'dcmotor_m' (MATLAB file):
6-26
Estimating Nonlinear Grey-Box Models
Use get to obtain more information about the model properties. The idnlgrey object
shares many properties of parametric linear model objects.
get(nlgr)
FileName: 'dcmotor_m'
Order: [1x1 struct]
Parameters: [2x1 struct]
InitialStates: [2x1 struct]
FileArgument: {}
CovarianceMatrix: 'estimate'
EstimationInfo: [1x1 struct]
TimeVariable: 't'
NoiseVariance: [2x2 double]
Algorithm: [1x1 struct]
Ts: 0
TimeUnit: 'seconds'
InputName: {'Voltage'}
InputUnit: {'V'}
InputGroup: [1x1 struct]
OutputName: {2x1 cell}
OutputUnit: {2x1 cell}
OutputGroup: [1x1 struct]
Name: 'DC-motor'
Notes: {}
UserData: []
Before estimating the parameters tau and k, simulate the output of the system with
the parameter guesses using the default differential equation solver (a Runge-Kutta 45
solver with adaptive step length adjustment).
1. Set the absolute and relative error tolerances to small values (1e-6 and 1e-5,
respectively).
nlgr.Algorithm.SimulationOptions.AbsTol = 1e-6;
6-27
6 ODE Parameter Estimation (Grey-Box Modeling)
nlgr.Algorithm.SimulationOptions.RelTol = 1e-5;
compare displays both measured and simulated outputs of one or more models, whereas
predict, called with the same input arguments, displays the simulated outputs.
Figure 3: Comparison between measured outputs and the simulated outputs of the
initial DC-motor model.
Parameter Estimation
6-28
Estimating Nonlinear Grey-Box Models
Estimate the parameters and initial states using pem (Prediction-Error identification
Method).
This information is stored in the EstimationInfo property of the idnlgrey object. The
property also contains information about how the model was estimated, such as solver
and search method, data set, and why the estimation was terminated.
nlgr.EstimationInfo
ans =
The fits are 98% and 84%, which indicate that the estimated model captures the
dynamics of the DC motor well.
compare(z, nlgr);
6-29
6 ODE Parameter Estimation (Grey-Box Modeling)
Figure 4: Comparison between measured outputs and the simulated outputs of the
estimated IDNLGREY DC-motor model.
3. Compare the performance of the idnlgrey model with a second-order ARX model.
na = [2 2; 2 2];
nb = [2; 2];
nk = [1; 1];
dcarx = arx(z, [na nb nk]);
compare(z, nlgr, dcarx);
6-30
Estimating Nonlinear Grey-Box Models
Figure 5: Comparison between measured outputs and the simulated outputs of the
estimated IDNLGREY and ARX DC-motor models.
The prediction errors obtained are small and are centered around zero (non-biased).
pe(z, nlgr);
6-31
6 ODE Parameter Estimation (Grey-Box Modeling)
Figure 6: Prediction errors obtained with the estimated IDNLGREY DC-motor model.
Residuals indicate what is left unexplained by the model and are small for good model
quality. Execute the following two lines of code to generate the residual plot. Press any
key to advance from one plot to another.
6-32
Estimating Nonlinear Grey-Box Models
6-33
6 ODE Parameter Estimation (Grey-Box Modeling)
A unit input step results in an angular position showing a ramp-type behavior and to an
angular velocity that stabilizes at a constant level.
6-34
Estimating Nonlinear Grey-Box Models
You can assess the quality of the estimated model to some extent by looking at the
estimated covariance matrix and the estimated noise variance. A "small" value of the (i,
i) diagonal element of the covariance matrix indicates that the i:th model parameter is
important for explaining the system dynamics when using the chosen model structure.
Small noise variance (covariance for multi-output systems) elements are also a good
indication that the model captures the estimation data in a good way.
nlgr.CovarianceMatrix
nlgr.NoiseVariance
6-35
6 ODE Parameter Estimation (Grey-Box Modeling)
ans =
1.0e-04 *
0.1521 0.0015
0.0015 0.0007
ans =
0.0099 -0.0004
-0.0004 0.1094
For more information about the estimated model, use present to display the initial
states and estimated parameter values, and estimated uncertainty (standard deviation)
for the parameters.
present(nlgr);
nlgr =
Continuous-time nonlinear grey-box model defined by 'dcmotor_m' (MATLAB file):
Input:
u(1) Voltage(t) [V]
States: initial value
x(1) Angular position(t) [rad] xinit@exp1 0.0302675 (est) in [-Inf, Inf]
x(2) Angular velocity(t) [rad/s] xinit@exp1 -0.133777 (est) in [-Inf, Inf]
Outputs:
y(1) Angular position(t) [rad]
y(2) Angular velocity(t) [rad/s]
Parameters: value standard dev
p1 Time-constant [s] 0.243649 0.00390034 (est) in [-Inf, Inf]
p2 Static gain [rad/(V*s)] 0.249644 0.000272168 (est) in [-Inf, Inf]
The model was estimated from the data set 'DC-motor', which
contains 400 data samples.
Loss function 0.00107459 and Akaike's FPE 0.00108534
Created: 04-Sep-2014 10:06:38
6-36
Estimating Nonlinear Grey-Box Models
Conclusions
This example illustrates the basic tools for performing nonlinear grey-box modeling. See
the other nonlinear grey-box examples to learn about:
6-37
6 ODE Parameter Estimation (Grey-Box Modeling)
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”. You must convert your model to
an idss object to perform input-output concatenation or to use sample time conversion
functions (c2d, d2c, d2d).
Note: Sample-time conversion functions require that you convert idgrey models with
FcnType ='cd' to idss models.
The toolbox represents nonlinear grey-box models as idnlgrey model objects. These
model objects store the parameter values resulting from the estimation. You can access
these parameters from the model objects to use these variables in computation in the
MATLAB workspace.
You can import nonlinear and linear grey box models into a Simulink model using the
System Identification Toolbox Block Library. For more information, see “Simulating
Identified Model Output in Simulink”.
6-38
Estimating Coefficients of ODEs to Fit Given Solution
Use grey-box identification to estimate coefficients of ODEs that describe the model
dynamics to fit a given response trajectory.
• For linear dynamics, represent the model using a linear grey-box model (idgrey).
Estimate the model coefficients using greyest.
• For nonlinear dynamics, represent the model using a nonlinear grey-box model
(idnlgrey). Estimate the model coefficients using pem.
In this example, you estimate the value of the friction coefficient of a simple pendulum
using its oscillation data. The motion of a simple pendulum is described by:
θ is the angular displacement of the pendulum relative to its state of rest. g is the
gravitational acceleration constant. m is the mass of the pendulum and l is the length of
the pendulum. b is the viscous friction coefficient whose value will be estimated to fit the
given angular displacement data. There is no external driving force that is contributing
to the pendulum’s motion.
The measured angular displacement data is loaded and saved as data, an iddata object
with a sampling time of 0.1 seconds. The set command is used to specify data attributes
such as the output name, output unit and the start time and units of the time vector.
Assuming that the pendulum undergoes only small angular displacements, the equation
describing the pendulum motion can be simplified:
6-39
6 ODE Parameter Estimation (Grey-Box Modeling)
Using the angular displacement ( q ) and the angular velocity ( q& ) as state variables, the
simplified equation can be rewritten in the form:
.
X (t) = AX ( t) + Bu(t)
y( t) = CX (t) + Du(t)
Here,
Èq ˘
X (t) = Í & ˙
Îq ˚
È 0 1 ˘
A = Í-g -b ˙
˙
Í
ÍÎ l ml 2 ˙˚
B=0
C = [1 0 ]
D=0
The B and D matrices are zero because there is no external driving force for the simple
pendulum.
1 Create an ODE file that relates the model coefficients to its state space
representation.
function [A,B,C,D] = LinearPendulum(m,g,l,b,Ts)
% Function mapping ODE coefficients to state-space matrices.
% Save this function as a file on your computer.
A = [0 1; -g/l, -b/m/l^2];
B = zeros(2,0);
C = [1 0];
D = zeros(1,0);
end
The function, LinearPendulum, returns the state space representation of the linear
motion model of the simple pendulum using the model coefficients m, g, l and b. The
sample time used is specified by Ts.
6-40
Estimating Coefficients of ODEs to Fit Given Solution
m = 1;
g = 9.81;
l = 1;
b = 0.2;
linear_model = idgrey('LinearPendulum', {m,g,l,b},'c');
m, g and l specify the values of the known model coefficients. b specifies the initial
guess for the viscous friction coefficient.
linear_model.Structure.Parameters(1).Free = false;
linear_model.Structure.Parameters(2).Free = false;
linear_model.Structure.Parameters(3).Free = false;
As defined in the previous step, m, g, and l are the first three parameters of
linear_model. Using the Structure.Parameters.Free field for each of the
parameters, m, g, and l are specified as fixed values.
4 Create an estimation options set that specifies the initial state to be estimated and
turns on the estimation progress display.
opt = greyestOptions('InitialState','estimate','Display','on');
opt.Focus = 'stability';
5 Estimate the viscous friction coefficient.
linear_model = greyest(data,linear_model,opt);
b_est = linear_model.Structure.Parameters(4).Value;
[linear_b_est, dlinear_b_est] = getpvec(linear_model, 'free')
6-41
6 ODE Parameter Estimation (Grey-Box Modeling)
The estimated value of b, the viscous friction coefficient, using linear grey-box
estimation is 0.1178 with a standard deviation of 0.0088.
6 Compare the response of the linear grey-box model to the measured data.
compare(data,linear_model)
The linear grey-box estimation model provides a 49.9% fit to measured data. This is
not surprising given that the underlying assumption of the linear pendulum motion
model is that the pendulum undergoes small angular displacements, whereas the
measured data shows large oscillations.
Nonlinear grey-box estimation requires that you express the differential equation as a set
of first order equations.
6-42
Estimating Coefficients of ODEs to Fit Given Solution
Using the angular displacement ( q ) and the angular velocity ( q& ) as state variables,
the equation of motion can be rewritten as a set of first order nonlinear differential
equations:
x1 (t) = q ( t)
x (t) = q&( t)
2
x& 1 (t) = x2 ( t)
-g b
x& 2 (t) = sin( x1 ( t)) - x2 (t)
l ml 2
y( t) = x1 (t)
1 Create an ODE file that relates the model coefficients to its nonlinear
representation.
% Output equation.
y = x(1); % Angular position.
% State equations.
dx = [x(2); ... % Angular position
-(g/l)*sin(x(1))-b/(m*l^2)*x(2) ... % Angular velocity
];
end
The function, NonlinearPendulum, returns the state derivatives and output of the
nonlinear motion model of the pendulum using the model coefficients m, g, l and b.
m = 1;
g = 9.81;
l = 1;
b = 0.2;
6-43
6 ODE Parameter Estimation (Grey-Box Modeling)
order = [1 0 2];
parameters = {m,g,l,b};
initial_states = [1; 0];
Ts = 0;
nonlinear_model = idnlgrey('NonlinearPendulum', order, ...
parameters, initial_states, Ts);
3 Specify m, g and l as known parameters.
As defined in the previous step, m, g, and l are the first three parameters of
nonlinear_model. Using the setpar command, m, g, and l are specified as fixed
values and b is specified as a free estimation parameter.
4 Estimate the viscous friction coefficient.
nonlinear_model = pem(data,nonlinear_model,'Display','Full');
b_est = nonlinear_model.Parameters(4).Value;
[nonlinear_b_est, dnonlinear_b_est] = ...
getpvec(nonlinear_model, 'free')
The estimated value of b, the viscous friction coefficient, using nonlinear grey-box
estimation is 0.1 with a standard deviation of 0.0149.
5 Compare the response of the linear and nonlinear grey-box models to the measured
data.
compare(data,linear_model,nonlinear_model)
6-44
Estimating Coefficients of ODEs to Fit Given Solution
The nonlinear grey-box model estimation provides a closer fit (95%) to the measured
data.
6-45
6 ODE Parameter Estimation (Grey-Box Modeling)
You parameterize the model using complex-conjugate pole/zero pairs. When you
parameterize a real, grey-box model using complex-conjugate pairs of parameters, the
software updates parameter values such that the estimated values are also complex
conjugate pairs.
The variable zd, which contains measured data, is loaded into the MATLAB® workspace.
plot(zd);
6-46
Estimate Model Using Zero/Pole/Gain Parameters
Estimate the model using the zero-pole-gain (zpk) form using the zpkestODE function.
To view this function, enter
type zpkestODE
6-47
6 ODE Parameter Estimation (Grey-Box Modeling)
sysc = zpk(z,p,k);
if Ts==0
[a,b,c,d] = ssdata(sysc);
else
[a,b,c,d] = ssdata(c2d(sysc,Ts,'foh'));
end
Assume that the model has five poles and four zeros. Assume that two of the poles and
two of the zeros are complex conjugate pairs.
init_sys is an idgrey model that is associated with the zpkestODE.m function. The
'cd' flag indicates that the ODE function, zpkestODE, returns continuous or discrete
models, depending on the sampling period.
compare(zd,init_sys);
6-48
Estimate Model Using Zero/Pole/Gain Parameters
6-49
6 ODE Parameter Estimation (Grey-Box Modeling)
ans =
The getpvec command returns the parameter values for a model. In the output above,
each row displays corresponding initial and estimated parameter values. All parameters
that were initially specified as complex conjugate pairs remain so after estimation.
compare(zd,init_sys,sys);
6-50
Estimate Model Using Zero/Pole/Gain Parameters
See Also
c2d | getpvec | greyest | idgrey | ssdata
Related Examples
• “Estimating Coefficients of ODEs to Fit Given Solution” on page 6-39
• “Creating IDNLGREY Model Files” on page 6-52
6-51
6 ODE Parameter Estimation (Grey-Box Modeling)
Grey box modeling is conceptually different to black box modeling in that it involves
a more comprehensive modeling step. For IDNLGREY (the nonlinear grey-box model
object; the nonlinear counterpart of IDGREY), this step consists of creating an ODE file,
also called a "model file". The ODE file specifes the right-hand sides of the state and the
output equations typically arrived at through physical first principle modeling. In this
example we will concentrate on general aspects of implementing it as a MATLAB file or a
C MEX file.
For discrete-time structures, xn(t) = x(T+Ts) with Ts being the sampling time, and for
continuous-time structures xn(t) = d/dt x(t). In addition, F(.) and H(.) are arbitrary
linear or nonlinear functions with Nx (number of states) and Ny (number of outputs)
components, respectively. Any of the model parameters p1, ..., pNpo as well as the initial
state vector X(0) can be estimated. Worth stressing is that
1. time-series modeling, i.e., modeling without an exogenous input
signal u(t), and
2. static modeling, i.e., modeling without any states x(t)
are two special cases that are supported by IDNLGREY. (See the tutorials idnlgreydemo3
and idnlgreydemo5 for examples of these two modeling categories).
6-52
Creating IDNLGREY Model Files
MODFILENAME can here be any user chosen file name of a MATLAB or C MEX-file,
e.g., see twotanks_m.m, pendulum_c.c etc. This file should be defined to return two
outputs
dx: the right-hand side(s) of the state-space equation(s) (a column
vector with Nx real entries; [] for static models)
y: the right-hand side(s) of the output equation(s) (a column vector
with Ny real entries)
In the onward discussion we will focus on writing model using either MATLAB language
or using C-MEX files. However, IDNLGREY also supports P-files (protected MATLAB
files obtained using the MATLAB command "pcode") and function handles. In fact, it
is not only possible to use C MEX model files but also Fortran MEX files. Consult the
MATLAB documentation on External Interfaces for more information about the latter.
What kind of model file should be implemented? The answer to this question really
depends on the use of the model.
Implementation using MATLAB language (resulting in a *.m file) has some distinct
advantages. Firstly, one can avoid time-consuming, low-level programming and
concentrate more on the modeling aspects. Secondly, any function available within
MATLAB and its toolboxes can be used directly in the model files. Thirdly, such files
will be smaller and, without any modifications, all built-in MATLAB error checking will
automatically be enforced. In addition, this is obtained without any code compilation.
C MEX modeling is much more involved and requires basic knowledge about the C
programming language. The main advantage with C MEX model files is the improved
execution speed. Our general advice is to pursue C MEX modeling when the model is
going to be used many times, when large data sets are employed, and/or when the model
structure contains a lot of computations. It is often worthwhile to start with using a
MATLAB file and later on turn to the C MEX counterpart.
6-53
6 ODE Parameter Estimation (Grey-Box Modeling)
With this said, let us next move on to MATLAB file modeling and use a nonlinear second
order model structure, describing a two tank system, as an example. See idnlgreydemo2
for the modeling details. The contents of twotanks_m.m are as follows.
type twotanks_m.m
% Output equation.
y = x(2); % Water level, lower tank.
% State equations.
dx = [1/A1*(k*u(1)-a1*sqrt(2*g*x(1))); ... % Water level, upper tank.
1/A2*(a1*sqrt(2*g*x(1))-a2*sqrt(2*g*x(2))) ... % Water level, lower tank.
];
In the function header, we here find the required t, x, and u input arguments followed
by the six scalar model parameters, A1, k, a1, g, A2 and a2. In the MATLAB file
case, the last input argument should always be varargin to support the passing of an
optional model file input argument, FileArgument. In an IDNLGREY model object,
FileArgument is stored as a cell array that might hold any kind of data. The first element
of FileArgument is here accessed through varargin{1}{1}.
The variables and parameters are referred in the standard MATLAB way. The first state
is x(1) and the second x(2), the input is u(1) (or just u in case it is scalar), and the scalar
parameters are simply accessed through their names (A1, k, a1, g, A2 and a2). Individual
elements of vector and matrix parameters are accessed as P(i) (element i of a vector
parameter named P) and as P(i, j) (element at row i and column j of a matrix parameter
named P), respectively.
Writing a C MEX model file is more involved than writing a MATLAB model file. To
simplify this step, it is recommended that the available IDNLGREY C MEX model
template is copied to MODFILENAME.c. This template contains skeleton source code as
well as detailed instructions on how to customize the code for a particular application.
The location of the template file is found by typing the following at the MATLAB
command prompt.
6-54
Creating IDNLGREY Model Files
For the two tank example, this template was copied to twotanks_c.c. After some initial
modifications and configurations (described below) the state and output equations were
entered, thereby resulting in the following C MEX source code.
type twotanks_c.c
/* Include libraries. */
#include "mex.h"
#include <math.h>
/* State equations. */
void compute_dx(double *dx, double t, double *x, double *u, double **p,
const mxArray *auxvar)
{
/* Retrieve model parameters. */
double *A1, *k, *a1, *g, *A2, *a2;
A1 = p[0]; /* Upper tank area. */
k = p[1]; /* Pump constant. */
a1 = p[2]; /* Upper tank outlet area. */
g = p[3]; /* Gravity constant. */
A2 = p[4]; /* Lower tank area. */
a2 = p[5]; /* Lower tank outlet area. */
/* Output equation. */
void compute_y(double *y, double t, double *x, double *u, double **p,
const mxArray *auxvar)
{
/* y[0]: Water level, lower tank. */
y[0] = x[1];
}
6-55
6 ODE Parameter Estimation (Grey-Box Modeling)
/*----------------------------------------------------------------------- *
DO NOT MODIFY THE CODE BELOW UNLESS YOU NEED TO PASS ADDITIONAL
INFORMATION TO COMPUTE_DX AND COMPUTE_Y
if (nrhs < 3) {
mexErrMsgIdAndTxt("IDNLGREY:ODE_FILE:InvalidSyntax",
"At least 3 inputs expected (t, u, x).");
}
p = mxCalloc(np, sizeof(double*));
6-56
Creating IDNLGREY Model Files
/*
Call the state and output update functions.
Note: You may also pass other inputs that you might need,
such as number of states (nx) and number of parameters (np).
You may also omit unused inputs (such as auxvar).
For example, you may want to use orders nx and nu, but not time (t)
or auxiliary data (auxvar). You may write these functions as:
compute_dx(dx, nx, nu, x, u, p);
compute_y(y, nx, nu, x, u, p);
*/
/* Clean up. */
mxFree(p);
}
Let us go through the contents of this file. As a first observation, we can divide the work
of writing a C MEX model file into four separate sub-steps, the last one being optional:
6-57
6 ODE Parameter Estimation (Grey-Box Modeling)
Before we address these sub-steps in more detail, let us briefly comment upon a couple of
general features of the C programming language.
A. High-precision variables (all inputs, states, outputs and
parameters of an IDNLGREY object) should be defined to be of the
data type "double".
B. The unary * operator placed just in front of the variable or
parameter names is a so-called dereferencing operator. The
C-declaration "double *A1;" specifies that A1 is a pointer to a
double variable. The pointer construct is a concept within C that
is not always that easy to comprehend. Fortunately, if the
declarations of the output/input variables of compute_y and
compute_x are not changed and all unpacked model parameters are
internally declared with a *, then there is no need to know more
about pointers from an IDNLGREY modeling point of view.
C. Both compute_y and compute_dx are first declared and implemented,
where after they are called in the main interface function. In the
declaration, the keyword "void" states explicitly that no value is
to be returned.
1. In the first sub-step we first include the C-libraries "mex.h" (required) and
"math.h" (required for more advanced mathematics). The number of outputs is also
declared per modeling file using a standard C-define:
/* Include libraries. */
#include "mex.h"
#include "math.h"
If desired, one may also include more C-libraries than the ones above.
The "math.h" library must be included whenever any state or output equation contains
more advanced mathematics, like trigonometric and square root functions. Below
is a selected list of functions included in "math.h" and the counterpart found within
MATLAB:
C-function MATLAB function
========================================
6-58
Creating IDNLGREY Model Files
Notice that the MATLAB functions are more versatile than the corresponding C-
functions, e.g., the former handle complex numbers, while the latter do not.
2-3. Next in the file we find the functions for updating the states, compute_dx, and
the output, compute_y. Both these functions hold argument lists, with the output to
be computed (dx or y) at position 1, after which follows all variables and parameters
required to compute the right-hand side(s) of the state and the output equations,
respectively.
All parameters are contained in the parameter array p. The first step in compute_dx
and compute_y is to unpack and name the parameters to be used in the subsequent
equations. In twotanks_c.c, compute_dx declares six parameter variables whose values
are determined accordingly:
/* Retrieve model parameters. */
double *A1, *k, *a1, *g, *A2, *a2;
A1 = p[0]; /* Upper tank area. */
k = p[1]; /* Pump constant. */
a1 = p[2]; /* Upper tank outlet area. */
g = p[3]; /* Gravity constant. */
A2 = p[4]; /* Lower tank area. */
a2 = p[5]; /* Lower tank outlet area. */
compute_y on the other hand does not require any parameter for computing the output,
and hence no model parameter is retrieved.
As is the case in C, the first element of an array is stored at position 0. Hence, dx[0]
in C corresponds to dx(1) in MATLAB (or just dx in case it is a scalar), the input u[0]
corresponds to u (or u(1)), the parameter A1[0] corresponds to A1, and so on.
In the example above, we are only using scalar parameters, in which case the overall
number of parameters Np equals the number of parameter objects Npo. If any vector or
matrix parameter is included in the model, then Npo < Np.
The scalar parameters are referenced as P[0] (P(1) or just P in a MATLAB file) and the
i:th vector element as P[i-1] (P(i) in a MATLAB file). The matrices passed to a C MEX
6-59
6 ODE Parameter Estimation (Grey-Box Modeling)
model file are different in the sense that the columns are stacked upon each other in
the obvious order. Hence, if P is a 2-by-2 matrix, then P(1, 1) is referred as P[0], P(2,
1) as P[1], P(1, 2) as P[2] and P(2, 2) as P[3]. See "Tutorials on Nonlinear Grey Box
Identification: An Industrial Three Degrees of Freedom Robot : C MEX-File Modeling of
MIMO System Using Vector/Matrix Parameters", idnlgreydemo8, for an example where
scalar, vector and matrix parameters are used.
The state and output update functions may also include other computations than just
retrieving parameters and computing right-hand side expressions. For execution speed,
one might, e.g., declare and use intermediate variables, whose values are used several
times in the coming expressions. The robot tutorial mentioned above, idnlgreydemo8, is a
good example in this respect.
compute_dx and compute_y are also able to handle an optional FileArgument. The
FileArgument data is passed to these functions in the auxvar variable, so that the first
component of FileArgument (a cell array) can be obtained through
4. The main interface function should almost always have the same content and for most
applications no modification whatsoever is needed. In principle, the only part that might
be considered for changes is where the calls to compute_dx and compute_y are made.
For static systems, one can leave out the call to compute_dx. In other situations, it might
be desired to only pass the variables and parameters referred in the state and output
equations. For example, in the output equation of the two tank system, where only one
state is used, one could very well shorten the input argument list to
compute_y(y, x);
6-60
Creating IDNLGREY Model Files
The input argument lists of compute_dx and compute_y might also be extended to
include further variables inferred in the interface function. The following integer
variables are computed and might therefore be passed on: nu (the number of inputs), nx
(the number of states), and np (here the number of parameter objects). As an example, nx
is passed to compute_y in the model investigated in the tutorial idnlgreydemo6.
The completed C MEX model file must be compiled before it can be used for IDNLGREY
modeling. The compilation can readily be done from the MATLAB command line as
mex MODFILENAME.c
Notice that the mex-command must be configured before it is used for the very first time.
This is also achieved from the MATLAB command line via
mex -setup
nlgr_m =
Continuous-time nonlinear grey-box model defined by 'twotanks_m' (MATLAB file):
nlgr_cmex =
Continuous-time nonlinear grey-box model defined by 'twotanks_c' (MEX-file):
6-61
6 ODE Parameter Estimation (Grey-Box Modeling)
Conclusions
In this tutorial we have discussed how to write IDNLGREY MATLAB and C MEX model
files. We finally conclude the presentation by listing the currently available IDNLGREY
model files and the tutorial/case study where they are being used. To simplify further
comparisons, we list both the MATLAB (naming convention FILENAME_m.m) and the
C MEX model files (naming convention FILENAME_c.c), and indicate in the tutorial
column which type of modeling approach that is being employed in the tutorial or case
study.
Tutorial/Case study MATLAB file C MEX-file
======================================================================
idnlgreydemo1 (MATLAB) dcmotor_m.m dcmotor_c.c
idnlgreydemo2 (C MEX) twotanks_m.m twotanks_c.c
idnlgreydemo3 (MATLAB) preys_m.m preys_c.c
(C MEX) predprey1_m.m predprey1_c.c
(C MEX) predprey2_m.m predprey2_c.c
idnlgreydemo4 (MATLAB) narendrali_m.m narendrali_c.c
idnlgreydemo5 (MATLAB) friction_m.m friction_c.c
idnlgreydemo6 (C MEX) signaltransmission_m.m signaltransmission_c.c
idnlgreydemo7 (C MEX) twobodies_m.m twobodies_c.c
idnlgreydemo8 (C MEX) robot_m.m robot_c.c
idnlgreydemo9 (MATLAB) cstr_m.m cstr_c.c
idnlgreydemo10 (MATLAB) pendulum_m.m pendulum_c.c
idnlgreydemo11 (C MEX) vehicle_m.m vehicle_c.c
idnlgreydemo12 (C MEX) aero_m.m aero_c.c
idnlgreydemo13 (C MEX) robotarm_m.m robotarm_c.c
The contents of these model files can be displayed in the MATLAB command window
through the command "type FILENAME_m.m" or "type FILENAME_c.c". All model files
are found in the directory returned by the following MATLAB command.
fullfile(matlabroot, 'toolbox', 'ident', 'iddemos', 'examples')
Additional Information
6-62
7
A time series is modeled by assuming it to be the output of a system that takes a white
noise signal e(t) of variance NV as its virtual input. The true measured input size of such
models is zero, and their governing equation takes the form y(t) = He(t), where y(t) is
the signal being modeled and H is the transfer function that represents the relationship
between y(t) and e(t). The power spectrum of the time series is given by H*(NV*Ts)*H',
where NV is the noise variance and Ts is the model sample time.
System Identification Toolbox software provides tools for modeling and forecasting
time-series data. You can estimate both linear and nonlinear black-box and grey-box
models for time-series data. A linear time-series model can be a polynomial (idpoly)
or state-space (idss, idgrey) model. Some particular types of models are parametric
autoregressive (AR), autoregressive and moving average (ARMA), and autoregressive
models with integrated moving average (ARIMA).
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.
The following example illustrates a 4th order autoregressive model estimation for time
series data:
load iddata9
sys = ar(z9,4);
Because the model has no measured inputs, size(sys,2) returns zero. The governing
equation of sys is A(q)y(t) = e(t). You can access the A polynomial using sys.a and the
estimated variance of the noise e(t) using sys.NoiseVariance.
7-2
Preparing Time-Series Data
For more information about preparing data for modeling, see “Ways to Prepare Data for
System Identification” on page 2-6.
If your data is already in the MATLAB workspace, you can import it directly into the
System Identification app. If you prefer to work at the command line, you must represent
the data as a System Identification Toolbox data object instead.
In the System Identification app. When you import scalar or multiple-output time
series data into the app, leave the Input field empty. For more information about
importing data, see “Represent Data”.
s contains as many columns as there are measured outputs and Ts is the sample time.
7-3
7 Time Series Identification
In this section...
“How to Estimate Time-Series Power Spectra Using the App” on page 7-4
“How to Estimate Time-Series Power Spectra at the Command Line” on page 7-5
1 In the System Identification app, select Estimate > Spectral Models to open the
Spectral Model dialog box.
2 In the Method list, select the spectral analysis method you want to use. For
information about each method, see “Selecting the Method for Computing Spectral
Models” on page 3-11.
3 Specify the frequencies at which to compute the spectral model in either of the
following ways:
For time-domain data, the frequency ranges from 0 to the Nyquist frequency. For
frequency-domain data, the frequency ranges from the smallest to the largest
frequency in the data set.
7-4
Estimate Time-Series Power Spectra
To export the model to the MATLAB workspace, drag it to the To Workspace rectangle
in the System Identification app. You can view the power spectrum and the confidence
intervals of the resulting idfrd model object using the bode command.
You must have already prepared your data, as described in “Preparing Time-Series Data”
on page 7-3.
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.
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.
7-5
7 Time Series Identification
For example, suppose y is time-series data. The following commands estimate the power
spectrum g and the periodogram p, and plot both models with three standard deviation
confidence intervals:
g = spa(y);
p = etfe(y);
spectrum(g,p);
For detailed information about these commands, see the corresponding reference pages.
7-6
Estimate AR and ARMA Models
The ARMA model for a single-output time-series is given by the following equation:
A( q) y( t) = C( q) e( t)
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 Polynomial Models?” on
page 3-40.
For information on models containing noise integration see “Estimate ARIMA Models” on
page 7-15
7-7
7 Time Series Identification
1 In the System Identification app, select Estimate > Polynomial Models to open
the Polynomial Models dialog box.
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 Polynomial Models dialog box to correspond
with this model structure. For information about each model structure, see
“Definition of AR and ARMA Models” on page 7-7.
• For single-output models. Enter the model orders according to the sequence
displayed in the Structure field.
• For multiple-output ARX models. Enter the model orders directly, as
described in “Polynomial Sizes and Orders of Multi-Output Polynomial Models”.
Alternatively, enter the name of the matrix NA in the MATLAB Workspace
browser that stores model orders, which is Ny-by-Ny.
Tip To enter model orders and delays using the Order Editor dialog box, click Order
Editor.
4 (AR models only) Select the estimation Method as ARX or IV (instrumental
variable method). For more information about these methods, see “Polynomial Model
Estimation Algorithms”.
7-8
Estimate AR and ARMA Models
7 In the Initial state list, specify how you want the algorithm to treat initial states.
For more information about the available options, see “Specifying Initial States for
Iterative Estimation Algorithms”.
Tip If you get an inaccurate fit, try setting a specific method for handling initial
states rather than choosing it automatically.
8 In the Covariance list, select Estimate if you want the algorithm to compute
parameter uncertainties. Effects of such uncertainties are displayed on plots as
model confidence regions.
You can export the model to the MATLAB workspace for further analysis by dragging it
to the To Workspace rectangle in the System Identification app.
7-9
7 Time Series Identification
The following table summarizes the commands and specifies whether single-output or
multiple-output models are supported.
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:
7-10
Estimate State-Space Time-Series Models
where T is the sampling interval and y(kT) is the output at time instant kT.
The time-series structure corresponds to the general structure with empty B and D
matrices.
For information about general discrete-time and continuous-time structures for state-
space models, see “What Are State-Space Models?” on page 4-2.
The following table provides a brief description of each command. The resulting models
are idss model objects. You can estimate either continuous-time, or discrete-time models
using these commands.
Command Description
n4sid Noniterative subspace method for estimating linear state-
space models.
ssest Estimates linear time-series models using an iterative
estimation method that minimizes the prediction error.
7-11
7 Time Series Identification
Estimate covariance.
z = [y.y ; zeros(25,1)];
j=1:200;
Ryh = zeros(25,1);
for k=1:25,
a = z(j,:)'*z(j+k-1,:);
Ryh(k) = Ryh(k)+conj(a(:));
end
Ryh = Ryh/200; % biased estimate
Ryh = [Ryh(end:-1:2); Ryh];
Alternatively, you can use the Signal Processing Toolbox command xcorr.
7-12
Identify Time-Series Models at Command Line
7-13
7 Time Series Identification
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 7-3.
For black-box modeling of time-series data, the toolbox supports nonlinear ARX models.
To learn how to estimate this type of model, see “Identifying Nonlinear ARX Models” on
page 5-7.
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 6-15. See also
“Estimating Coefficients of ODEs to Fit Given Solution” on page 6-39 for an example of
time series modeling using the grey-box approach.
For more information about validating models, see “Validating Models After Estimation”
on page 10-2.
7-14
Estimate ARIMA Models
where the term represents the discrete-time integrator. Similarly, you can
formulate the equations for ARI and ARIX models.
Using time-series model estimation commands ar, arx and armax you can introduce
integrators into the noise source e(t). You do this by using the IntegrateNoise
parameter in the estimation command.
The estimation approach does not account any constant offsets in the time-series data.
The ability to introduce noise integrator is not limited to time-series data alone. You
can do so also for input-output models where the disturbances might be subject to
seasonality. One example is the polynomial models of ARIMAX structure:
load iddata9 z9
Ts = z9.Ts;
y = cumsum(z9.y);
model = ar(y,4,'ls','Ts',Ts,'IntegrateNoise', true);
% 5 step ahead prediction
7-15
7 Time Series Identification
compare(y,model,5)
Estimate a multivariate time-series model such that the noise integration is present in
only one of the two time series.
load iddata9 z9
Ts = z9.Ts;
y = z9.y;
y2 = cumsum(y);
% artificially construct a bivariate time series
data = iddata([y, y2],[],Ts); na = [4 0; 0 4];
nc = [2;1];
model1 = armax(data, [na nc], 'IntegrateNoise',[false; true]);
% Forecast the time series 100 steps into future
7-16
Estimate ARIMA Models
yf = forecast(model1,data(1:100), 100);
plot(data(1:100),yf)
If the outputs were coupled ( na was not a diagonal matrix), the situation will be more
complex and simply adding an integrator to the second noise channel will not work.
7-17
7 Time Series Identification
Test Data
load marple
Most of the routines in System Identification Toolbox™ support complex data. For
plotting we examine the real and imaginary parts of the data separately, however.
7-18
Spectrum Estimation Using Complex Data - Marple's Test Case
per = etfe(marple);
w = per.Frequency;
clf
h = spectrumplot(per,w);
opt = getoptions(h);
opt.FreqScale = 'linear';
opt.FreqUnits = 'Hz';
setoptions(h,opt)
7-19
7 Time Series Identification
Since the data record is only 64 samples, and the periodogram is computed for 128
frequencies, we clearly see the oscillations from the narrow frequency window. We
therefore apply some smoothing to the periodogram (corresponding to a frequency
resolution of 1/32 Hz):
sp = etfe(marple,32);
spectrumplot(per,sp,w);
7-20
Spectrum Estimation Using Complex Data - Marple's Test Case
7-21
7 Time Series Identification
The default window length gives a very narrow lag window for this small amount of data.
We can choose a larger lag window by:
ss20 = spa(marple,20);
spectrumplot(sp,'b',ss20,'g',w,opt);
legend({'Smoothed periodogram','Blackman-Tukey estimate'});
7-22
Spectrum Estimation Using Complex Data - Marple's Test Case
t5 = ar(marple,5);
spectrumplot(sp,'b',t5,'g',w,opt);
legend({'Smoothed periodogram','5th order AR estimate'});
7-23
7 Time Series Identification
The AR-command in fact covers 20 different methods for spectrum estimation. The above
one was what is known as 'the modified covariance estimate' in Marple's book.
7-24
Spectrum Estimation Using Complex Data - Marple's Test Case
AR-modeling can also be done using the Instrumental Variable approach. For this, we
use the function ivar:
ti = ivar(marple,4);
spectrumplot(t5,ti,w,opt);
legend({'Modified covariance','Instrumental Variable'})
7-25
7 Time Series Identification
7-26
Spectrum Estimation Using Complex Data - Marple's Test Case
Additional Information
7-27
7 Time Series Identification
To avoid ambiguity in how the software treats a time-series model, you can transform it
explicitly into an input-output model using noise2meas. This command causes the noise
input e(t) to be treated as a measured input and transforms the linear time series model
with Ny outputs into an input-output model with Ny outputs and Ny inputs. You can use
the resulting model with commands, such as, bode, nyquist, and iopzmap to study the
characteristics of the H transfer function. For example:
iosys = noise2meas(sys);
% step response of H if the step command was applied
% to the noise source e(t)
step(iosys)
% poles and zeros of H
iopzmap(iosys)
You can calculate and plot the time-series spectrum directly (without conversion using
noise2meas) using spectrum. For example:
spectrum(sys)
2
F(w ) = H (w)
7-28
8
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.
For more information, see “Recursive Estimation and Data Segmentation Techniques
in System Identification Toolbox™” on page 8-12. For detailed information about
recursive parameter estimation algorithms, see the corresponding chapter in System
Identification: Theory for the User by Lennart Ljung (Prentice Hall PTR, Upper Saddle
River, NJ, 1999).
At the command line, you can recursively estimate linear polynomial models, such as
ARX, ARMAX, Box-Jenkins, and Output-Error models. For time-series data containing
no inputs and a single output, you can estimate AR (autoregressive) and ARMA
(autoregressive and moving average) single-output models.
8-2
Data Supported for Recursive Estimation
• Matrix of the form [y u], where y represents the output data using one or more
column vectors. u represents the input data using one or more column vectors.
• iddata object.
Related Examples
• “Recursive Estimation and Data Segmentation Techniques in System Identification
Toolbox™”
More About
• “What Is Recursive Estimation?” on page 8-2
• “Algorithms for Recursive Estimation”
• “Preliminary Step – Estimating Model Orders and Input Delays”
• “Polynomial Sizes and Orders of Multi-Output Polynomial Models”
8-3
8 Recursive Model Identification
You specify the type of recursive estimation algorithms as arguments in the recursive
estimation commands.
For detailed information about these algorithms, see the corresponding chapter in
System Identification: Theory for the User by Lennart Ljung (Prentice Hall PTR, Upper
Saddle River, NJ, 1999).
qˆ ( t ) = qˆ ( t - 1) + K ( t ) ( y ( t ) - yˆ ( t ) )
q̂ ( t) is the parameter estimate at time t. y(t) is the observed output at time t and ŷ ( t )
is the prediction of y(t) based on observations up to time t-1. The gain, K(t), determines
how much the current prediction error y ( t ) - yˆ ( t ) affects the update of the parameter
estimate. The estimation algorithms minimize the prediction-error term y ( t ) - yˆ ( t ) .
8-4
Algorithms for Recursive Estimation
K ( t ) = Q ( t) y ( t )
The recursive algorithms supported by the System Identification Toolbox product differ
based on different approaches for choosing the form of Q(t) and computing y ( t ) , where
y ( t ) represents the gradient of the predicted model output yˆ ( t| q) with respect to the
parameters q .
The simplest way to visualize the role of the gradient y ( t ) of the parameters, is to
consider models with a linear-regression form:
y ( t ) = yT ( t) q0 ( t ) + e ( t )
In this equation, y ( t ) is the regression vector that is computed based on previous values
of measured inputs and outputs. q0 ( t ) represents the true parameters. e(t) is the noise
source (innovations), which is assumed to be white noise. The specific form of y ( t )
depends on the structure of the polynomial model.
For linear regression equations, the predicted output is given by the following equation:
yˆ ( t ) = yT ( t) qˆ ( t - 1 )
For models that do not have the linear regression form, it is not possible to compute
exactly the predicted output and the gradient y ( t ) for the current parameter estimate
q̂ ( t - 1 ) . To learn how you can compute approximation for y ( t ) and q̂ ( t - 1 ) for general
model structures, see the section on recursive prediction-error methods in System
Identification: Theory for the User by Lennart Ljung (Prentice Hall PTR, Upper Saddle
River, NJ, 1999).
8-5
8 Recursive Model Identification
The following set of equations summarizes the Kalman filter adaptation algorithm:
qˆ ( t ) = qˆ ( t - 1) + K ( t ) ( y ( t ) - yˆ ( t ) )
yˆ ( t ) = yT ( t) qˆ ( t - 1 )
K ( t ) = Q ( t) y ( t )
P ( t - 1) y ( t )
Q (t ) =
R2 + y T ( t ) P ( t - 1) y ( t )
T
P ( t - 1 ) y ( t) y ( t ) P ( t - 1 )
P ( t ) = P ( t - 1) + R1 -
T
R2 + y ( t ) P ( t - 1 ) y ( t )
y ( t ) = yT ( t) q0 ( t ) + e ( t )
This formulation also assumes that the true parameters q0 ( t ) are described by a random
walk:
q0 ( t ) = q0 ( t - 1) + w ( t )
w(t) is Gaussian white noise with the following covariance matrix, or drift matrix R1:
Ew ( t ) wT ( t ) = R1
8-6
Algorithms for Recursive Estimation
y ( t ) = yT ( t) q0 ( t ) + e ( t )
The Kalman filter algorithm is entirely specified by the sequence of data y(t), the
gradient y ( t ) , R1, R2, and the initial conditions q ( 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.
The general syntax for the command described in “Algorithms for Recursive Estimation”
on page 8-4 is the following:
[params,y_hat]=command(data,nn,adm,adg)
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 8-6).
The following set of equations summarizes the forgetting factor adaptation algorithm:
qˆ ( t ) = qˆ ( t - 1) + K ( t ) ( y ( t ) - yˆ ( t ) )
yˆ ( t ) = yT ( t) qˆ ( t - 1 )
K ( t ) = Q ( t) y ( t )
8-7
8 Recursive Model Identification
P ( t - 1)
Q (t ) =
T
l+y ( t ) P ( t - 1 ) y ( t)
Ê P ( t - 1) y ( t ) y ( t ) P ( t - 1 ) ˆ
T
P (t ) = (t - 1) -
1 ÁP ˜
lÁ
( ) ( ) ( ) ˜¯
T
Ë l + y t P t - 1 y t
t
 k=1 l t-k ( y(k) - y(k))2
This approach discounts old measurements exponentially such that an observation that
is t samples old carries a weight that is equal to l t times the weight of the most recent
observation. t = 1 1-l represents the memory horizon of this algorithm. Measurements
older than t = 1 1-l typically carry a weight that is less than about 0.3.
l is called the forgetting factor and typically has a positive value between 0.97 and
0.995.
Note: In the linear regression case, the forgetting factor algorithm is known as the
recursive least-squares (RLS) algorithm. The forgetting factor algorithm for l = 1 is
equivalent to the Kalman filter algorithm with R1=0 and R2=1. For more information
about the Kalman filter algorithm, see “Kalman Filter Algorithm” on page 8-5.
The general syntax for the command described in “Algorithms for Recursive Estimation”
on page 8-4 is the following:
[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 l (described in “Mathematics of the Forgetting Factor Algorithm” on
page 8-7).
8-8
Algorithms for Recursive Estimation
In the linear regression case, the gradient methods are also known as the least mean
squares (LMS) methods.
The following set of equations summarizes the unnormalized gradient and normalized
gradient adaptation algorithm:
qˆ ( t ) = qˆ ( t - 1) + K ( t ) ( y ( t ) - yˆ ( t ) )
yˆ ( t ) = yT ( t) qˆ ( t - 1 )
K ( t ) = Q ( t) y ( t )
In the unnormalized gradient approach, Q(t) is the product of the gain g and the identity
matrix:
Q( t) = g * y (t)
In the normalized gradient approach, Q(t) is the product of the gain g , and the identity
matrix is normalized by the magnitude of the gradient y ( t ) :
g * y(t)
Q (t ) =
2
y (t )
These choices of Q(t) update the parameters in the negative gradient direction, where the
gradient is computed with respect to the parameters.
8-9
8 Recursive Model Identification
The general syntax for the command described in “Algorithms for Recursive Estimation”
on page 8-4 is the following:
[params,y_hat]=command(data,nn,adm,adg)
To specify the unnormalized gain algorithm, set adm to 'ug' and adg to the value of
the gain g (described in “Mathematics of the Unnormalized and Normalized Gradient
Algorithm” on page 8-9).
To specify the normalized gain algorithm, set adm to 'ng' and adg to the value of the
gain g .
8-10
Data Segmentation
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.
To see an example of using data segmentation, run the Recursive Estimation and Data
Segmentation demonstration by typing to the following command at the prompt:
iddemo5
8-11
8 Recursive Model Identification
Introduction
The recursive estimation functions include RPEM, RPLR, RARMAX, RARX, ROE, and
RBJ. These algorithms implement all the recursive algorithms described in Chapter 11 of
Ljung(1987).
RPEM is the general Recursive Prediction Error algorithm for arbitrary multiple-input-
single-output models (the same models as PEM works for).
PRLR is the general Recursive PseudoLinear Regression method for the same family of
models.
RARX is a more efficient version of RPEM (and RPLR) for the ARX-case.
ROE, RARMAX and RBJ are more efficient versions of RPEM for the OE, ARMAX, and
BJ cases (compare these functions to the off-line methods).
Adaptation Schemes
Each one of the algorithms implement the four most common adaptation principles:
KALMAN FILTER approach: The true parameters are supposed to vary like a random
walk with incremental covariance matrix R1.
GRADIENT method: The update step is taken as a gradient step of length gamma
(th_new = th_old + gamma*psi*epsilon).
8-12
Recursive Estimation and Data Segmentation Techniques in System Identification Toolbox™
Analysis Data
In order to illustrate some of these schemes, let us pick a model and generate some input-
output data:
u = sign(randn(50,1)); % input
e = 0.2*randn(50,1); % noise
th0 = idpoly([1 -1.5 0.7],[0 1 0.5],[1 -1 0.2]); % a low order idpoly model
opt = simOptions('AddNoise',true,'NoiseData',e);
y = sim(th0,u,opt);
z = iddata(y,u);
plot(z) % analysis data object
8-13
8 Recursive Model Identification
First we build an Output-Error model of the data we just plotted. Use a second order
model with one delay, and apply the forgetting factor algorithm with lambda = 0.98:
8-14
Recursive Estimation and Data Segmentation Techniques in System Identification Toolbox™
Now let us try a second order ARMAX model, using the RPLR approach (i.e. ELS) with
Kalman filter adaptation, assuming a parameter variance of 0.001:
8-15
8 Recursive Model Identification
8-16
Recursive Estimation and Data Segmentation Techniques in System Identification Toolbox™
So far we have assumed that all data are available at once. We are thus studying the
variability of the system rather than doing real on-line calculations. The algorithms are
also prepared for such applications, but they must then store more update information.
The conceptual update then becomes:
Thus the previous estimate th is fed back into the algorithm along with the previous
value of the "P-matrix" and the data vector phi.
We now do an example of this where we plot just the current value of th.
8-17
8 Recursive Model Identification
The command SEGMENT segments data that are generated from systems that may
undergo abrupt changes. Typical applications for data segmentation are segmentation of
8-18
Recursive Estimation and Data Segmentation Techniques in System Identification Toolbox™
speech signals (each segment corresponds to a phonem), failure detection (the segments
correspond to operation with and without failures) and estimating different working
modes of a system. We shall study a system whose time delay changes from two to one.
load iddemo6m.mat
z = iddata(z(:,1),z(:,2));
plot(z)
The change takes place at sample number 20, but this is not so easy to see. We would
like to estimate the system as an ARX-structure model with one a-parameter, two b-
parameters and one delay:
8-19
8 Recursive Model Identification
The three pieces of information to be given are: the data, the model orders, and a guess of
the variance (r2) of the noise that affects the system. If the variance is entirely unknown,
it can be estimated automatically. Here we set it to 0.1:
nn = [1 2 1];
[seg,v,tvmod] = segment(z,nn,0.1);
Let's take a look at the segmented model. On light-colored axes, the lines for the
parameters a, b1 and b2 appear in blue, green, and red colors, respectively. On dark
colored axes, these lines appear in yellow, magenta, and cyan colors, respectively.
plot(seg)
hold on
8-20
Recursive Estimation and Data Segmentation Techniques in System Identification Toolbox™
We see clearly the jump around sample number 19. b1 goes from 0 to 1 and b2 vice versa,
which shows the change of the delay. The true values can also be shown:
plot(pars)
hold off
The method for segmentation is based on AFMM (adaptive forgetting through multiple
models), Andersson, Int. J. Control Nov 1985. A multi-model approach is used in a first
step to track the time varying system. The resulting tracking model could be of interest
in its own right, and are given by the third output argument of SEGMENT (tvmod in our
case). They look as follows:
plot(tvmod)
8-21
8 Recursive Model Identification
From the tracking model, SEGMENT estimates the time points when jumps have
occurred, and constructs the segmented model by a smoothing procedure over the
tracking model.
The two most important "knobs" for the algorithm are r2, as mentioned before, and the
guessed probability of jumps, q, the fourth input argument to SEGMENT. The smaller
r2 and the larger q, the more willing SEGMENT will be to indicate segmentation points.
In an off line situation, the user will have to try a couple of choices (r2 is usually more
sensitive than q). The second output argument to SEGMENT, v, is the loss function for
8-22
Recursive Estimation and Data Segmentation Techniques in System Identification Toolbox™
the segmented model (i.e. the estimated prediction error variance for the segmented
model). A goal will be to minimize this value.
The reflected signal from a laser (or radar) beam contains information about the distance
to the reflecting object. The signals can be quite noisy. The presence of objects affects
both the distance information and the correlation between neighboring points. (A smooth
object increases the correlation between nearby points.)
In the following we study some quite noisy laser range data. They are obtained by one
horizontal sweep, like one line on a TV-screen. The value is the distance to the reflecting
object. We happen to know that an object of interest hides between sample numbers 17
and 48.
plot(hline)
8-23
8 Recursive Model Identification
The eye is not good at detecting the object. We shall use "segment". First we detrend and
normalize the data to a variance about one. (This is not necessary, but it means that the
default choices in the algorithm are better tuned).
hline = detrend(hline)/200;
y(t) + a y(t-1) = b
The coefficient 'a' will pick up correlation information. The value 'b' takes up the possible
changes in level. We thus introduce a fake input of all ones:
[m,n] = size(hline);
8-24
Recursive Estimation and Data Segmentation Techniques in System Identification Toolbox™
The segmentation has thus been quite successful. SEGMENT is capable of handling
multi-input systems, and of using ARMAX models for the added noise. We can try this on
the test data iddata1.mat (which contains no jumps):
load iddata1.mat
s = segment(z1(1:100),[2 2 2 1],1);
clf
plot(s),hold on
8-25
8 Recursive Model Identification
8-26
Recursive Estimation and Data Segmentation Techniques in System Identification Toolbox™
SEGMENT thus correctly finds that no jumps have occurred, and also gives good
estimates of the parameters.
Additional Information
8-27
8-28
9
Online Estimation
• Adaptive control — Estimate a plant model to modify the controller based on changes
in the plant model.
• Fault detection — Compare the online plant model with the idealized/reference plant
model to detect a fault (anomaly) in the plant.
• Soft sensing — Generate a “measurement” based on the estimated plant model, and
use this measurement for feedback control or fault detection.
• Verify the experiment-data quality before starting offline estimation — Before using
the measured data for offline estimation, perform online estimation for a small
number of iterations. The online estimation provides a quick check of whether the
experiment used excitation signals that captured the relevant system dynamics. Such
a check is useful because offline estimation can be time intensive.
The System Identification Toolbox software provides the Recursive Least Squares
Estimator and Recursive Polynomial Model Estimator blocks to perform online
estimation using Simulink. You can also estimate a state-space model online from these
models by using the Recursive Polynomial Model Estimator and Model Type Converter
blocks together. You can generate C/C++ code and Structured Text for these blocks using
products such as Simulink Coder and Simulink PLC Coder™. Use the generated code
9-2
What Is Online Estimation?
to deploy online estimation to an embedded target. For example, you can estimate the
insulation characteristics of a room from measured input-output data and feed them to
the controller for the heating/cooling system. After validating the online estimation in
simulation, you can generate code for your Simulink model and deploy the same to the
target hardware.
Requirements
When you perform online estimation using the Recursive Least Squares Estimator and
Recursive Polynomial Model Estimator blocks, the following requirements apply:
• Model must be discrete-time linear or nearly linear with parameters that vary slowly
with respect to time.
• Structure of the estimated model must be fixed while the Simulink model is running.
References
[1] Ljung, L. System Identification: Theory for the User. Upper Saddle River, NJ:
Prentice-Hall PTR, 1999, pp. 428–440.
See Also
Kalman Filter | Recursive Least Squares Estimator | Recursive Polynomial Model
Estimator
Related Examples
• “Online Recursive Least Squares Estimation” on page 9-19
• “Online ARMAX Polynomial Model Estimation” on page 9-32
• “Generate Online Estimation Code” on page 9-12
More About
• “How Online Estimation Differs from Offline Estimation” on page 9-4
• “Recursive Algorithms for Online Estimation” on page 9-14
9-3
9 Online Estimation
Use the Recursive Least Squares Estimator and Recursive Polynomial Model Estimator
blocks to perform online estimation. Use tools such as arx, pem, ssest, tfest, nlarx,
and the System Identification app to perform offline estimation.
• Model delays — You can estimate model delays in offline estimation using tools
such as delayest (see “Determining Model Order and Delay”). Online estimation,
however, provides limited ability to handle delays. For polynomial model estimation
using the Recursive Polynomial Model Estimation block, you can specify as
known value of the input delay (nk) in the block dialog. If nk is unknown, choose a
sufficiently large value for the number of coefficients of B (nb). The input delay is
indicated by the number of leading coefficients of the B polynomial that are close to
zero.
• Data preprocessing — For offline estimation data preprocessing, you can use
functions such as detrend, retrend, idfilt, and the System Identification app.
For online estimation, however, you must use the tools available in the Simulink
environment. (See “Preprocess Online Estimation Data” on page 9-6.)
• Reset estimation — Online estimation allows you to reset the estimation at a specific
time step during estimation. For example, reset the estimation when the system
changes modes. In contrast, you cannot reset an offline estimation.
To reset estimation, in the online estimation block’s dialog, select the Algorithm and
Block Options tab. Select the appropriate External reset option.
• Enable/disable estimation — Online estimation allows you to enable/disable
estimation for chosen time spans. For example, suppose the measured data is
especially noisy or faulty (contains many outliers) for a specific time interval. Disable
online estimation for this interval. You cannot selectively enable/disable offline
estimation.
9-4
How Online Estimation Differs from Offline Estimation
More About
• “What Is Online Estimation?” on page 9-2
9-5
9 Online Estimation
Use the tools in the Simulink software to preprocess data for online estimation. Common
tools to perform data preprocessing in Simulink are:
• Blocks in the “Math Operations” library. Use these blocks, for example, to subtract or
add an offset or normalize a signal.
• Blocks in the “Continuous” and “Discrete” library. Use these blocks, for example, to
filter a signal.
• Rate Transition block, which allows you to handle the transfer of data between blocks
operating at different rates. Use this block, for example, to resample your data from a
source that is operating at a different sampling rate than the online estimation block.
• MATLAB Function block, which allows you to include MATLAB code in your model.
Use this block, for example, to implement a custom preprocessing algorithm.
See “Online ARMAX Polynomial Model Estimation” on page 9-32 for an example of
how you can preprocess an estimation input signal by removing its mean.
See Also
Kalman Filter | Recursive Least Squares Estimator | Recursive Polynomial Model
Estimator
More About
• “What Is Online Estimation?” on page 9-2
9-6
Validate Online Estimation Results
• Examine the estimation error (residuals), which is the difference between the
measured and estimated outputs. For systems whose parameters are constant or vary
slowly with respect to time, the estimation generally takes some time to converge
(settle). During this initial period, the estimation error can be high. However, after
the estimation converges, a low estimation error value gives confidence in the
estimated values.
You can also analyze the residuals using techniques such as the whiteness test and
the independence test. For such analysis, use the measured data and estimation error
collected after the parameter values have settled to approximately constant values.
For more information regarding these tests, see “What Is Residual Analysis?”
To obtain the estimation error, in the Algorithm and Block Options tab of the
online estimation block’s dialog, select the Output estimation error check box. The
software adds an Error outport to the block, which you can monitor using a Scope
block. This outport provides the one-step-ahead estimation error, e(t) = y(t)–yest(t). For
the time step, t, y and yest are the measured and estimated outputs, respectively.
• Examine the parameter covariance matrix, which measures the estimation
uncertainty. A smaller covariance value gives confidence in the estimated values.
To obtain the parameter covariance, in the Algorithm and Block Options tab
of the online estimation block’s dialog, select the Output parameter covariance
matrix check box. The software adds a Covariance outport to the block, which you
can monitor using a Display block. This outport provides the parameter covariance
matrix.
• Simulate the estimated model and compare the simulated and measured outputs.
That is, feed the measured input into a model that uses the estimated parameter
values. Then, compare this system’s output with the measured output. The simulated
output closely matching the measured output gives confidence in the estimated
values.
For examples of such validation, see “Online Recursive Least Squares Estimation” on
page 9-19 and “Online ARMAX Polynomial Model Estimation” on page 9-32.
9-7
9 Online Estimation
If the validation indicates low confidence in the estimation, then see “Troubleshooting
Online Estimation” on page 9-9 for ideas on improving the quality of the fit.
See Also
Kalman Filter | Recursive Least Squares Estimator | Recursive Polynomial Model
Estimator
9-8
Troubleshooting Online Estimation
Validating the results of online estimation can indicate low confidence in the estimation
results. Try the following tips to improve the quality of the fit.
• Recursive least squares (RLS) estimation — Use the Recursive Least Squares
Estimator block to estimate a system that is linear in the parameters to be estimated.
Suppose the inputs to the RLS block are simply the time-shifted versions of some
fundamental input/output variables. You can estimate this system using an ARX
model structure instead. ARX models can express the time-shifted regressors using
the A and B parameters. The autoregressive term, A(q), allows representation of
dynamics using fewer coefficients than an RLS model. Also, configuring an ARX
structure is simpler, because you provide fewer inputs.
For example, the a and b parameters of the system y(t) = b1u(t)+b2u(t-1)-a1y(t-1) can
be estimated using either recursive least squares (RLS) or ARX models. The RLS
estimation requires you to provide u(t), u(t-1) and y(t-1) as regressors. An ARX model
eliminates this requirement because you can express these time-shifted parameters
using the A and B parameters. Therefore, you provide the Recursive Polynomial
Model Estimator block only u and y. For more information regarding ARX models, see
“What Are Polynomial Models?”.
• ARX and ARMAX models — Use the Recursive Polynomial Model Estimator block to
estimate ARX models (SISO and MISO) and ARMAX models (SISO). For information
about these models, see “What Are Polynomial Models?”
9-9
9 Online Estimation
The ARMAX model has more dynamic elements (C parameters) than the ARX model
to express noise. However, ARMAX models are more sensitive to initial guess values
than ARX models, and therefore require more careful initialization.
9-10
Troubleshooting Online Estimation
Related Examples
• “Validate Online Estimation Results” on page 9-7
More About
• “What Is Online Estimation?” on page 9-2
9-11
9 Online Estimation
1 Develop a Simulink model that simulates the online model estimation. For example,
create a model that simulates the input/output data, performs online estimation for
this data, and uses the estimated parameter values.
2 After validating the online estimation performance in simulation, create a subsystem
for the online estimation block. If you preprocess the inputs or postprocess the
parameter estimates, include the relevant blocks in the subsystem.
3 Convert the subsystem to a referenced model. You generate code for this referenced
model, so ensure that it uses only the blocks that support code generation. For a list
of blocks that support code generation, see “Simulink Built-In Blocks That Support
Code Generation”.
The original model, which now contains a model reference, is now referred to as the
top model.
4 In the top model, replace the model source and sink blocks with their counterpart
hardware blocks. For example, replace the simulated inputs/output blocks with the
relevant hardware source block. You generate code for this model, which includes the
online estimation. So, ensure that it uses only blocks that support code generation.
5 Generate code for the top model.
For details on configuring the subsystem and converting it to a referenced model, see the
“Generate Code for Referenced Models” example in the Simulink Coder documentation.
See Also
Kalman Filter | Model Type Converter | Recursive Least Squares Estimator | Recursive
Polynomial Model Estimator
9-12
Generate Online Estimation Code
Related Examples
• “Generate Code for Referenced Models”
More About
• “Code Generation for Referenced Models”
• “Simulink Built-In Blocks That Support Code Generation”
9-13
9 Online Estimation
qˆ ( t ) = qˆ ( t - 1) + K ( t ) ( y ( t ) - yˆ ( t ) )
q̂ ( t) is the parameter estimate at time t. y(t) is the observed output at time t and ŷ ( t )
is the prediction of y(t) based on observations up to time t-1. The gain, K(t), determines
how much the current prediction error y ( t ) - yˆ ( t ) affects the update of the parameter
estimate. The estimation algorithms minimize the prediction-error term y ( t ) - yˆ ( t ) .
K ( t ) = Q ( t) y ( t )
The recursive algorithms supported by the System Identification Toolbox product differ
based on different approaches for choosing the form of Q(t) and computing y ( t ) , where
y ( t ) represents the gradient of the predicted model output yˆ ( t| q) with respect to the
parameters q .
The simplest way to visualize the role of the gradient y ( t ) of the parameters, is to
consider models with a linear-regression form:
y ( t ) = yT ( t) q0 ( t ) + e ( t )
In this equation, y ( t ) is the regression vector that is computed based on previous values
of measured inputs and outputs. q0 ( t ) represents the true parameters. e(t) is the noise
9-14
Recursive Algorithms for Online Estimation
For linear regression equations, the predicted output is given by the following equation:
yˆ ( t ) = yT ( t) qˆ ( t - 1 )
For models that do not have the linear regression form, it is not possible to compute
exactly the predicted output and the gradient y ( t ) for the current parameter estimate
q̂ ( t - 1 ) . To learn how you can compute approximation for y ( t ) and q̂ ( t - 1 ) for general
model structures, see the section on recursive prediction-error methods in [1].
The forgetting factor and Kalman Filter formulations are more computationally intensive
than gradient and unnormalized gradient methods. However, they have much better
convergence properties.
Forgetting Factor
The following set of equations summarizes the forgetting factor adaptation algorithm:
qˆ ( t ) = qˆ ( t - 1) + K ( t ) ( y ( t ) - yˆ ( t ) )
yˆ ( t ) = yT ( t) qˆ ( t - 1 )
K ( t ) = Q ( t) y ( t )
9-15
9 Online Estimation
P ( t - 1)
Q (t ) =
T
l+y ( t ) P ( t - 1 ) y ( t)
Ê P ( t - 1) y ( t ) y ( t ) P ( t - 1 ) ˆ
T
P (t ) = 1 ÁP
(t - 1) - ˜
lÁ
( ) ( ) ( ) ˜¯
T
Ë l + y t P t - 1 y t
t
 k=1 l t-k ( y(k) - y(k))2
See section 11.2 in [1] for details.
This approach discounts old measurements exponentially such that an observation that
is t samples old carries a weight that is equal to l t times the weight of the most recent
observation. t = 1 1-l represents the memory horizon of this algorithm. Measurements
older than t = 1 1-l typically carry a weight that is less than about 0.3.
l is called the forgetting factor and typically has a positive value between 0.97 and
0.995.
Note: The forgetting factor algorithm for l = 1 is equivalent to the Kalman filter
algorithm with R1=0 and R2=1. For more information about the Kalman filter algorithm,
see “Kalman Filter” on page 9-16.
Kalman Filter
The following set of equations summarizes the Kalman filter adaptation algorithm:
qˆ ( t ) = qˆ ( t - 1) + K ( t ) ( y ( t ) - yˆ ( t ) )
yˆ ( t ) = yT ( t) qˆ ( t - 1 )
9-16
Recursive Algorithms for Online Estimation
K ( t ) = Q ( t) y ( t )
P ( t - 1) y ( t )
Q (t ) =
R2 + y T ( t ) P ( t - 1) y ( t )
T
P ( t - 1 ) y ( t) y ( t ) P ( t - 1 )
P ( t ) = P ( t - 1) + R1 -
T
R2 + y ( t ) P ( t - 1 ) y ( t )
y ( t ) = yT ( t) q0 ( t ) + e ( t )
This formulation also assumes that the true parameters q0 ( t ) are described by a random
walk:
q0 ( t ) = q0 ( t - 1) + w ( t )
w(t) is Gaussian white noise with the following covariance matrix, or drift matrix R1:
Ew ( t ) wT ( t ) = R1
y ( t ) = yT ( t) q0 ( t ) + e ( t )
The Kalman filter algorithm is entirely specified by the sequence of data y(t), the
gradient y ( t ) , R1, R2, and the initial conditions q ( t = 0 ) (initial guess of the parameters)
and P ( t = 0 ) (covariance matrix that indicates parameters errors).
Note: It is assumed that R1 and P(t = 0) matrices are scaled such that R2 = 1. This
scaling does not affect the parameter estimates.
9-17
9 Online Estimation
In the linear regression case, the gradient methods are also known as the least mean
squares (LMS) methods.
The following set of equations summarizes the unnormalized gradient and normalized
gradient adaptation algorithm:
qˆ ( t ) = qˆ ( t - 1) + K ( t ) ( y ( t ) - yˆ ( t ) )
yˆ ( t ) = yT ( t) qˆ ( t - 1 )
K ( t ) = Q ( t) y ( t )
Q( t) = g * y (t)
g * y(t)
Q (t ) =
2
y (t )
These choices of Q(t) update the parameters in the negative gradient direction, where the
gradient is computed with respect to the parameters. See pg. 372 in [1] for details.
References
[1] Ljung, L. System Identification: Theory for the User. Upper Saddle River, NJ:
Prentice-Hall PTR, 1999.
See Also
Recursive Least Squares Estimator | Recursive Polynomial Model Estimator
More About
• “What Is Online Estimation?” on page 9-2
9-18
Online Recursive Least Squares Estimation
Engine Model
The engine model includes nonlinear elements for the throttle and manifold system, and
the combustion system. The model input is the throttle angle and the model output is the
engine speed in rpm.
open_system('iddemo_engine');
sim('iddemo_engine')
9-19
9 Online Estimation
The engine model is set up with a pulse train driving the throttle angle from open to
closed. The engine response is nonlinear, specifically the engine rpm response time when
the throttle is open and closed are different.
At 100 seconds into the simulation an engine fault occurs causing the engine inertia to
increase (the engine inertia, J, is modeled in the iddemo_engine/Vehicle Dynamics
block). The inertia change causes engine response times at open and closed throttle
positions to increase. You use online recursive least squares to detect the inertia change.
open_system('iddemo_engine/rpm')
9-20
Online Recursive Least Squares Estimation
Estimation Model
The engine model is a damped second order system with input and output nonlinearities
to account for different response times at different throttle positions. Use the recursive
least squares block to identify the following discrete system that models the engine:
Since the estimation model does not explicitly include inertia we expect the values to
change as the inertia changes. We use the changing values to detect the inertia change.
The engine has significant bandwidth up to 16Hz. Set the estimator sampling frequency
to 2*160Hz or a sample time of seconds.
9-21
9 Online Estimation
open_system('iddemo_engine/Regressors');
• Parameter Covariance Matrix: 1e4, set high as we expect the parameter values to
vary from their initial guess.
• Sample Time: .
9-22
Online Recursive Least Squares Estimation
9-23
9 Online Estimation
• Forgetting Factor: 1-2e-4. Since the estimated values are expected to change
with the inertia, set the forgetting factor to a value less than 1. Choose = 1-2e-4
which corresponds to a memory time constant of or 15 seconds. A 15 second
memory time ensures that significant data from both the open and closed throttle
position are used for estimation as the position is changed every 10 seconds.
• Select the Output estimation error check box. You use this block output to validate
the estimation.
• Select the Output parameter covariance matrix check box. You use this block
output to validate the estimation.
9-24
Online Recursive Least Squares Estimation
9-25
9 Online Estimation
The Error output of the Recursive Least Squares Estimator block gives the one-
step-ahead error for the estimated model. This error is less than 5% indicating that for
one-step-ahead prediction the estimated model is accurate.
open_system('iddemo_engine/Error (%)')
9-26
Online Recursive Least Squares Estimation
The diagonal of the parameter covariances matrix gives the variances for the
parameters. The and variances are small relative to the parameter values
indicating good confidence in the estimated values. In contrast, the covariance is large
relative to the parameter values indicating a low confidence in these values.
9-27
9 Online Estimation
While the small estimation error and covariances give confidence that the model is being
estimated correctly, it is limited in that the error is a one-step-ahead predictor. A more
rigorous check is to use the estimated model in a simulation model and compare with the
actual model output. The Estimated Model section of the simulink model implements
this.
The Regressors1 block is identical to the Regressors block use in the recursive
estimator. The only difference is that the y signal is not measured from the plant but
fed back from the output of the estimated model. The Output of the regressors block
is multiplied by estimated values to give an estimate of the engine speed. The
values were taken from a snapshot of the estimated parameter values at 60 seconds.
open_system('iddemo_engine/rpm Est')
9-28
Online Recursive Least Squares Estimation
The estimated model output matches the model output fairly well. The steady-state
values are close and the transient behavior is slightly different but not significantly
so. Note that after 100 seconds when the engine inertia changes the estimated model
output differs more significantly from the model output. This difference is expected as
the estimated model parameters are fixed and the estimated model does not include any
information about the inertia change (the only model input is the throttle position).
The estimated model output combined with the low one-step-ahead error and parameter
covariances gives us confidence in the recursive estimator.
The engine model is setup to introduce an inertia change 100 seconds into the simulation.
The recursive estimator can be used to detect the change in inertia.
9-29
9 Online Estimation
The covariance for , 0.0001273, is large relative to the parameter value 0.9805
indicating low confidence in the estimated value. The time plot of shows why the
covariance is large. Specifically is varying as the throttle position varies indicating
that the estimated model is not rich enough to fully capture different rise times at
different throttle positions and needs to adjust . However, we can use this to identify
the inertia changes as the average value of changes as the inertia changes. You can
9-30
Online Recursive Least Squares Estimation
use a threshold detector on the moving average of the parameter to detect changes in
the engine inertia.
bdclose('iddemo_engine')
9-31
9 Online Estimation
9-32
Online ARMAX Polynomial Model Estimation
exothermic and irreversible reaction, A --> B, takes place. The inlet stream of reagent
A is fed to the tank at a constant rate. After stirring, the end product streams out of the
vessel at the same rate as reagent A is fed into the tank (the volume in the reactor tank
is constant). Details of the operation of the CSTR and its 2-state nonlinear model used
in this example are explained in the example “"Non-Adiabatic Continuous Stirred Tank
Reactor: MATLAB File Modeling with Simulations in Simulink"”
and the outputs (y(t)), which are also the states of the model (x(t)), are:
open_system('iddemo_cstr');
9-33
9 Online Estimation
The signal in this example contains a step change from 1.5 [kgmol/m^3] to 2
[kgmol/m^3] at time . In addition to this step change, also contains a
white noise perturbation for t in the [0,200) and [400,600) ranges. The power of this
white noise signal is 0.015. The noise power is adjusted empirically to approximately
give a signal-to-noise ratio of 10. Not having sufficient excitation in the reference signal
9-34
Online ARMAX Polynomial Model Estimation
It is known from the nonlinear model that the CSTR output is more sensitive to
the control input at higher levels. The Recursive Polynomial Model Estimator
block is used to detect this change in sensitivity. This information is used to adjust the
gains of the PI controller as varies. The aim is to avoid having a a high gain control
loop which may lead to instability.
The 'Recursive Polynomial Model Estimator' block is found under the System
Identification Toolbox/Estimators library in Simulink. You use this block to
estimate linear models with ARMAX structure. ARMAX models have the form:
• The Inputs and Output inport of the recursive polynomial model estimator
block correspond to and respectively. For the CSTR model and are
deviations from the jacket temperature and A concentration trim operating points:
, . It is good to scale and to have a peak
amplitude of 1 to improve the numerical condition of the estimation problem. The
trim operating points, and , are not known exactly before system operation.
9-35
9 Online Estimation
They are estimated and extracted from the measured signals by using a first-
order moving average filter. These preprocessing filters are implemented in the
iddemo_cstr/Preprocess Tj and iddemo_cstr/Preprocess CA blocks.
open_system('iddemo_cstr/Preprocess Tj');
• The optional Enable inport of the Recursive Polynomial Model Estimator block
controls the parameter estimation in the block. Parameter estimation is disabled
when the Enable signal is zero. Parameter estimation is enabled for all other values
of the Enable signal. In this example the estimation is disabled for the time intervals
and . During these intervals the measured input
does not contain sufficient excitation for closed-loop system identification.
Configure the block parameters to estimate a second-order ARMAX model. In the Model
Parameters tab, specify:
• Model Structure: ARMAX. Choose ARMAX since the current and past values of the
disturbances acting on the system, , are expected to impact the CSTR system
output .
• Initial Estimate: None. By default, the software uses a value of 0 for all estimated
parameters.
9-36
Online ARMAX Polynomial Model Estimation
• Input Delay (nk): 1. Like most physical systems, the CSTR system does not have
direct feedthrough. Also, there are no extra time delays between its I/Os.
• Parameter Covariance Matrix: 1e4. Specify a high covariance value because the
initial guess values are highly uncertain.
• Sample Time: 0.1. The CSTR model is known to have a bandwidth of about 0.25Hz.
chosen such that 1/0.1 is greater than 20 times this bandwidth (5Hz).
9-37
9 Online Estimation
9-38
Online ARMAX Polynomial Model Estimation
• Forgetting Factor: 1-5e-3. Since the estimated parameters are expected to change
with the operating point, set the forgetting factor to a value less than 1. Choose
which corresponds to a memory time constant of
seconds. A 100 second memory time ensures that a significant amount data used for
identification is coming from the 200 second identification period at each operating
point.
• Select the Output estimation error check box. You use this block output to validate
the estimation.
• Select the Add enable port check box. You only want to adapt the estimated
model parameters when extra noise is injected in the reference port. The parameter
estimation n is disabled through this port when the extra noise is no longer injected.
9-39
9 Online Estimation
9-40
Online ARMAX Polynomial Model Estimation
At every time step, the recursive polynomial model estimator provides an estimate
for , , , and the estimation error . The Error outport of the polynomial
model estimator block contains and is also known as the one-step-ahead prediction
error. The Parameters outport of the block contains the A(q), B(q), and C(q) polynomial
coefficients in a bus signal. Given the chosen polynomial orders ( , , ,
) the Parameters bus elements contain:
The estimated parameters in the A(q), B(q), and C(q) polynomials change during
simulation as follows:
sim('iddemo_cstr');
open_system('iddemo_cstr/ABC');
9-41
9 Online Estimation
The parameter estimates quickly change from their initial values of 0 due to the high
value chosen for the initial parameter covariance matrix. The parameters in the
and polynomials approach their values at rapidly. However, the parameters
in the polynomial show some fluctuations. One reason behind these fluctuations
is that the disturbance to CSTR output is not fully modelled by the ARMAX
structure. The error model is not important for the control problem studied here
9-42
Online ARMAX Polynomial Model Estimation
The parameter estimates are held constant for since the estimator block
was disabled for this interval (0 signal to the Enable inport). The parameter estimation
is enabled at when the CSTR tank starts switching to its new operating point.
The parameters of and converge to their new values by , and then held
constant by setting the Enable port to 0. The convergence of and is slower
at this operating point. This slow convergence is because of the smaller eigenvalues of
the parameter covariance matrix at t=400 compared to the initial 1e4 values set at t=0.
The parameter covariance, which is a measure of confidence in the estimates, is updated
with each time step. The algorithm quickly changed the parameter estimates when the
confidence in estimates were low at t=0. The improved parameter estimates capture
the system behavior better, resulting in smaller one-step-ahead prediction errors and
smaller eigenvalues in the parameter covariance matrix (increased confidence). The
system behavior changes in t=400. However, the block is slower to change the parameter
estimates due to the increased confidence in the estimates. You can use the External
Reset option of the Recursive Polynomial Model Estimator block to provide a new value
for parameter covariance at t=400. To see the value of the parameter covariance, select
the Output parameter covariance matrix check box in the Recursive Polynomial
Model Estimator block.
The Error output of the Recursive Polynomial Model Estimator block gives the
one-step-ahead error for the estimated model.
open_system('iddemo_cstr/Error');
9-43
9 Online Estimation
The one-step-ahead error is higher when there are no extra perturbations injected in the
channel for system identification. These higher errors may be caused by the lack
of sufficient information in the input channel that the estimator block relies on.
However, even this higher error is low and bounded when compared to the measured
fluctuations in . This gives confidence in the estimated parameter values.
A more rigorous check of the estimated model is to simulate the estimated model and
compare with the actual model output. The iddemo_cstr/Time-Varying ARMAX block
implements the time-varying ARMAX model estimated by the Online Polynomial Model
Estimator block. The error between the output of the CSTR system and the estimated
time-varying ARMAX model output is:
9-44
Online ARMAX Polynomial Model Estimation
open_system('iddemo_cstr/Simulation Error');
The simulation error is again bounded and low when compared to the fluctuations in
the . This further provides confidence that the estimated linear models are able to
predict the nonlinear CSTR model behavior.
The identified models can be further analyzed in MATLAB. The model estimates for the
operating points and can be obtained by looking
at the estimated A(q), B(q), and C(q) polynomials at and respectively.
Bode plots of these models are:
Ts = 0.1;
tidx = find(t>=200,1);
9-45
9 Online Estimation
P200 = idpoly(AHat(tidx,:),BHat(tidx,:),CHat(tidx,:),1,1,[],Ts);
tidx = find(t>=600,1);
P600 = idpoly(AHat(tidx,:),BHat(tidx,:),CHat(tidx,:),1,1,[],Ts);
bodemag(P200,'b',P600,'r--',{10^-1,20});
legend('Estimated Model at C_A=1.5 [kgmol/m^3]', ...
'Estimated Model at C_A=2.0 [kgmol/m^3]', ...
'Location', 'Best');
The estimated model has a higher gain at higher concentration levels. This is in
agreement with prior knowledge about the nonlinear CSTR plant. The transfer
function at has a higher gain (double the amplitude) at low
frequencies.
Summary
9-46
Online ARMAX Polynomial Model Estimation
You estimated two ARMAX models to capture the behavior of the nonlinear CSTR plant
at two operating conditions. The estimation was done during closed-loop operation with
an adaptive controller. You looked at two signals to validate the estimation results: One
step ahead prediction errors and the errors between the CSTR plant output and the
simulation of the estimation model. Both of these errors signals were bounded and small
compared to the CSTR plant output. This provided confidence in the estimated ARMAX
model parameters.
bdclose('iddemo_cstr');
9-47
9 Online Estimation
Introduction
You want to estimate the position and velocity of a ground vehicle in the north and
east directions. The vehicle can move freely in the two-dimensional space without any
constraints. You design a multi-purpose navigation and tracking system that can be used
for any object and not just a vehicle.
9-48
State Estimation Using Time-Varying Kalman Filter
and are the vehicle's east and north positions from the origin, is the
vehicle orientation from east and is the steering angle of the vehicle. is the
continuous-time variable.
9-49
9 Online Estimation
The Simulink model consists of two main parts: Vehicle model and the Kalman filter.
These are explained further in the following sections.
open_system('ctrlKalmanNavigationExample');
Vehicle Model
9-50
State Estimation Using Time-Varying Kalman Filter
The longitunidal dynamics of the model ignore tire rolling resistance. The lateral
dynamics of the model assume that the desired steering angle can be achieved
instantaneously and ignore the yaw moment of inertia.
where
9-51
9 Online Estimation
The terms denote velocities and not the derivative operator. is the discrete-time
index. The model used in the Kalman filter is of the form:
where is the state vector, is the measurements, is the process noise, and is the
measurement noise. Kalman filter assumes that and are zero-mean, independent
random variables with known variances , , and .
Here, the A, G, and C matrices are:
where
The third row of A and G model the east velocity as a random walk:
. In reality, position is a continuous-time variable
and is the integral of velocity over time . The first row of the A
and G represent a disrete approximation to this kinematic relationship:
. The second and fourth rows of the A and
G represent the same relationship between the north velocity and position.
The C matrix represents that only position measurements are available. A position
sensor, such as GPS, provides these measurements at the sample rate of 1Hz. The
9-52
State Estimation Using Time-Varying Kalman Filter
The elements of capture how much the vehicle velocity can change over one sample
time Ts. The variance of the process noise w, the Q matrix, is chosen to be time-varying.
It captures the intuition that typical values of are smaller when velocity is large.
For instance, going from 0 to 10m/s is easier than going from 10 to 20m/s. Concretely, you
use the estimated north and east velocities and a saturation function to construct Q[n]:
The diagonals of Q model the variance of w inversely proportional to the square of the
estimated velocities. The saturation function prevents Q from becoming too large or
small. The coefficient 250 is obtained from a least squares fit to 0-5, 5-10, 10-15, 15-20,
20-25m/s acceleration time data for a generic vehicle. Note that the diagonal Q implies
a naive approach that assumes that the velocity changes in north and east direction are
uncorrelated.
• Select the Use current measurement y[n] to improve the xhat[n] check box.
This implements the "current estimator" variant of the discrete-time Kalman filter.
9-53
9 Online Estimation
This option improves the estimation accuracy and is more useful for slow sample
times. However, it increases the computational cost. In addition, this Kalman filter
variant has direct feedthrough, which leads to an algebraic loop if the Kalman filter is
used in a feedback loop that does not contain any delays (the feedback loop itself also
has direct feedthrough). The algebraic loop can further impact the simulation speed.
Click the Options tab to set the block inport and outport options:
• Unselect the Add input port u check box. There are no known inputs in the plant
model.
• Select the Output state estimation error covariance Z check box. The Z matrix
provides information about the filter's confidence in the state estimates.
9-54
State Estimation Using Time-Varying Kalman Filter
9-55
9 Online Estimation
Click Model Parameters to specify the plant model and noise characteristics:
• Initial states x[0]: 0. This represents an initial guess of 0 for the position and
velocity estimates at t=0s.
• State estimation error covariance P[0]: 10. Assume that the error between your
initial guess x[0] and its actual value is a random variable with a standard deviation
.
• Select the Use G and H matrices (defalut G=I and H=0) check box to specify a
non-default G matrix.
• H: 0. The process noise does not impact the measurments y entering the Kalman filter
block.
• Sample time (-1 for inherited): Ts, which is defined earlier in this example.
9-56
State Estimation Using Time-Varying Kalman Filter
9-57
9 Online Estimation
Results
Test the performance of the Kalman filter by simulating a scenario where the vehicle
makes the following maneuvers:
• At t = 260s, it decelerates to 15m/s and makes a constant speed 180 degree turn.
Simulate the Simulink model. Plot the actual, measured and Kalman filter estimates of
vehicle position.
sim('ctrlKalmanNavigationExample');
figure(1);
% Plot results and connect data points with a solid line.
plot(x(:,1),x(:,2),'bx',...
y(:,1),y(:,2),'gd',...
xhat(:,1),xhat(:,2),'ro',...
'LineStyle','-');
title('Position');
xlabel('East [m]');
ylabel('North [m]');
legend('Actual','Measured','Kalman filter estimate','Location','Best');
axis tight;
9-58
State Estimation Using Time-Varying Kalman Filter
The error between the measured and actual position as well as the error between the
kalman filter estimate and actual position is:
figure(2);
% East Position Errors
9-59
9 Online Estimation
subplot(2,1,1);
plot(t,n_xe,'g',t,e_xe,'r');
ylabel('Position Error - East [m]');
xlabel('Time [s]');
legend(sprintf('Meas: %.3f',norm(n_xe,1)/numel(n_xe)),sprintf('Kalman f.: %.3f',norm(e_
axis tight;
% North Position Errors
subplot(2,1,2);
plot(t,y(:,2)-x(:,2),'g',t,xhat(:,2)-x(:,2),'r');
ylabel('Position Error - North [m]');
xlabel('Time [s]');
legend(sprintf('Meas: %.3f',norm(n_xn,1)/numel(n_xn)),sprintf('Kalman f: %.3f',norm(e_x
axis tight;
9-60
State Estimation Using Time-Varying Kalman Filter
The plot legends show the position measurement and estimation error ( and
) normalized by the number of data points. The Kalman filter estimates have
about 25% percent less error than the raw measurements.
The actual velocity in the east direction and its Kalman filter estimate is shown below in
the top plot. The bottom plot shows the estimation error.
9-61
9 Online Estimation
The legend on the error plot shows the east velocity estimation error
normalized by the number of data points.
The Kalman filter velocity estimates track the actual velocity trends correctly. The noise
levels decrease when the vehicle is traveling at high velocities. This is in line with the
design of the Q matrix. The large two spikes are at t=50s and t=200s. These are the times
when the car goes through sudden decelearation and a sharp turn, respectively. The
velocity changes at those instants are much larger than the predictions from the Kalman
filter, which is based on its Q matrix input. After a few time-steps, the filter estimates
catch up with the actual velocity.
Summary
9-62
State Estimation Using Time-Varying Kalman Filter
You estimated the position and velocity of a vehicle using the Kalman filter block in
Simulink. The process noise dynamics of the model were time-varying. You validated
the filter performance by simulating various vehicle maneuvers and randomly generated
measurement noise. The Kalman filter improved the position measurements and
provided velocity estimates for the vehicle.
bdclose('ctrlKalmanNavigationExample');
9-63
9-64
10
Model Analysis
In this section...
“Ways to Validate Models” on page 10-2
“Data for Model Validation” on page 10-3
“Supported Model Plots” on page 10-3
“Definition of Confidence Interval for Specific Model Plots” on page 10-4
For information about the response of the noise model, see “Noise Spectrum Plots” on
page 10-46.
• Plotting the poles and zeros of the linear parametric model.
For more information, see “Pole and Zero Plots” on page 10-54.
• Comparing the response of nonparametric models, such as impulse-, step-, and
frequency-response models, to parametric models, such as linear polynomial models,
state-space model, and nonlinear parametric models.
10-2
Validating Models After Estimation
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.
• Compare models using Akaike Information Criterion or Akaike Final Prediction
Error.
For more information, see the aic and fpe reference page.
• Plotting linear and nonlinear blocks of Hammerstein-Wiener and nonlinear ARX
models.
Displaying confidence intervals on supported plots helps you assess the uncertainty of
model parameters. For more information, see “Computing Model Uncertainty” on page
10-83.
Note: Validation data should be the same in frequency content as the estimation data. If
you detrended the estimation data, you must remove the same trend from the validation
data. For more information about detrending, see “Handling Offsets and Trends in Data”
on page 2-108.
10-3
10 Model Analysis
10-4
Validating Models After Estimation
10-5
10 Model Analysis
To include or exclude a model on a plot, click the corresponding icon in the System
Identification app. Clicking the model icon updates any plots that are currently open.
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 app.
10-6
Plotting Models in the App
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” on page 14-11.
10-7
10 Model Analysis
You also 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. For more information, see “Simulation
and Prediction in the App” on page 10-11 and “Simulation and Prediction at the
Command Line” on page 10-15.
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.
Related Examples
“Compare Simulated Output with Measured Data” on page 10-17
10-8
Related Examples
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:
...
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
10-9
10 Model Analysis
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:
The difference between prediction and simulation is that in prediction, the past values
of outputs used for calculation are measured values while in simulation the outputs are
themselves a result of calculation using inputs and initial conditions.
The way information in past outputs is used depends on the disturbance model H of
1
the model. For the previous dynamic model, H ( z) = 1 + az-1 . In models of Output-Error
(OE) structure (H(z) = 1), there is no information in past outputs that can be used for
predicting future output values. In this case, predictions and simulations coincide. For
state-space models (idss), output-error structure corresponds to models with K=0. For
polynomial models (idpoly), this corresponds to models with polynomials a=c=d=1.
Note: Prediction with k=∞ means that no previous outputs are used in the computation
and prediction returns the same result as simulation.
Both simulation and prediction require initial conditions, which correspond to the states
of the model at the beginning of the simulation or prediction.
10-10
Related Examples
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.
To create a model output plot for parametric linear and nonlinear models in the System
Identification app, select the Model output check box in the Model Views area. By
default, this operation estimates the initial states from the data and plots the output of
selected models for comparison.
To include or exclude a model on the plot, click the corresponding model icon in the
System Identification app. 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 10-11.
To change plot settings, see “Changing Model Output Plot Settings” on page 10-13.
For general information about creating and working with plots, see “Working with Plots”
on page 14-11.
The following figure shows a sample Model Output plot, created in the System
Identification app.
10-11
10 Model Analysis
The model output plot shows different information depending on the domain of the input-
output validation data, as follows:
• For time-domain validation data, the plot shows simulated or predicted model output.
• For frequency-domain data, the plot shows the amplitude of the model response to
the frequency-domain input signal. The model response is equal to the product of the
Fourier transform of the input and the model's frequency function.
• For frequency-response data, the plot shows the amplitude of the model frequency
response.
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
Ë ¯
10-12
Related Examples
In this equation, y is the measured output, ŷ is the simulated or predicted model output,
and y is the mean of y. 100% corresponds to a perfect fit, and 0% indicates that the fit is
no better than guessing the output to be a constant ( ŷ = 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:
• The validation data set was not preprocessed in the same way as the estimation data
set.
Action Command
Display confidence intervals. • To display the dashed lines on either
side of the nominal model curve,
select Options > Show confidence
Note: Confidence intervals are only intervals. Select this option again to
available for simulated model output hide the confidence intervals.
of linear models. Confidence internal
• To change the confidence value, select
are not available for nonlinear ARX and
Options > Set % confidence level,
Hammerstein-Wiener models.
and choose a value from the list.
• To enter your own confidence level,
See “Definition: Confidence Interval” on select Options > Set confidence
page 10-14. level > Other. Enter the value as a
probability (between 0 and 1) or as the
number of standard deviations of a
Gaussian distribution.
10-13
10 Model Analysis
Action Command
Change between simulated output or • Select Options > Simulated output
predicted output. or Options > k step ahead predicted
output.
• To change the prediction horizon, select
Note: Prediction is only available for time-
Options > Set prediction horizon,
domain validation data.
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 (Signal Select Options > Signal plot or Options
plot), or the difference between model > Error plot.
output and measured output (Error plot).
(Time-domain validation data only) Select Options > Customized time
Set the time range for model output and span for fit and enter the minimum and
the time interval for which the Best Fit maximum time values. For example:
value is computed.
[1 20]
(Multiple-output system only) Select the output by name in the Channel
Select a different output. menu.
The confidence interval corresponds to the range of output values with a specific
probability of being the actual output 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 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.
10-14
Related Examples
In the app, 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 10-13.
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 output of Note: Omitting the third argument
one or more models on assumes an infinite horizon and
top of the measured results in the comparison of the
output. You should use an simulated response to the input data.
independent validation
data set as input to the
model.
sim Simulate and plot the To simulate the response of the model
model output only. model using input data data, use the
following command:
sim(model,data)
10-15
10 Model Analysis
The process of computing simulated and predicted responses over a time range starts by
using the initial conditions to compute the first few output values. sim, forecast and
predict commands provide defaults for handling initial conditions.
Simulation: Default initial conditions are zero for polynomial (idpoly), process
(idproc) and transfer-function (idtf) models . For state-space (idss) and grey-
box (idgrey) models, the default initial conditions are the internal model initial
10-16
Related Examples
states (model property x0). You can specify other initial conditions using the
InitialCondition simulation option (see simOptions).
Use the compare command to validate models by simulation because its algorithm
estimates the initial states of a model to optimize the model fit to a given data set.
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 InitialCondition option (see predictOptions). For
example, to compute the initial states that optimize the 1-step-ahead predicted response
of the model m to the output data z:
opt = predictOptions('InitialCondition','estimate');
[Yp,X0est] = predict(m,z,1,opt);
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.
10-17
10 Model Analysis
load iddata1;
ze = z1(1:150);
zv = z1(151:300);
m = armax(ze,[2 3 1 0]);
compare(zv,m);
10-18
Related Examples
This example shows how you can create input data and a model, and then use the data
and the model to simulate output data.
In this example, you create the following ARMAX model with Gaussian noise e:
u = idinput(400,'rbs',[0 0.3]);
opt = simOptions('AddNoise',true);
y = sim(m_armax,u,opt);
The 'AddNoise' option specifies to include in the simulation the Gaussian noise e
present in the model. Set this option to false (default behavior) to simulate the noise-
free response to the input u , which is equivalent to setting e to zero.
10-19
10 Model Analysis
u = idinput(400,'rbs',[0 0.3]);
Create an iddata object with empty output to represent just the input signal.
data = iddata([],u);
data.ts = 0.1;
opt = simOptions('AddNoise',true);
y=sim(model_ss,data,opt);
In this example, y is the original series of monthly sales figures. You use the first half
of the measured data to estimate the time-series model and test the model's ability to
forecast sales six months ahead using the entire data set.
Simulate figures for sales growth every month before settling down.
rng('default');
t = (0:0.2:19)';
yd = 1-exp(-0.2*t) + randn(size(t))/50;
y = iddata(yd,[],0.2);
plot(y);
10-20
Related Examples
Estimate a second-order autoregressive model with noise integration using the data.
m = ar(y1, 2, 'yw', 'IntegrateNoise', true);
Forecast the response 10 steps beyond the available data's time range.
yfuture = forecast(m,y,10);
10-21
10 Model Analysis
10-22
Residual Analysis
Residual Analysis
In this section...
“What Is Residual Analysis?” on page 10-23
“Supported Model Types” on page 10-24
“What Residual Plots Show for Different Data Domains” on page 10-24
“Displaying the Confidence Interval” on page 10-25
“How to Plot Residuals Using the App” on page 10-26
“How to Plot Residuals at the Command Line” on page 10-27
“Examine Model Residuals” on page 10-27
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.
According to the independence test criteria, a good model has residuals uncorrelated
with past inputs. Evidence of correlation indicates that the model does not describe how
part of the output relates to the corresponding input. For example, a peak outside the
confidence interval for lag k means that the output y(t) that originates from the input u(t-
k) is not properly described by the model.
Your model should pass both the whiteness and the independence tests, except in the
following cases:
• For output-error (OE) models and when using instrumental-variable (IV) methods,
make sure that your model shows independence of e and u, and pay less attention to
the results of the whiteness of e.
In this case, the modeling focus is on the dynamics G and not the disturbance
properties H.
10-23
10 Model Analysis
• Correlation between residuals and input for negative lags, is not necessarily an
indication of an inaccurate model.
When current residuals at time t affect future input values, there might be feedback
in your system. In the case of feedback, concentrate on the positive lags in the cross-
correlation plot during model validation.
Note: Residual analysis plots are not available for frequency response (FRD) models.
For time-series models, you can only generate model-output plots for parametric models
using time-domain time-series (no input) measured data.
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.
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.
10-24
Residual Analysis
The following figure shows a sample Residual Analysis plot, created in the System
Identification app.
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.
You can display a confidence interval on the plot in the app to gain insight into the
quality of the model. To learn how to show or hide confidence interval, see the description
of the plot settings in “How to Plot Residuals Using the App” on page 10-26.
10-25
10 Model Analysis
Note: If you are working in the System Identification app, you can specify a custom
confidence interval. If you are using the resid command, the confidence interval is fixed
at 99%.
To include or exclude a model on the plot, click the corresponding model icon in the
System Identification app. Active models display a thick line inside the Model Board
icon.
Action Command
Display confidence intervals • To display the dashed lines on either side of the
around zero. nominal model curve, select Options > Show
confidence intervals. Select this option again to
hide the confidence intervals.
Note: Confidence internal are
• To change the confidence value, select Options >
not available for nonlinear
Set % confidence level and choose a value from
ARX and Hammerstein-Wiener
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 choose the
(data samples) for which to value from the list.
compute autocorellation and • To enter your own lag value, select Options > Set
cross-correlation functions. confidence level > Other. Enter the value as the
number of data samples.
10-26
Residual Analysis
Action Command
Note: For frequency-domain
validation data, increasing
the number of lags increases
the frequency resolution of
the residual spectrum and the
transfer function.
(Multiple-output system only) Select the input-output by name in the Channel
Select a different input-output menu.
pair.
10-27
10 Model Analysis
1 To load the sample System Identification app session that contains estimated
models, type the following command in the MATLAB Command Window:
systemIdentification('dryer2_linear_models')
2 To generate a residual analysis plot, select the Model resids check box in the
System Identification app.
Note: For the nonparametric models, imp and spad, residual analysis plots are not
available.
10-28
Residual Analysis
The top axes show the autocorrelation of residuals for the output (whiteness test). The
horizontal scale is the number of lags, which is the time difference (in samples) between
the signals at which the correlation is estimated. The horizontal dashed lines on the
plot represent the confidence interval of the corresponding estimates. Any fluctuations
within the confidence interval are considered to be insignificant. Four of the models,
arxqs, n4s3, arx223 and amx2222, produce residuals that enter outside the confidence
interval. A good model should have a residual autocorrelation function within the
confidence interval, indicating that the residuals are uncorrelated.
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.
To remove models with poor performance from the Residual Analysis plot, click the
model icons arxqs, n4s3, arx223, and amx2222 in the System Identification app.
The Residual Analysis plot now includes only the three models that pass the residual
tests: arx692, n4s6, and amx3322.
10-29
10 Model Analysis
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.
10-30
Impulse and Step Response Plots
In this section...
“Supported Models” on page 10-31
“How Transient Response Helps to Validate Models” on page 10-31
“What Does a Transient Response Plot Show?” on page 10-32
“Displaying the Confidence Interval” on page 10-33
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.
Note: For frequency-response models, impulse- and step-response plots are not available.
For nonlinear models, only step-response plots are available.
Examples
“How to Plot Impulse and Step Response Using the App” on page 10-34
“How to Plot Impulse and Step Response at the Command Line” on page 10-36
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,
10-31
10 Model Analysis
you can estimate an impulse or step response from the data using correlation analysis
(nonparametric model), and then plot the correlation analysis result on top of the
transient responses of the parametric models.
Because nonparametric and parametric models are derived using different algorithms,
agreement between these models increases confidence in the parametric model results.
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.
y( t) - 1 .5 y(t - T ) + 0.7 y( t - 2 T) =
0 .9u(t) + 0.5u(t - T )
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 App” on page 10-34.
The following figure shows a sample Transient Response plot, created in the System
Identification app.
10-32
Examples
The confidence interval corresponds to the range of response values with a specific
probability of being the actual response 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 curve
represents the range where there is a 95% chance that it contains 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.
10-33
10 Model Analysis
To include or exclude a model on the plot, click the corresponding model icon in the
System Identification app. Active models display a thick line inside the Model Board
icon.
10-34
More About
Action Command
Note: To change the time span of • To use the time span based on model
models you estimated using correlation dynamics, type [] or default.
analysis models, select Estimate >
Correlation models and reestimate The default time span is computed based
the model using a new time span. on the model dynamics and might be
different for different models. For nonlinear
models, the default time span is 10.
Toggle between line plot or stem plot. Select Style > Line plot or Style > Stem plot.
More About
“Impulse and Step Response Plots” on page 10-31
10-35
10 Model Analysis
To display confidence intervals for a specified number of standard deviations, use the
following syntax:
h = impulseplot(model);
showConfidence(h,sd);
where h is the plot handle returned by impulseplot. You could also use the plot
handle returned by stepplot. sd is the number of standard deviations of a Gaussian
distribution. For example, a confidence value of 99% for the nominal model curve
corresponds to 2.58 standard deviations.
Alternatively, you can turn on the confidence region view interactively by right-clicking
on the plot and selecting Characteristics > Confidence Region. Use the plot property
editor to specify the number of standard deviations.
The following table summarizes commands that generate impulse- and step-response
plots. For detailed information about each command, see the corresponding reference
page.
10-36
More About
opt = stepDataOptions;
opt.InputOffset = u0;
opt.StepAmplitude = A;
step(sys,opt)
More About
“Impulse and Step Response Plots” on page 10-31
10-37
10 Model Analysis
In the case of linear dynamic systems, the transfer function G is essentially an operator
that takes the input u of a linear system to the output y:
y = Gu
For a continuous-time system, the transfer function relates the Laplace transforms of the
input U(s) and output Y(s):
Y ( s) = G ( s)U ( s)
In this case, the frequency function G(iw) is the transfer function evaluated on the
imaginary axis s=iw.
For a discrete-time system sampled with a time interval T, the transfer function relates
the Z-transforms of the input U(z) and output Y(z):
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 p T .
10-38
Examples
Examples
“How to Plot Bode Plots Using the App” on page 10-42
“How to Plot Bode and Nyquist Plots at the Command Line” on page 10-44
Note: Frequency-response plots are not available for nonlinear models. In addition,
Nyquist plots do not support time-series models that have no input.
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.
One example of how frequency-response plots help validate other models is that you can
estimate a frequency response from the data using spectral analysis (nonparametric
model), and then plot the spectral analysis result on top of the frequency response of
the parametric models. Because nonparametric and parametric models are derived
using different algorithms, agreement between these models increases confidence in the
parametric model results.
10-39
10 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 j = 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.
• 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 output power spectrum of the noise model
instead. For more information, see “Noise Spectrum Plots” on page 10-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 app.
10-40
Examples
The confidence interval corresponds to the range of response values with a specific
probability of being the actual response 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 curve
represents the range where there is a 95% chance that it contains 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.
10-41
10 Model Analysis
To include or exclude a model on the plot, click the corresponding model icon in the
System Identification app. Active models display a thick line inside the Model Board
icon.
Action Command
Display the confidence interval. • To display the dashed lines on either 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 values for Select Options > Frequency range and specify a
computing the noise spectrum. new frequency vector in units of rad/s.
The default frequency vector is Enter the frequency vector using any one of following
128 linearly distributed values, methods:
greater than zero and less
than or equal to the Nyquist • MATLAB expression, such as [1:100]*pi/100 or
frequency. logspace(-3,-1,200). Cannot contain variables
in the MATLAB workspace.
• Row vector of values, such as [1:.1:100]
10-42
More About
Action Command
Note: To restore the default frequency vector, enter
[].
Change frequency units between Select Style > Frequency (Hz) or Style >
hertz and radians per second. Frequency (rad/s).
Change frequency scale between Select Style > Linear frequency scale or Style >
linear and logarithmic. Log frequency scale.
Change amplitude scale between Select Style > Linear amplitude scale or Style >
linear and logarithmic. Log amplitude scale.
(Multiple-output system only) Select the output by name in the Channel menu.
Select an input-output pair
to view the noise spectrum
corresponding to those channels.
More About
“Frequency Response Plots” on page 10-38
10-43
10 Model Analysis
To display confidence intervals for a specified number of standard deviations, use the
following syntax:
h=command(model);
showConfidence(h,sd)
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.
10-44
More About
More About
“Frequency Response Plots” on page 10-38
10-45
10 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.
Note: For nonlinear models and correlation analysis models, noise-spectrum plots are
not available. For time-series models, you can only generate noise-spectrum plots for
parametric and spectral-analysis models.
Examples
“How to Plot the Noise Spectrum Using the App” on page 10-49
“How to Plot the Noise Spectrum at the Command Line” on page 10-52
y( t) = G ( z)u(t) + v(t)
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)
10-46
Examples
The toolbox computes both H and l during the estimation of the noise model and stores
these quantities as model properties. The H(z) operator represents the noise model.
Whereas the frequency-response plot shows the response of G, the noise-spectrum plot
shows the frequency-response of the noise model H.
For input-output models, the noise spectrum is given by the following equation:
2
( )
F v (w) = l H eiw
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 where there is a 95% chance that the true response belongs.. 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.
10-47
10 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.
10-48
How to Plot the Noise Spectrum Using the App
To include or exclude a model on the plot, click the corresponding model icon in the
System Identification app. Active models display a thick line inside the Model Board
icon.
10-49
10 Model Analysis
Action Command
• 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 specify a new
values for computing the frequency vector in units of radians per second.
noise spectrum.
Enter the frequency vector using any one of following
The default frequency methods:
vector is 128 linearly
distributed values, greater • MATLAB expression, such as [1:100]*pi/100 or
than zero and less than logspace(-3,-1,200). Cannot contain variables in
or equal to the Nyquist the MATLAB workspace.
frequency. • Row vector of values, such as [1:.1:100]
10-50
More About
Action Command
Note: You cannot view cross
spectra between different
outputs.
More About
“Noise Spectrum Plots” on page 10-46
10-51
10 Model Analysis
To determine if your estimated noise model is good enough, you can compare the output
spectrum of the estimated noise-model H to the estimated output spectrum 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;
ymeasured is data.y. v is the noise term v(t), as described in “What Does a Noise
Spectrum Plot Show?” on page 10-46 and corresponds to the difference between the
simulated response ysimulated and the actual response ymeasured.
The toolbox uses the following equation to compute the noise spectrum of the actual
noise:
•
F v (w) = Â Rv ( t ) e-iwt
t=-•
Rv ( t ) = Ev ( t ) v ( t - t )
If the parametric and the nonparametric estimates of the noise spectra are different,
then you might need a higher-order noise model.
10-52
More About
More About
“Noise Spectrum Plots” on page 10-46
10-53
10 Model Analysis
In this section...
“Supported Models” on page 10-54
“What Does a Pole-Zero Plot Show?” on page 10-54
“Reducing Model Order Using Pole-Zero Plots” on page 10-56
“Displaying the Confidence Interval” on page 10-56
Supported Models
You can create pole-zero plots of linear identified models. To study the poles and zeros of
the noise component of an input-output model or a time series model, use noise2meas to
first extract the noise model as an independent input-output model, whose inputs are the
noise channels of the original model.
Examples
“How to Plot Model Poles and Zeros Using the App” on page 10-58
“How to Plot Poles and Zeros at the Command Line” on page 10-60
10-54
Examples
y( t) = G ( z)u(t) + v(t)
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 most-delayed and least-delayed input. For example, there two
poles and one zero in the following ARX model:
10-55
10 Model Analysis
y( t) - 1 .5 y(t - T ) + 0.7 y( t - 2 T) =
0 .9u(t) + 0.5u(t - T )
For example, you can use the following syntax to plot a 1-standard-deviation confidence
interval around model poles and zeros.
showConfidence(iopzplot(model))
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-40.
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
10-56
Examples
10-57
10 Model Analysis
To include or exclude a model on the plot, click the corresponding model icon in the
System Identification app. Active models display a thick line inside the Model Board
icon.
The following table summarizes the Zeros and Poles plot settings.
Action Command
Display the confidence • To display the dashed lines on either side of the
interval. 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 imaginary Select Style > Re/Im-axes. Select this option again to
axes. hide the axes.
Show the unit circle. Select Style > Unit circle. Select this option again to
hide the unit circle. The unit circle is useful as a reference
curve for discrete-time models.
(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.
10-58
More About
More About
“Pole and Zero Plots” on page 10-54
10-59
10 Model Analysis
To display confidence intervals for a specified number of standard deviations, use the
following syntax:
h = iopzplot(model);
showConfidence(h,sd)
More About
“Pole and Zero Plots” on page 10-54
10-60
Analyzing MIMO Models
In this section...
“Overview of Analyzing MIMO Models” on page 10-61
“Array Selector” on page 10-62
“I/O Grouping for MIMO Models” on page 10-64
“Selecting I/O Pairs” on page 10-65
sys_mimo=rsample(idss(rss(3,3,3)),10);
step(sys_mimo);
A set of 9 plots appears, one from each input to each output, for the ten model samples.
10-61
10 Model Analysis
Array Selector
If you plot an identified linear model array, Array Selector appears as an option in
the right-click menu. Selecting this option opens the Model Selector for LTI Arrays,
shown below.
10-62
Analyzing MIMO Models
You can use this window to include or exclude models within the LTI array using various
criteria.
Arrays
Select the LTI array for model selection using the Arrays list.
Selection Criteria
There are two selection criteria. The default, Index into Dimensions, allows you to
include or exclude specified indices of the LTI Array. Select systems from the Selection
Criterion Setup and specify whether to show or hide the systems using the pull-down
menu below the Setup lists.
The second criterion is Bound on Characteristics. Selecting this options causes the
Model Selector to reconfigure. The reconfigured window is shown below
10-63
10 Model Analysis
Use this option to select systems for inclusion or exclusion in your response plot based on
their time response characteristics. The panel directly above the buttons describes how
to set the inclusion or exclusion criteria based on which selection criteria you select from
the reconfigured Selection Criteria Setup panel.
For example, if you select Outputs, the step plot reconfigures into 3 plots, one for each
input.
10-64
Analyzing MIMO Models
Selecting None returns to the default configuration, where all I/O pairs are displayed
individually.
10-65
10 Model Analysis
This window automatically configures to the number of I/O pairs in your MIMO system.
You can select:
Using these options, you can inspect individual I/O pairs, or look at particular I/O
channels in detail.
10-66
Customizing Response Plots Using the Response Plots Property Editor
In this section...
“Opening the Property Editor” on page 10-67
“Overview of Response Plots Property Editor” on page 10-68
“Labels Pane” on page 10-70
“Limits Pane” on page 10-70
“Units Pane” on page 10-71
“Style Pane” on page 10-77
“Options Pane” on page 10-77
“Editing Subplots Using the Property Editor” on page 10-78
Before looking at the Property Editor, open a step response plot using these commands.
This creates a step plot. Select Properties from the right-click menu. Note that when
you open the Property Editor, a set of black squares appear around the step response,
as this figure shows:
10-67
10 Model Analysis
10-68
Customizing Response Plots Using the Response Plots Property Editor
In general, you can change the following properties of response plots. Note that only the
Labels and Limits panes are available when using the Property Editor with Simulink
Design Optimization™ software.
If you cannot customize units, as is the case with step responses, the Property Editor
will display that no units are available for the selected plot.
• Styles in the Styles pane.
You can show a grid, adjust font properties, such as font size, bold and italics, and
change the axes foreground color
• Change options where applicable in the Options pane.
These include peak response, settling time, phase and gain margins, etc. Plot options
change with each plot response type. The Property Editor displays only the options
that make sense for the selected response plot. For example, phase and gain margins
are not available for step responses.
10-69
10 Model Analysis
As you make changes in the Property Editor, they display immediately in the response
plot. Conversely, if you make changes in a plot using right-click menus, the Property
Editor for that plot automatically updates. The Property Editor and its associated plot
are dynamically linked.
Labels Pane
To specify new text for plot titles and axis labels, type the new string in the field next to
the label you want to change. Note that the label changes immediately as you type, so
you can see how the new text looks as you are typing.
Limits Pane
Default values for the axes limits make sure that the maximum and minimum x and y
values are displayed. If you want to override the default settings, change the values in
the Limits fields. The Auto-Scale box automatically clears if you click a different field.
The new limits appear immediately in the response plot.
10-70
Customizing Response Plots Using the Response Plots Property Editor
Units Pane
You can use the Units pane to change units in your response plot. The contents of this
pane depend on the response plot associated with the editor.
The following table lists the options available for the response objects. Use the menus to
toggle between units.
10-71
10 Model Analysis
10-72
Time Units Options
Impulse • Time.
10-73
10 Model Analysis
10-74
Frequency Units Options
10-75
10 Model Analysis
Step • Time.
10-76
Time Units Options
Style Pane
Use the Style pane to toggle grid visibility and set font preferences and axes foreground
colors for response plots.
If you do not want to specify RGB values numerically, click the Select button to open
the Select Color dialog box.
Options Pane
The Options pane allows you to customize response characteristics for plots. Each
response plot has its own set of characteristics and optional settings; the table below lists
them. Use the check boxes to activate the feature and the fields to specify rise or settling
time percentages.
10-77
10 Model Analysis
subplot(2,1,1)
step(rss(2,1))
subplot(2,1,2)
impulse(rss(1,1))
10-78
Time Units Options
After the figure window appears, double-click in the upper (step response) plot to activate
the Property Editor. You will see a set of small black squares appear around the
step response, indicating that it is the active plot for the editor. To switch to the lower
(impulse response) plot, just click once in the impulse response plot region. The set of
black squares switches to the impulse response, and the Property Editor updates as
well.
10-79
10 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 + d N ˆ
FPE = V Á
Á 1 - d ˜˜
Ë N¯
where V is the loss function, d is the number of estimated parameters, and N is the
number of values in the estimation data set.
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 )
10-80
Akaike's Criteria for Model Validation
Ê N ˆ
 e ( t, q N ) (e ( t, q N ))
T
1
V = det Á 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.
According to Akaike's theory, the most accurate model has the smallest FPE.
You can also access the FPE value of an estimated model , m, as follows:
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.
10-81
10 Model Analysis
2d
AIC = log V +
N
where V is the loss function, d is the number of estimated parameters, and N is the
number of values in the estimation data set.
Ê N ˆ
 e ( t, q N ) (e ( t, q N ))
T
1
V = det Á 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.
10-82
Computing Model Uncertainty
Understanding model variability helps you to understand how different your model
parameters would be if you repeated the estimation using a different data set (with the
same input sequence as the original data set) and the same model structure.
When validating your parametric models, check the uncertainty values. Large
uncertainties in the parameters might be caused by high model orders, inadequate
excitation, and poor signal-to-noise ratio in the data.
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, idtf, idgrey, idfrd, and idnlgrey.
When you estimate a model, the covariance matrix of the estimated parameters is stored
with the model. Use getcov to fetch the covariance matrix. Use getpvec to fetch the
list of parameters and their individual uncertainties that have been computed using the
covariance matrix. The covariance matrix is used to compute all uncertainties in model
output, Bode plots, residual plots, and pole-zero plots.
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
10-83
10 Model Analysis
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 10-23. 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.
For output-error models, such as transfer function models, state-space with K=0
and polynomial models of output-error form, with the noise model H fixed to 1, the
covariance matrix computation does not assume white residuals. Instead, the covariance
is estimated based on the estimated color of the residual correlations. This estimation of
the noise color is also performed for state-space models with K=0, which is equivalent to
an output-error model.
Type present(model) at the prompt, where model represents the name of a linear
or nonlinear model.
• Confidence intervals on the linear model plots, including step-response, impulse-
response, Bode, Nyquist, noise spectrum and pole-zero plots.
Confidence intervals are computed based on the variability in the model parameters.
For information about displaying confidence intervals, see the corresponding plot
section.
• Covariance matrix of the estimated parameters in linear models and nonlinear grey-
box models.
Use getcov.
• Estimated standard deviations of polynomial coefficients, poles/zeros, or state-space
matrices using idssdata, tfdata, zpkdata, and polydata.
• 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
10-84
Computing Model Uncertainty
10-85
10 Model Analysis
Troubleshooting Models
In this section...
“About Troubleshooting Models” on page 10-86
“Model Order Is Too High or Too Low” on page 10-86
“Nonlinearity Estimator Produces a Poor Fit” on page 10-87
“Substantial Noise in the System” on page 10-87
“Unstable Models” on page 10-88
“Missing Input Variables” on page 10-89
“Complicated Nonlinearities” on page 10-89
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.
You can estimate the model order as described in “Preliminary Step – Estimating Model
Orders and Input Delays” on page 3-46. Typically, you use the suggested order as a
starting point to estimate the lowest possible order with different model structures. After
each estimation, you monitor the Model Output and the Residual Analysis plots, and
then adjust your settings for the next estimation.
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-
10-86
Troubleshooting Models
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.
High-order models are more expensive to compute and result in greater parameter
uncertainty.
You specify the complexity of piece-wise-linear, wavelet, sigmoid, and custom networks
using the number of units (NumberOfUnits nonlinear estimator property). A high
number of units indicates a complex nonlinearity estimator. In the case of neural
networks, you specify the complexity using the parameters of the network object. For
more information, see the Neural Network Toolbox documentation.
To select the appropriate complexity of the nonlinearity estimator, start with a low
complexity and validate the model output. Next, increate the complexity and validate the
model output again. The model fit degrades when the nonlinearity estimator becomes too
complex.
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.
One indication of noise is when a state-space model is better than an ARX model at
reproducing the measured output; whereas the state-space structure has sufficient
flexibility to model noise, the ARX model structure is less able to model noise because the
10-87
10 Model Analysis
A polynomial must account for both the system dynamics and the noise. The following
equation represents the ARX model and shows that A couples the dynamics and the noise
by appearing in the denominator of both the dynamics term and the noise terms:
B 1
y= u+ e
A A
Another indication that a noise model is needed appears in residual analysis plots when
you see significant autocorrelation of residuals at nonzero lags. For more information
about residual analysis, see “Residual Analysis” on page 10-23.
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
Unstable Linear Model
You can test whether a linear model is unstable is by examining the pole-zero plot of the
model, which is described in “Pole and Zero Plots” on page 10-54. The stability threshold
for pole values differs for discrete-time and continuous-time models, as follows:
• 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.
Note: Linear trends might cause linear models to be unstable. However, detrending the
model does not guarantee stability.
When an unstable model is OK: In some cases, an unstable model is still a useful
model. For example, your system might be unstable without a controller, and you plan to
use your model for control design. In this case, you can import your unstable model into
Simulink or Control System Toolbox products.
Forcing stability during estimation: If you believe that your system is stable, but
your model is unstable, then you can estimate the model with the Focus estimation
option set to Stability. This setting might result in a reduced model quality. For more
information about Focus, see the various estimation option configuration commands
such as tfestOptions, ssestOptions, procestOptions etc..
10-88
Troubleshooting Models
Allowing for some instability: A more advanced approach to achieving a stable model
is by setting the stability threshold estimation option to allow a margin of error. The
threshold estimation options are advanced properties of an estimation option set.
To test if a nonlinear model is unstable is to plot the simulated model output on top of
the validation data. If the simulated output diverges from measured output, the model
is unstable. However, agreement between model output and measured output does not
guarantee stability.
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.
You can model the nonlinearities by performing a simple transformation on the signals
to make the problem linear in the new variables. For example, if electrical power is the
driving stimulus in a heating process and temperature is the output, you can form a
simple product of voltage and current measurements.
10-89
10 Model Analysis
If your problem is sufficiently complex and you do not have physical insight into the
problem, you might try fitting nonlinear black-box models.
10-90
Next Steps After Getting an Accurate Model
For nonlinear black-box models (idnlarx and idnlhw objects), you can compute a linear
approximation of the nonlinear model. See “Linear Approximation of Nonlinear Black-
Box Models”.
Tip To export a model from the app, drag the model icon to the To Workspace rectangle.
Alternatively, right-click the model to open the Data/model Info dialog box. Click
Export.
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 Identified
Models for Control Design Applications” on page 12-2.
Finally, if you have Simulink software installed, you can exchange data between the
System Identification Toolbox software and the Simulink environment. For more
information, see “Simulating Identified Model Output in Simulink”.
10-91
10-92
11
11-2
Toolbox Preferences Editor
Note: The SISO Design Tool requires the Control System Toolbox software.
11-3
11 Setting Toolbox Preferences
Units Pane
• Frequency
The default auto option uses rad/TimeUnit as the frequency units relative to
the system time units, where TimeUnit is the system time units specified in the
TimeUnit property of the system on frequency-domain plots. For multiple systems
with different time units, the units of the first system is used.
For the frequency axis, you can select logarithmic or linear scales.
11-4
Other Time Units Options
• 'rad/millisecond'
• 'rad/minute'
• 'rad/hour'
• 'rad/day'
• 'rad/week'
• 'rad/month'
• 'rad/year'
• 'cycles/nanosecond'
• 'cycles/microsecond'
• 'cycles/millisecond'
• 'cycles/hour'
• 'cycles/day'
• 'cycles/week'
• 'cycles/month'
• 'cycles/year'
• Magnitude — Decibels (dB) or absolute value (abs)
• Phase — Degrees or radians
• Time
The default auto option uses the time units specified in the TimeUnit property of the
system on the time- and frequency-domain plots. For multiple systems with different
time units, the units of the first system is used.
• 'days'
• 'weeks'
• 'months'
• 'years'
11-6
Style Pane
Style Pane
Use the Style pane to toggle grid visibility and set font preferences and axes foreground
colors for all plots you create. This figure shows the Style pane.
If you do not want to specify RGB values numerically, click the Select button to open
the Select Colors dialog box.
11-7
11 Setting Toolbox Preferences
Options Pane
The Options pane has selections for time responses and frequency responses. This figure
shows the Options pane with default settings.
The following are the available options for the Options pane:
• Time Response:
• Show settling time within xx%— You can set the threshold of the settling time
calculation to any percentage from 0 to 100%. The default is 2%.
• Specify rise time from xx% to yy%— The standard definition of rise time is the
time it takes the signal to go from 10% to 90% of the final value. You can choose
any percentages you like (from 0% to 100%), provided that the first value is
smaller than the second.
• Frequency Response:
• Only show magnitude above xx—Specify a lower limit for magnitude values in
response plots so that you can focus on a region of interest.
• Unwrap phase—By default, the phase is unwrapped. Wrap the phrase by clearing
this box. If the phase is wrapped, all phase values are shifted such that their
equivalent value displays in the range [-180°, 180°).
11-8
SISO Tool Pane
(1 + Tz1 s)
DC ¥ L
(1 + Tp1 s )
where DC is compensator DC gain, Tz1, Tz2, ..., are the zero time constants, and Tp1,
Tp2, ..., are the pole time constants.
DC ¥
(1 + s wz ) L
1
(1 + s w p )
1
11-9
11 Setting Toolbox Preferences
where DC is compensator DC gain, ωz1, and ωz2, ... and ωp1, ωp2, ..., are the natural
frequencies of the zeros and poles, respectively.
( s + z1 )
K¥
( s + p1 )
where K is the overall compensator gain, and z1, z2, ... and p1, p2, ..., are the zero and
pole locations, respectively.
• Bode Options — By default, the SISO Design Tool shows the plant and sensor poles
and zeros as blue x's and o's, respectively. Clear this box to eliminate the plant's poles
and zeros from the Bode plot. Note that the compensator poles and zeros (in red) will
still appear.
11-10
12
Control System Toolbox software also provides the LTI Viewer to extend System
Identification Toolbox functionality for linear model analysis.
Control System Toolbox software supports only linear models. If you identified a
nonlinear plant model using System Identification Toolbox software, you must linearize
it before you can work with this model in the Control System Toolbox software. For more
information, see the linapp, idnlarx/linearize, or idnlhw/linearize reference
page.
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.
To learn how you can reduce model order using pole-zero plots, see “Reducing Model
Order Using Pole-Zero Plots” on page 10-56.
12-2
Using Identified Models for Control Design Applications
Control System Toolbox software provides both the SISO Design Tool and commands for
working at the command line. You can import linear models directly into SISO Design
Tool using the following command:
sisotool(model)
You can also identify a linear model from measured SISO data and tune a PID controller
for the resulting model in the PID Tuner. You can interactively adjust the identified
parameters to obtain an LTI model whose response fits your response data. The PID
Tuner automatically tunes a PID controller for the identified model. You can then
interactively adjust the performance of the tuned control system, and save the identified
plant and tuned controller. To access the PID Tuner, enter pidTuner at the MATLAB
command line. For more information, see “PID Controller Tuning”.
The following table summarizes the commands for transforming linear state-space and
polynomial models to an LTI object.
12-3
12 Control Design Applications
The following code converts the noise component of a linear identified model, sys, to a
numeric state-space model:
noise_model_ss = idss(sys,'noise');
To convert both the measured and noise components of a linear identified model, sys, to
a numeric state-space model:
model_ss = idss(sys,'augmented');
For more information about subreferencing the dynamic or the noise model, see
“Separation of Measured and Noise Components of Models” on page 3-117.
If you have the Control System Toolbox software, you can plot models in the LTI Viewer
from either the System Identification app or the MATLAB Command Window.
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.
When the MATLAB software is installed, the System Identification app contains the To
LTI Viewer rectangle. To plot models in the LTI Viewer, do one of the following:
12-4
Using Identified Models for Control Design Applications
• Drag and drop the corresponding icon to the To LTI Viewer rectangle in the System
Identification app.
• Right-click the icon to open the Data/model Info dialog box. Click Show in LTI
Viewer to plot the model in the LTI Viewer.
Alternatively, use the following syntax when working at the command line to view a
model in the LTI Viewer:
ltiview(model)
For example, you can perform the following operations on identified models:
• G1+G2
• G1*G2
• append(G1,G2)
• feedback(G1,G2)
12-5
12 Control Design Applications
Construct a random numeric model using the Control System Toolbox software.
rng('default');
sys0 = drss(3,3,2);
rng('default') specifies the setting of the random number generator as its default
setting.
sys0 is a third-order numeric state-space model with three outputs and two inputs.
Convert sys0 to an identified state-space model and set its output noise variance.
sys = idss(sys0);
sys.NoiseVariance = 0.1*eye(3);
u = iddata([],idinput([800 2],'rbs'));
opt = simOptions('AddNoise',true);
y = sim(sys,u,opt);
opt is an option set specifying simulation options. y is the simulated output for sys0.
data = [y u];
Estimate the state-space model from the generated data using ssest .
estimated_ss = ssest(data(1:400));
12-6
Create and Plot Identified Models Using Control System Toolbox Software
sys_tf = tf(estimated_ss);
compare(data(401:800),estimated_ss)
ltiview(estimated_ss);
12-7
12 Control Design Applications
12-8
13
You can use the System Identification Toolbox block library to perform the following
tasks:
The model you import might be a component of a larger system modeled in Simulink.
For example, if you identified a plant model using the System Identification Toolbox
software, you can import this plant into a Simulink model for control design.
• Estimate parameters of linear polynomial models during simulation from single-
output data.
To open the System Identification Toolbox block library, on the Home tab, in the
Simulink section, click Simulink Library. In the Library Browser, select System
Identification Toolbox.
You can also open the System Identification Toolbox block library directly by typing the
following command at the MATLAB prompt:
slident
To get help on a block, right-click the block in the Library Browser, and select Help.
13-2
Preparing Data
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.
For information about configuring each block, see the corresponding reference pages.
13-3
13 System Identification Toolbox Blocks
After you add a block to the model, double-click the block to specify block parameters.
Block Description
Recursive Least Squares Estimate model coefficients using recursive least squares
Estimator (RLS) algorithm
Recursive Polynomial Model Estimate input-output and time-series model coefficients
Estimator
Kalman Filter Estimate states of discrete-time or continuous-time linear
system
Model Type Converter Convert polynomial model coefficients to state-space
model matrices
For information about configuring each block, see the corresponding reference pages.
13-4
Simulating Identified Model Output in Simulink
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 13-5.
Block Description
“Idmodel” Simulate a linear identified model in Simulink software.
The model can be a process (idproc), linear polynomial
(idpoly), state-space (idss), grey-box (idgrey) and
transfer-function (idtf) model.
“Nonlinear ARX Model” Simulate idnlarx model in Simulink.
“Hammerstein-Wiener Simulate idnlhw model in Simulink.
Model”
13-5
13 System Identification Toolbox Blocks
Block Description
“Nonlinear Grey-Box Model” Simulate nonlinear ODE (idnlgrey model object) 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 13-6.) For information about configuring each block, see the
corresponding reference pages.
Specify the initial states for simulation in the Initial states (state space only: idss,
idgrey) field of the Function Block Parameters: Idmodel dialog box:
• For idss and idgrey models, initial states must be a vector of length equal to the
order of the model.
• For models other than idss and idgrey, initial conditions are zero.
• In some situations, you may want to match the simulated response of the model to a
certain input/output data set:
1 Convert the identified model into state-space form (idss model), and use the
state-space model in the block.
2 Compute the initial state values that produce the best fit between the model
output and the measured output signal using findstates(idParametric).
3 Specify the same input signal for simulation that you used as the validation data
in the app or in the compare plot.
For example:
13-6
Simulating Identified Model Output in Simulink
z is the data set you used for validating the model m. Use the model mss and
initial states X0 in the Idmodel block to perform the simulation.
The states of a nonlinear ARX model correspond to the dynamic elements of the
nonlinear ARX model structure, which are the model regressors. Regressors can be the
delayed input/output variables (standard regressors) or user-defined transformations
of delayed input/output variables (custom regressors). For more information about the
states of a nonlinear ARX model, see the idnlarx 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.
The default initial state for simulating a Hammerstein-Wiener model is 0. For more
information about specifying initial conditions for simulation, see the IDNLHW Model
reference page.
13-7
13 System Identification Toolbox Blocks
Prerequisites
Estimate a model, M, using a multiple-experiment data set, Z, which contains data from
three experiments — z1, z2, and z3:
% Load multi-experiment data.
load(fullfile(matlabroot, 'toolbox', 'ident', 'iddemos',...
'data', 'twobodiesdata'));
To simulate the model using input u2, use x0(:,2) as the initial states. x0(:,2) is
computed to maximize the fit between the measured output, y2, and the response of M.
To compute initial states that maximizes the fit to the corresponding output y2, and
simulate the model using the second experiment:
1 Extract the initial states that correspond to the second experiment for simulation:
X0est = x0(:,2);
2 Open the System Identification Toolbox library by typing the following command at
the MATLAB prompt:
slident
3 Open a new Simulink model window. Then, drag and drop an Idmodel block from
the library into the model window.
4 Open the Function Block Parameters dialog box by double-clicking the Idmodel
block. Specify the following block parameters:
13-8
Prerequisites
6 Simulate the model for 2 seconds, and compare the simulated output ysim with the
measured output ymeasured using the Scope block.
13-9
13-10
14
1 Import your data into the MATLAB workspace, as described in “Representing Data
in MATLAB Workspace” on page 2-9.
2 Start a new session in the System Identification app, or open a saved session. For
more information, see “Starting a New Session in the App” on page 14-3.
3 Import data into the app from the MATLAB workspace. For more information, see
“Represent Data”.
4 Plot and preprocess data to prepare it for system identification. For example, you can
remove constant offsets or linear trends (for linear models only), filter data, or select
data regions of interest. For more information, see “Preprocess Data”.
5 Specify the data for estimation and validation. For more information, see “Specify
Estimation and Validation Data in the App” on page 2-30.
6 Select the model type to estimate using the Estimate menu.
7 Validate models. For more information, see “Model Validation”.
8 Export models to the MATLAB workspace for further analysis. For more
information, see “Exporting Models from the App to the MATLAB Workspace” on
page 14-10.
14-2
Working with System Identification App
A session represents the total progress of your identification process, including any data
sets and models in the System Identification app.
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 App” on page 14-3.
For more information about the steps for using the System Identification app, see “Steps
for Using the System Identification App” on page 14-2.
systemIdentification
14-3
14 System Identification App
Alternatively, you can start a new session by selecting the Apps tab of MATLAB
desktop. In the Apps section, click System Identification. This action opens the
System Identification app.
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.
The following figure describes the different areas in the System Identification app.
14-4
Working with System Identification App
Select check
boxes to display Select check
data plots. boxes to display
model plots.
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 app using 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 app, see “Steps
for Using the System Identification App” on page 14-2.
The Data Board area, located below the Import data menu in the System
Identification app, contains rectangular icons that represent the data you imported into
the app.
The Model Board, located to the right of the <--Preprocess menu in the System
Identification app, contains rectangular icons that represent the models you estimated or
imported into the app. You can drag and drop model icons in the Model Board into open
dialog boxes.
14-5
14 System Identification App
You can open a previously saved session using the following syntax:
systemIdentification(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 app is already open, you can open a session by selecting File
> Open session.
Note: If there is data in the System Identification app, you must close the current session
before you can open a new session by selecting File > Close session.
The following table summarizes the menu commands for saving, merging, and closing
sessions in the System Identification app.
14-6
Working with System Identification App
Deleting a Session
To delete a saved session, you must delete the corresponding session file.
Managing Models
• “Importing Models into the App” on page 14-7
• “Viewing Model Properties” on page 14-8
• “Renaming Models and Changing Display Color” on page 14-8
• “Organizing Model Icons” on page 14-9
• “Deleting Models in the App” on page 14-10
• “Exporting Models from the App to the MATLAB Workspace” on page 14-10
You can import System Identification Toolbox models from the MATLAB workspace into
the System Identification app. If you have Control System Toolbox software, you can also
import any models (LTI objects) you created using this toolbox.
The following procedure assumes that you begin with the System Identification app
already open. If this window is not open, type the following command at the prompt:
systemIdentification
1 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.
5 Click Close to close the Import Model Object dialog box.
14-7
14 System Identification App
You can get information about each model in the System Identification app by right-
clicking the corresponding model icon.
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 app. The Data/model Info dialog box
updates when you select each model.
You can rename a model and change its display color by double-clicking the model icon in
the System Identification app.
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 app.
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 App” on page 14-15.
Tip As an alternative to using three RGB values, you can enter any one of the following
letters in single quotes:
'y' 'r' 'b' 'c' 'g' 'm' 'k'
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.
14-8
Working with System Identification App
You can rearrange model icons in the System Identification app by dragging and
dropping the icons to empty Model Board rectangles.
Note: You cannot drag and drop a model icon into the data area on the left.
When you need additional space for organizing model icons, select Options > Extra
model/data board in the System Identification app. 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 app 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 14-6, all additional
windows and notes are also saved.
14-9
14 System Identification App
To delete models in the System Identification app, drag and drop the corresponding icon
into Trash. You can also use the Delete key on your keyboard to move items to the
Trash. Moving items to Trash does not permanently delete these items.
To restore a model from Trash, drag its icon from Trash to the Model Board in the
System Identification app. 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.
The models you create in the System Identification app are not available in the MATLAB
workspace until you export them. Exporting is necessary when you need to perform an
operation on the model that is only available at the command line. Exporting models to
the MATLAB workspace also makes them available to the Simulink software or another
toolbox, such as the Control System Toolbox product.
14-10
Working with System Identification App
When you export models to the MATLAB workspace, the resulting variables have the
same name as in the System Identification app.
You can identify data sets and models on a plot by color: the color of the line in the data
or model icon in the System Identification app matches the line color on the plots.
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 14-12.
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.
14-11
14 System Identification App
There are two ways to change which portion of the plot is currently in view:
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.
14-12
Working with System Identification App
• 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.
Note: To restore the full range of the data in view, select Options > Autorange in the
plot window.
You can change axis limits for the vertical and the horizontal axes of the input and
output channels that are currently displayed 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.
Note: To view the entire data range, select Options > Autorange in the plot window.
14-13
14 System Identification App
Model inputs and outputs are called channels. When you create a plot of a multivariable
input-output data set or model, the plot only shows one input-output channel pair at a
time. The selected channel names are displayed in the title bar of 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 “Separation of Measured and Noise Components of Models” on page 3-117.
Tip When you import data into the System Identification app, it is helpful to assign
meaningful channel names in the Import Data dialog box. For more information about
importing data, see “Represent Data”.
There are several Style options that are common to all plot types. These include the
following:
Grid Lines
14-14
Working with System Identification App
To display currently visible lines as a combination of solid, dashed, dotted, and dash-
dotted line style, select Style > Separate linestyles.
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 app.
The MATLAB Figure window provides editing and printing commands for plots that are
not available in the System Identification Toolbox plot window. To take advantage of this
functionality, you can first create a plot in the System Identification app, and then open
it in a MATLAB Figure window to fine-tune the display.
After you create the plot, as described in “Plotting Models in the App” on page 10-6,
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.
The System Identification app lets you customize the window behavior and appearance.
For example, you can set the size and position of specific dialog boxes and modify the
appearance of plots.
You can save the session to save the customized app state.
You might choose to edit the file that controls default settings, as described in “Modifying
idlayout.m” on page 14-16 (advanced usage).
14-15
14 System Identification App
Use Options > Save preferences to save the current state of the System Identification
app. This command saves the following settings to a preferences file, idprefs.mat:
The idprefs.mat file is located in the same folder as startup.m, by default. To change
the location where your preferences are saved, use the midprefs command with the new
path as the argument. For example:
midprefs('c:\matlab\toolbox\local\')
You can also type midprefs and browse to the desired folder.
Modifying idlayout.m
You might want to customize the default plot options by editing idlayout.m (advanced
usage).
Caution Do not edit the original file to avoid overwriting the idlayout.m defaults
shipped with the product.
14-16
Working with System Identification App
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.
14-17
14-18