When the output of a system depends nonlinearly on its inputs, sometimes it is possible to decompose the input-output relationship into two or more interconnected elements. In this case, you can represent the dynamics by a linear transfer function and capture the nonlinearities using nonlinear functions of inputs and outputs of the linear system. The Hammerstein-Wiener model achieves this configuration as a series connection of static nonlinear blocks with a dynamic linear block.
Hammerstein-Wiener model applications span several areas, such as modeling electro-mechanical system and radio frequency components, audio and speech processing and predictive control of chemical processes. These models are popular because they have a convenient block representation, transparent relationship to linear systems, and are easier to implement than heavy-duty nonlinear models (such as neural networks and Volterra models).
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.
You can also use a Hammerstein-Wiener model as a grey-box structure to capture physical knowledge about process characteristics. For example, the input nonlinearity might represent typical physical transformations in actuators and the output nonlinearity might describe common sensor characteristics.
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.
System Identification Toolbox™ software provides several scalar nonlinearity estimators F(x) for Hammerstein-Wiener models. The nonlinearity estimators are available for both the input and output nonlinearities f and h, respectively. For more information about F(x), see Structure of Hammerstein-Wiener Models.
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.
Nonlinearity | Class | Structure | Comments | |
---|---|---|---|---|
Piecewise linear (default) | pwlinear | A piecewise linear function parameterized by breakpoint locations. | By default, the number of breakpoints is 10. | |
One layer sigmoid network | sigmoidnet | $$g(x)={\displaystyle \sum _{k=1}^{n}{\alpha}_{k}}\kappa \left({\beta}_{k}\left(x-{\gamma}_{k}\right)\right)$$ $$\kappa (s)$$ is the sigmoid function $$\kappa (s)={\left({e}^{s}+1\right)}^{-1}$$. $${\beta}_{k}$$ is a row vector such that $${\beta}_{k}(x-{\gamma}_{k})$$ is a scalar. | Default number of units n is 10. | |
Wavelet network | wavenet | $$g(x)={\displaystyle \sum _{k=1}^{n}{\alpha}_{k}}\kappa \left({\beta}_{k}\left(x-{\gamma}_{k}\right)\right)$$ where $$\kappa (s)$$ is the wavelet function. | By default, the estimation algorithm determines the number of units n automatically. | |
Saturation | saturation | Parameterize hard limits on the signal value as upper and lower saturation limits. | Use to model known saturation effects on signal amplitudes. | |
Dead zone | deadzone | Parameterize dead zones in signals as the duration of zero response. | Use to model known dead zones in signal amplitudes. | |
One- dimensional polynomial | poly1d | Single-variable polynomial of a degree that you specify. | By default, the polynomial degree is 1. | |
Unit gain | unitgain | Excludes the input or output nonlinearity from the model structure
to achieve a Wiener or Hammerstein configuration, respectively.
| Useful for configuring multi-input, multi-output (MIMO) models to exclude nonlinearities from specific input and output channels. | |
Custom network (user-defined) | customnet | Similar to sigmoid network but you specify $$\kappa (s)$$. | (For advanced use) Uses the unit function that you specify. |
Estimate a Hammerstein-Wiener model with default configuration by:
Specifying model order and input delay:
nb—The number of zeros plus one.
nf—The number of poles.
nk—The delay from input to the output in terms of the number of samples.
nb is the order of the transfer function numerator (B polynomial), and nf is the order of the transfer function denominator (F polynomial). As you fit different Hammerstein-Wiener models to your data, you can configure the linear block structure by specifying a different order and delay. For MIMO systems with ny outputs and nu inputs, nb, nf, and nk are ny-by-nu matrices.
Initializing using one of the following discrete-time linear models:
An input-output polynomial model of Output-Error (OE)
structure (idpoly
)
A linear state-space model with no disturbance component
(idss
object with K=0)
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 model, and the B and F polynomials as the transfer function numerator and denominator. See Using Linear Model for Hammerstein-Wiener Estimation.
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:
Configuring the input and output nonlinearity properties.
Excluding the input or output nonlinear block.
See these topics for detailed steps to change the model structure:
Estimation of Hammerstein-Wiener models uses iterative search to minimize the simulation error between the model output and the measured output.
You can configure the estimation using the nlhw
options
option set, nlhwOptions
. The
most commonly used options are:
Display
— Shows progress
of iterative minimization in the MATLAB^{®} Command Window.
SearchMethod
— Search method
for minimization of prediction or simulation errors, such as Gauss-Newton
and Levenberg-Marquardt line search, and Trust-region reflective Newton
approach.
SearchOption
— Option set
for the search algorithm, with fields that depend on the value of SearchMethod
.
Fields include:
MaxIter
— Maximum number
of iterations.
Tolerance
— Condition for
terminating iterative search when the expected improvement of the
parameter values is less than a specified value.
See the nlhwOptions
reference
page for more details about the estimation options.
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.
In the System Identification app, select Estimate > Nonlinear models to open the Nonlinear Models dialog box.
In the Configure tab, select Hammerstein-Wiener
from
the Model type list.
(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.
(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. |
The Initial Model list includes models that:
Exist in the System Identification app.
Have the same number of inputs and outputs as the dimensions of the estimation data (selected as Working Data in the System Identification app).
Keep the default settings in the Nonlinear Models dialog box that specify the model structure, or modify these settings:
Note: For more information about available options, click Help in the Nonlinear Models dialog box to open the app help. |
What to Configure | Options in Nonlinear Models GUI | Comment |
---|---|---|
Input or output nonlinearity | In the I/O Nonlinearity tab, select the Nonlinearity and specify the No. of Units. | If you do not know which nonlinearity to try, use the (default) piecewise linear nonlinearity. When you estimate
from binary input data, you cannot reliably estimate the input nonlinearity.
In this case, set Nonlinearity for the input
channel to 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 tab, specify B Order, F Order, and Input Delay. For MIMO systems, select the output channel and specify the orders and delays from each input channel. | If you do not know the input delay values, click Infer Input Delay. This action opens the Infer Input Delay dialog box which suggests possible delay values. |
Estimation algorithm | In the Estimate tab, click Estimation Options. | You can specify to estimate initial states. |
To obtain regularized estimates of model parameters, in the Estimate tab, click Estimation Options. Specify the regularization constants in the Regularization_Tradeoff_Constant and Regularization_Weighting fields. To learn more, see Regularized Estimates of Model Parameters.
Click Estimate to add this model to the System Identification app.
The Estimate tab displays the estimation progress and results.
Validate the model response by selecting the desired plot in the Model Views area of the System Identification app.
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.
Configure the nonlinearity estimator.
Exclude the input or output nonlinearity.
Improve estimation results using initial states.
What if you cannot get a satisfactory model?
This example shows how to use nlhw
to estimate a Hammerstein-Wiener model for measured input/output data.
Prepare the data for estimation.
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.
m5 = idnlhw([2 2 3],'dead','sat'); m5 = nlhw(ze,m5);
Compare the resulting models by plotting the model outputs on top of the measured output.
compare(zv,m1,m2,m3,m4,m5)
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.
Estimate a linear model.
load iddata1
LM = arx(z1,[2 2 1]);
Extract the transfer function coefficients from the linear model.
[Num, Den] = tfdata(LM);
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 and nu is number of inputs nf = nb; nk = 0; % In general, nk = zeros(ny,nu) % ny is number of outputs and 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 = nlhw(z1, M);
Compare responses of linear and nonlinear model against measured data.
compare(z1,LM,M);
You can use a polynomial model of Output-Error (OE) structure
(idpoly
) or state-space model with no disturbance
component (idss
model with K = 0) for Hammerstein-Wiener
estimation. The linear model must sufficiently represent the linear
dynamics of your system.
Tip To learn more about when to use linear models, see When to Fit Nonlinear Models. |
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.
Estimate a Hammerstein-Wiener model using either a linear input-output polynomial model of OE structure or state-space model by typing
m = nlhw(data,LinModel)
LinModel
must be an idpoly
model
of OE structure, a state-space model (idss
with K
=
0) or transfer function idtf
model. m
is
an idnlhw
object. data
is
a time-domain iddata
object.
By default, both the input and output nonlinearity estimators
are piecewise linear functions (see pwlinear
).
Specify different input and output nonlinearity, for example sigmoidnet
and deadzone
:
m = nlhw(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.
This example shows how to estimate Hammerstein-Wiener models using linear OE models.
Load the estimation data.
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 the data to view and analyze the data characteristics.
plot(ThrottleData)
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 a Hammerstein-Wiener model to model the linear behavior of this single-input single-output system in the normal operating range.
% Detrend the data because linear models cannot capture offsets. Tr = getTrend(ThrottleData); Tr.OutputOffset = 15; DetrendedData = detrend(ThrottleData,Tr); % Estimate a linear OE model with na=2, nb=1, nk=1. opt = oeOptions('Focus','simulation'); LinearModel = oe(DetrendedData,[2 1 1],opt);
Compare the simulated model response with estimation data.
compare(DetrendedData, LinearModel)
The linear model captures the rising and settling behavior in the linear operating range but does not account for output saturation at 90 degrees.
Estimate a Hammerstein-Wiener model to model the output saturation.
NonlinearModel = nlhw(ThrottleData, LinearModel, [], 'saturation');
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 the nonlinear model with data.
compare(ThrottleData, NonlinearModel)
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:
u_{NL} — Input
nonlinearity, representing the static nonlinearity at the
input (model.InputNonlinearity
) to the Linear
Block
.
Linear Block
— Step, impulse,
Bode and pole-zero plots of the embedded linear model (model.LinearModel
).
By default, a step plot is displayed.
y_{NL} — Output
nonlinearity, representing the static nonlinearity at the
output (model.OutputNonlinearity
) of the Linear
Block
.
To create a Hammerstein-Wiener plot in the System Identification app, select the Hamm-Wiener check box in the Model Views area. For general information about creating and working with plots, see Working with Plots.
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 U_{NL}
is
selected. You can select the output nonlinearity block Y_{NL}
or Linear
Block
, as shown in the next figure.
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:
Compare Model Output to Measured Output
Simulate and Predict Model Response
Check Iterative Search Termination Conditions
The Hammerstein-Wiener model can contain up to two nonlinear blocks. The nonlinearity at the input to the Linear Block is labeled u_{NL} and is called the input nonlinearity. The nonlinearity at the output of the Linear Block is labeled y_{NL} and is called the output nonlinearity.
To configure the plot, perform the following steps:
If the top pane is not visible, click to expand the Hammerstein-Wiener Model Plot window.
Select the nonlinear block you want to plot:
To plot the response of the input nonlinearity function, click the u_{NL} block.
To plot the response of the output nonlinearity function, click the y_{NL} block.
The selected block is highlighted in green.
Note: The input to the output nonlinearity block y_{NL} is the output from the Linear Block and not the measured input data. |
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.
Click Apply to update the plot.
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.
To configure the plot:
If the top pane is not visible, click to expand the Hammerstein-Wiener Model Plot window.
Click the Linear Block to select it. The Linear Block is highlighted in green.
In the Select I/O pair list, select the input and output data pair for which to view the response.
In the Choose plot type list, select the linear plot from the following options:
Step
Impulse
Bode
Pole-Zero Map
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.
Click Apply and then Close.
If you selected to plot a Bode plot, you can set the frequency range.
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.
Enter the frequency vector using any one of following methods:
MATLAB expression, such as (1:100)*pi/100
or logspace(-3,-1,200)
.
Cannot contain variables in the MATLAB workspace.
Row vector of values, such as (1:.1:100)
.
Click Apply and then Close.
In most applications, sim
and predict
are sufficient for computing the
simulated and predicted model response, respectively. This topic describes
how the software evaluates the output of nonlinearity estimators and
uses this output to compute the model response.
Evaluating the 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 output 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.
For example, suppose that you estimate a two-input model:
M = nlhw(data,[nb nf nk],[wavenet;poly1d],'saturation')
In the input nonlinearity:
F = M.InputNonlinearity F1 = F(1); F2 = F(2);
F
is a vector function containing two elements: F=[F1(u1_value);F2(u2_value)]
,
where F1
is a wavenet
object
and F2
is a poly1d
object. u1_value
is
the first input signal and u2_value
is the second
input signal.
Evaluate F
by evaluating F1
and F2
separately:
w1 = evaluate(F(1),u1_value); w2 = evaluate(F(2),u2_value);
The total input to the linear block, w
, is
a vector of w1
and w2
(w
= [w1 w2]
).
Similarly, you can evaluate the value of the nonlinearity H:
H = M.OutputNonlinearity %equivalent to H = M.ynl
This example shows how the software evaluates the simulated output by first computing the output of the input and output nonlinearity estimators.
Estimate a Hammerstein-Wiener model.
load twotankdata estData = iddata(y,u,0.2); M = nlhw(estData,[1 5 3],'pwlinear','poly1d');
Extract the input nonlinearity, linear model, and output nonlinearity as separate variables.
uNL = M.InputNonlinearity; linModel = M.LinearModel; yNL = M.OutputNonlinearity;
Simulate the output of the input nonlinearity estimator.
% Input data for simulation u = estData.u; % Compute output of input nonlinearity w = evaluate(uNL,u); % Response of linear model to input w and zero initial conditions. x = sim(linModel,w); % Compute the output of the Hammerstein-Wiener model M % as the output of the output nonlinearity estimator to input x. y = evaluate(yNL,x); % Previous commands are equivalent to. ysim = sim(M,u); % Compare low-level and direct simulation results. time = estData.SamplingInstants; plot(time,y,time,ysim,'.')