Accelerating the pace of engineering and science

Documentation

Identifying Hammerstein-Wiener Models

Applications of Hammerstein-Wiener Models

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.

Structure of Hammerstein-Wiener Models

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}\left(q\right)}{{F}_{j,i}\left(q\right)}$

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:

1. 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.

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)).

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. See the idnlhw reference page for more information.

Nonlinearity Estimators for Hammerstein-Wiener Models

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.

Piecewise linear
(default)
pwlinearA piecewise linear function parameterized by breakpoint locations. By default, the number of breakpoints is 10.
One layer sigmoid networksigmoidnet

$g\left(x\right)=\sum _{k=1}^{n}{\alpha }_{k}\kappa \left({\beta }_{k}\left(x-{\gamma }_{k}\right)\right)$

$\kappa \left(s\right)$ is the sigmoid function $\kappa \left(s\right)={\left({e}^{s}+1\right)}^{-1}$. ${\beta }_{k}$ is a row vector such that ${\beta }_{k}\left(x-{\gamma }_{k}\right)$ is a scalar.

Default number of units n is 10.
Wavelet networkwavenet

$g\left(x\right)=\sum _{k=1}^{n}{\alpha }_{k}\kappa \left({\beta }_{k}\left(x-{\gamma }_{k}\right)\right)$

where $\kappa \left(s\right)$ is the wavelet function.

By default, the estimation algorithm determines the number of units nautomatically.
SaturationsaturationParameterize hard limits on the signal value as upper and lower saturation limits.Use to model known saturation effects on signal amplitudes.
One-
dimensional polynomial
poly1dSingle-variable polynomial of a degree that you specify.By default, the polynomial degree is 1.
Unit gainunitgainExcludes the input or output nonlinearity from the model structure to achieve a Wiener or Hammerstein configuration, respectively.
 Note:   Excluding both the input and output nonlinearities reduces the Hammerstein-Wiener structure to a linear transfer function.
Useful for configuring multi-input, multi-output (MIMO) models to exclude nonlinearities from specific input and output channels.
Custom network
(user-defined)
customnetSimilar to sigmoid network but you specify $\kappa \left(s\right)$.(For advanced use)
Uses the unit function that you specify.

Ways to Configure Hammerstein-Wiener Estimation

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 Algorithm for Hammerstein-Wiener Models

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 method using the Algorithm properties of the idnlhw class. The most common of these properties are:

• MaxIter — Maximum number of iterations.

• 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.

• Tolerance — Condition for terminating iterative search when the expected improvement of the parameter values is less than a specified value.

• Display — Shows progress of iterative minimization in the MATLAB® Command Window.

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.

How to Estimate Hammerstein-Wiener Models in the System Identification App

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.

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).

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.
What to ConfigureOptions in Nonlinear Models GUIComment
Input or output nonlinearityIn 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 None.

For multiple-input and multiple-output systems, you can assign nonlinearities to specific input and output channels.

Model order and delayIn 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 algorithmIn the Estimate tab, click Algorithm Options.You can specify to estimate initial states.

6. 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.

7. Click Estimate to add this model to the System Identification app.

The Estimate tab displays the estimation progress and results.

8. 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.

How to Estimate Hammerstein-Wiener Models at the Command Line

Use nlhw to Estimate Hammerstein-Wiener Models

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 = pem(ze,m5);
```

Compare the resulting models by plotting the model outputs on top of the measured output.

```compare(zv,m1,m2,m3,m4,m5)
```

Improve a Linear Model Using Hammerstein-Wiener Structure

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 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 responses of linear and nonlinear model against measured data.

```compare(z1,LM,M);
```

Using Linear Model for Hammerstein-Wiener Estimation

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.

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.

How to Initialize Hammerstein-Wiener Estimation Using Linear Polynomial Output-Error or State-Space Models

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 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.

Estimate Hammerstein-Wiener Models Using Linear OE Models

This example shows how to estimate Hammerstein-Wiener models using linear OE 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 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)
```

Validating Hammerstein-Wiener Models

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:

• uNLInput 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.

• yNLOutput nonlinearity, representing the static nonlinearity at the output (model.OutputNonlinearity) of the Linear Block.

How to Create Hammerstein-Wiener Plots in the App

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.

 Note:   The Hamm-Wiener check box is unavailable if you do not have a Hammerstein-Wiener model in the Model Board.

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.

How to Validate Hammerstein-Wiener Models at the Command Line

You can use the following approaches to validate Hammerstein-Wiener models at the command line:

Plotting Nonlinear Block Characteristics

The Hammerstein-Wiener model can contain up to two nonlinear blocks. The nonlinearity at the input to the Linear Block is labeled uNL and is called the input nonlinearity. The nonlinearity at the output of the Linear Block is labeled yNL and is called the output nonlinearity.

To configure the plot, perform the following steps:

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.

The selected block is highlighted in green.

 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.

Plotting Linear Block Characteristics

The Hammerstein-Wiener model contains one Linear Block that represents the embedded linear model.

To configure the plot:

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.

Click Apply and then Close.

2. 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.

How the Software Computes Hammerstein-Wiener Model Output

In most applications, sim(idnlhw) and predict are sufficient for computing the simulated and predicted model response, respectively. This advanced topic describes how the software evaluates the output of nonlinearity estimators and uses this output to compute the model response.

Evaluating Nonlinearities (SISO)

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)`

Evaluating Nonlinearities (MIMO)

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`

Low-level Simulation of Hammerstein-Wiener Model

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.

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, '.')
```