Estimate and validate nonlinear models from single-input/single-output (SISO) data to find the one that best represents your system dynamics.
After completing this tutorial, you will be able to accomplish the following tasks using the System Identification app:
Import data objects from the MATLAB^{®} workspace into the app.
Estimate and validate nonlinear models from the data.
Plot and analyze the behavior of the nonlinearities.
This tutorial uses the data file twotankdata.mat
,
which contains SISO time-domain data for a two-tank system, shown
in the following figure.
Two-Tank System
In the two-tank system, water pours through a pipe into Tank 1, drains into Tank 2, and leaves the system through a small hole at the bottom of Tank 2. The measured input u(t) to the system is the voltage applied to the pump that feeds the water into Tank 1 (in volts). The measured output y(t) is the height of the water in the lower tank (in meters).
Based on Bernoulli's law, which states that water flowing through a small hole at the bottom of a tank depends nonlinearly on the level of the water in the tank, you expect the relationship between the input and the output data to be nonlinear.
twotankdata.mat
includes 3000 samples with
a sample time of 0.2 s.
You can estimate nonlinear discrete-time black-box models for both single-output and multiple-output time-domain data. You can choose from two types of nonlinear, black-box model structures:
Nonlinear ARX models
Hammerstein-Wiener models
Note: You can estimate Hammerstein-Wiener black-box models from input/output data only. These models do not support time-series data, where there is no input. |
For more information on estimating nonlinear black-box models, see Nonlinear Model Identification.
This block diagram represents the structure of a nonlinear ARX model in a simulation scenario:
The nonlinear ARX model computes the output y in two stages:
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).
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.
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 multilayer 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)={L}^{T}(x-r)+d+g\left(Q(x-r)\right)$$
x is a vector of the regressors. $${L}^{T}(x)+d$$ is the output of the linear function block and is affine when d≠0. d is a scalar offset. $$g\left(Q(x-r)\right)$$ 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.
This block diagram represents the structure of a Hammerstein-Wiener model:
where:
w(t) = f(u(t)) is a nonlinear function transforming input data u(t). w(t) has the same dimension as u(t).
x(t) = (B/F)w(t) is a linear transfer function. x(t) has the same dimension as y(t).
where B and F are similar to polynomials in the linear Output-Error model, as described in What Are Polynomial Models?.
For ny outputs and nu inputs, the linear block is a transfer function matrix containing entries:
$$\frac{{B}_{j,i}(q)}{{F}_{j,i}(q)}$$
where j = 1,2,...,ny
and i = 1,2,...,nu
.
y(t) = h(x(t)) is a nonlinear function that maps the output of the linear block to the system output.
w(t) and x(t) are internal variables that define the input and output of the linear block, respectively.
Because f acts on the input port of the linear block, this function is called the input nonlinearity. Similarly, because h acts on the output port of the linear block, this function is called the output nonlinearity. If system contains several inputs and outputs, you must define the functions f and h for each input and output signal.
You do not have to include both the input and the output nonlinearity in the model structure. When a model contains only the input nonlinearity f, it is called a Hammerstein model. Similarly, when the model contains only the output nonlinearity h), it is called a Wiener model.
The nonlinearities f and h are scalar functions, one nonlinear function for each input and output channel.
The Hammerstein-Wiener model computes the output y in three stages:
Computes w(t) = f(u(t)) from the input data.
w(t) is an input to the linear transfer function B/F.
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.
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.
Compute the model output by transforming the output of the linear block x(t) using the nonlinear function h: y(t) = h(x(t)).
Similar to the input nonlinearity, the output nonlinearity is a static function. Configure the output nonlinearity in the same way as the input nonlinearity. You can also remove the output nonlinearity, such that y(t) = x(t).
Resulting models are idnlhw
objects
that store all model data, including model parameters and nonlinearity
estimator.
Load sample data in twotankdata.mat
by typing
the following command in the MATLAB Command Window:
load twotankdata
This command loads the following two variables into the MATLAB Workspace browser:
u
is the input data, which is the
voltage applied to the pump that feeds the water into Tank 1 (in volts).
y
is the output data, which is
the water height in Tank 2 (in meters).
System Identification Toolbox™ data objects encapsulate both data values and data properties into a single entity. You can use the System Identification Toolbox commands to conveniently manipulate these data objects as single entities.
You must have already loaded the sample data into the MATLAB workspace, as described in Loading Data into the MATLAB Workspace.
Use the following commands to create two iddata
data objects, ze
and zv
,
where ze
contains data for model estimation and zv
contains
data for model validation. Ts
is the sample time.
Ts = 0.2; % Sample time is 0.2 sec z = iddata(y,u,Ts); % First 1000 samples used for estimation ze = z(1:1000); % Remaining samples used for validation zv = z(1001:3000);
To view the properties of the iddata
object,
use the get
command. For example:
get(ze)
MATLAB software returns the following data properties and values:
Domain: 'Time' Name: '' OutputData: [1000x1 double] y: 'Same as OutputData' OutputName: {'y1'} OutputUnit: {''} InputData: [1000x1 double] u: 'Same as InputData' InputName: {'u1'} InputUnit: {''} Period: Inf InterSample: 'zoh' Ts: 0.2000 Tstart: 0.2000 SamplingInstants: [1000x0 double] TimeUnit: 'seconds' ExperimentName: 'Exp1' Notes: {} UserData: []
To modify data properties, use dot notation. For example, to assign channel names and units that label plot axes, type the following syntax in the MATLAB Command Window:
% Set time units to minutes ze.TimeUnit = 'sec'; % Set names of input channels ze.InputName = 'Voltage'; % Set units for input variables ze.InputUnit = 'V'; % Set name of output channel ze.OutputName = 'Height'; % Set unit of output channel ze.OutputUnit = 'm'; % Set validation data properties zv.TimeUnit = 'sec'; zv.InputName = 'Voltage'; zv.InputUnit = 'V'; zv.OutputName = 'Height'; zv.OutputUnit = 'm';
To
verify that the InputName
property of ze
is
changed, type the following command:
ze.inputname
Tip
Property names, such as |
To open the System Identification app, type the following command in the MATLAB Command Window:
systemIdentification
The default session name, Untitled
,
appears in the title bar.
You can import the data objects into the app from the MATLAB workspace.
You must have already created the data objects, as described in Creating iddata Objects, and opened the app, as described in Starting the System Identification App.
To import data objects:
In the System Identification app, select Import data > Data object.
This action opens the Import Data dialog box.
Enter ze
in the Object field
to import the estimation data. Press Enter.
This action enters the object information into the Import Data fields.
Click More to view additional information about this data, including channel names and units.
Click Import to add the icon
named ze
to the System Identification app.
In the Import Data dialog box, type zv
in
the Object field to import the validation data.
Press Enter.
Click Import to add the icon
named zv
to the System Identification app.
In the Import Data dialog box, click Close.
In the System Identification app, drag the validation data zv icon to the Validation Data rectangle. The estimation data ze icon is already designated in the Working Data rectangle.
Alternatively, right-click the zv
icon to
open the Data/model Info dialog box. Select the Use as Validation
Data check-box. Click Apply and
then Close to add zv
to
the Validation Data rectangle.
The System Identification app now resembles the following figure.
In this portion of the tutorial, you estimate a nonlinear ARX model using default model structure and estimation options.
You must have already prepared the data, as described in Preparing Data. For more information about nonlinear ARX models, see What Is a Nonlinear ARX Model?
In the System Identification app, select Estimate > Nonlinear models.
This action opens the Nonlinear Models dialog box.
The Configure tab
is already open and the default Model type is Nonlinear
ARX
.
In the Regressors tab, the Input
Channels and Output Channels have Delay set
to 1
and No. of Terms set
to 2
. The model output y(t) is
related to the input u(t) via the following nonlinear
autoregressive equation:
$$y(t)=f\left(y(t-1),y(t-2),u(t-1),u(t-2)\right)$$
f is the nonlinearity estimator selected
in the Nonlinearity drop-down list of the Model
Properties tab, and is Wavelet Network
by
default. The number of units for the nonlinearity estimator is set
to Select automatically and controls the flexibility
of the nonlinearity—more units correspond to a more flexible
nonlinearity.
Click Estimate.
This
action adds the model nlarx1
to the System Identification
app, as shown in the following figure.
The Nonlinear Models dialog box displays a summary of the estimation information in the Estimate tab. The Fit (%) is the mean square error between the measured data and the simulated output of the model: 100% corresponds to a perfect fit (no error) and 0% to a model that is not capable of explaining any of the variation of the output and only the mean level.
Note: Fit (%) is computed using the estimation data set, and not the validation data set. However, the model output plot in the next step compares the fit to the validation data set. |
In the System Identification app, select the Model output check box.
This action simulates the model using the input validation data as input to the model and plots the simulated output on top of the output validation data.
The Best Fits area of the Model Output plot shows that the agreement between the model output and the validation-data output.
Perform the following procedure to view the shape of the nonlinearity as a function of regressors on a Nonlinear ARX Model plot.
In the System Identification app, select the Nonlinear ARX check box to view the nonlinearity cross-sections.
By default, the plot shows
the relationship between the output regressors Height(t-1)
and Height(t-2)
.
This plot shows a regular plane in the following figure. Thus, the
relationship between the regressors and the output is approximately
a linear plane.
In the Nonlinear ARX Model Plot
window, set Regressor 1 to Voltage(t-1)
.
Set Regressor 2 to Voltage(t-2)
.
Click Apply.
The relationship between these regressors and the output is nonlinear, as shown in the following plot.
To rotate the nonlinearity surface, select Style > Rotate 3D and drag the plot to a new orientation.
To display a 1-D cross-section
for Regressor 1, set Regressor 2 to none
, and click Apply.
The following figure shows the resulting nonlinearity magnitude for
Regressor 1, which represents the time-shifted voltage signal, Voltage(t-1)
.
In this portion of the tutorial, you estimate a nonlinear ARX model with specific input delay and nonlinearity settings. Typically, you select model orders by trial and error until you get a model that produces an accurate fit to the data.
You must have already estimated the nonlinear ARX model with default settings, as described in Estimating a Nonlinear ARX Model with Default Settings.
In the Nonlinear Models dialog box, click the Configure tab, and click the Regressors tab.
For the Voltage
input channel,
double-click the corresponding Delay cell, enter 3
,
and press Enter.
This action updates the Resulting Regressors list
to show Voltage(t-3)
and Voltage(t-4)
—
terms with a minimum input delay of three samples.
Click Estimate.
This
action adds the model nlarx2
to the System Identification
app and updates the Model Output window to include this model. The
Nonlinear Models dialog box displays the new estimation information
in the Estimate tab.
In the Nonlinear Models dialog box, click the Configure tab, and select the Model Properties tab.
In the Number of units in nonlinear block area,
select Enter, and type 6
.
This number controls the flexibility of the nonlinearity.
Click Estimate.
This
action adds the model nlarx3
to the System Identification
app. It also updates the Model Output window, as shown in the following
figure.
You can estimate a nonlinear ARX model that includes only a subset of standard regressors that enter as inputs to the nonlinear block. By default, all standard and custom regressors are used in the nonlinear block. In this portion of the tutorial, you only include standard regressors.
You must have already specified the model structure, as described in Changing the Nonlinear ARX Model Structure.
In the Nonlinear Models dialog box, click the Configure tab, and select the Regressors tab.
Click the Edit Regressors button to open the Model Regressors dialog box.
Clear the following check boxes:
Height(t-2)
Voltage(t-3)
Click OK.
This action excludes the time-shifted Height(t-2)
and Voltage(t-3)
from
the list of inputs to the nonlinear block.
Click Estimate.
This action adds the model nlarx4
to the
System Identification app. It also updates the Model Output window.
You can estimate a series of nonlinear ARX models by making
systematic variations to the model structure and base each new model
on the configuration of a previously estimated model. In this portion
of the tutorial, you estimate a nonlinear ARX model that is similar
to an existing model (nlarx3
), but with a different
nonlinearity.
In the Nonlinear Models dialog box, select the Configure tab. Click Initialize. This action opens the Initial Model Specification dialog box.
In the Initial Model list, select nlarx3
.
Click OK.
Click the Model Properties tab.
In the Nonlinearity list, select Sigmoid
Network
.
In the Number of units in nonlinear block field,
type 6
.
Click Estimate.
This
action adds the model nlarx5
to the System Identification
app. It also updates the Model Output plot, as shown in the following
figure.
The best model is the simplest model that accurately describes the dynamics.
To view information about the best model, including the model order, nonlinearity, and list of regressors, right-click the model icon in the System Identification app.
In this portion of the tutorial, you estimate nonlinear Hammerstein-Wiener models using default model structure and estimation options.
You must have already prepared the data, as described in Preparing Data. For more information about nonlinear ARX models, see What Is a Hammerstein-Wiener Model?
In the System Identification app, select Estimate > Nonlinear models to open the Nonlinear Models dialog box.
In the Configure tab, select Hammerstein-Wiener
in
the Model type list.
The I/O Nonlinearity tab is open. The default
nonlinearity estimator is Piecewise Linear
with 10
units
for Input Channels and Output Channels,
which corresponds to 10
breakpoints for the piecewise
linear function.
Select the Linear Block tab to view the model orders and input delay.
By default, the model orders and delay of the linear output-error (OE) model are n_{b}=2, n_{f}=3, and n_{k}=1.
Click Estimate.
This action adds the model nlhw1
to the System
Identification app.
In the System Identification app, select the Model output check box.
This action simulates the model using the input validation data as input to the model and plots the simulated output on top of the output validation data.
The Best Fits area of the Model Output window shows the agreement between the model output and the validation-data output.
You can plot the input/output nonlinearities and the linear transfer function of the model on a Hammerstein-Wiener plot.
In the System Identification app, select the Hamm-Wiener check box to view the Hammerstein-Wiener model plot.
The plot displays the input nonlinearity, as shown in the following figure.
Click the y_{NL} rectangle in the top portion of the Hammerstein-Wiener Model Plot window.
The plot updates to display the output nonlinearity.
Click the Linear Block rectangle in the top portion of the Hammerstein-Wiener Model Plot window.
The plot updates to display the step response of the linear transfer function.
In the Choose plot type list,
select Bode
. This action displays a Bode
plot of the linear transfer function.
In this portion of the tutorial, you estimate a Hammerstein-Wiener model with a specific model order and nonlinearity settings. Typically, you select model orders and delays by trial and error until you get a model that produces a satisfactory fit to the data.
You must have already estimated the Hammerstein-Wiener model with default settings, as described in Estimating Hammerstein-Wiener Models with Default Settings.
In the Nonlinear Models dialog box, click the Configure tab, and select the Linear Block tab.
For the Voltage
input channel,
double-click the corresponding Input Delay (nk) cell,
change the value to 3
, and press Enter.
Click Estimate.
This
action adds the model nlhw2
to the System Identification
app and the Model Output window is updated to include this model,
as shown in the following figure.
The Best Fits area
of the Model Output window shows the quality of the nlhw2
fit.
In this portion of the example, you modify the default Hammerstein-Wiener model structure by changing its nonlinearity estimator.
Tip
If you know that your system includes saturation or dead-zone
nonlinearities, you can specify these specialized nonlinearity estimators
in your model. |
In the Nonlinear Models dialog box, click the Configure tab.
In the I/O Nonlinearity tab,
for the Voltage
input, click the Nonlinearity cell,
and select Sigmoid Network
from the list.
Click the corresponding No. of Units cell and
set the value to 20
.
Click Estimate.
This action adds the model nlhw3
to the System
Identification app. It also updates the Model Output window, as shown
in the following figure.
In the Nonlinear Models dialog box, click the Configure tab.
In the I/O Nonlinearity tab,
set the Voltage
input Nonlinearity to Wavelet
Network
. This action sets the No. of Units to
be determined automatically, by default.
Set the Height
output Nonlinearity to One-dimensional
Polynomial
.
Click Estimate.
This
action adds the model nlhw4
to the System Identification
app. It also updates the Model Output window, as shown in the following
figure.
The best model is the simplest model that accurately describes the dynamics.
In this example, the best model fit was produced in Changing the Nonlinearity Estimator in a Hammerstein-Wiener Model.