# nlhw

Estimate Hammerstein-Wiener model

## Syntax

## Description

refines
or estimates the parameters of a Hammerstein-Wiener model, `sys`

= nlhw(`Data`

,`sys0`

)`sys0`

,
using the estimation data.

Use this syntax to:

Update the parameters of a previously estimated model to improve the fit to the estimation data. In this case, the estimation algorithm uses the parameters of

`sys0`

as initial guesses.Estimate the parameters of a model previously created using the

`idnlhw`

constructor. Prior to estimation, you can configure the model properties using dot notation.

## Examples

### Estimate a Hammerstein-Wiener Model

```
load iddata3
m1 = nlhw(z3,[4 2 1]);
```

### Estimate a Hammerstein Model with Saturation

Load data.

load twotankdata; z = iddata(y,u,0.2,'Name','Two tank system'); z1 = z(1:1000);

Create a saturation object with lower limit of 0 and upper limit of 5.

`InputNL = idSaturation('LinearInterval',[0 5]);`

Estimate model with no output nonlinearity.

m = nlhw(z1,[2 3 0],InputNL,[]);

### Estimate Hammerstein-Wiener Model with a Custom Network Nonlinearity

Generating a custom network nonlinearity requires the definition of a user-defined unit function.

Define the unit function and save it as `gaussunit.m`

.

function [f,g,a] = gaussunit(x) % Custom unit function nonlinearity. % % Copyright 2015 The MathWorks, Inc. f = exp(-x.*x); if nargout>1 g = -2*x.*f; a = 0.2; end

Create a custom network nonlinearity using the `gaussunit`

function.

H = @gaussunit; CNet = idCustomNetwork(H);

Load the estimation data.

load twotankdata; z = iddata(y,u,0.2,'Name','Two tank system'); z1 = z(1:1000);

Estimate a Hammerstein-Wiener model using the custom network.

m = nlhw(z1,[5 1 3],CNet,[]);

### Estimate Default Hammerstein-Wiener Model Using an Input-Output Polynomial Model of OE Structure

Estimate linear OE model.

load throttledata.mat Tr = getTrend(ThrottleData); Tr.OutputOffset = 15; DetrendedData = detrend(ThrottleData, Tr); opt = oeOptions('Focus','simulation'); LinearModel = oe(DetrendedData,[1 2 1],opt);

Estimate Hammerstein-Wiener model using OE model as its linear component and saturation as its output nonlinearity.

sys = nlhw(ThrottleData,LinearModel,[],idSaturation);

### Estimate a Hammerstein-Wiener Model Using `idnlhw`

to first Define the Model Properties

Load the estimation data.

`load iddata1`

Construct a Hammerstein-Wiener model using `idnlhw`

to define the model properties `B`

and `F`

.

```
sys0 = idnlhw([2,2,0],[],'idWaveletNetwork');
sys0.B{1} = [0.8,1];
sys0.F{1} = [1,-1.2,0.5];
```

Estimate the model.

sys = nlhw(z1,sys0);

Estimate a Hammerstein-Wiener model using `nlhw`

to define the model properties `B`

and `F`

.

sys2 = nlhw(z1,[2,2,0],[],'idWaveletNetwork','B',{[0.8,1]},'F',{[1,-1.2,0.5]});

Compare the two estimated models to see that they are equivalent.

compare(z1,sys,'g',sys2,'r--');

### Refine a Hammerstein-Wiener Model Using Successive Calls of `nlhw`

Estimate a Hammerstein-Wiener Model.

load iddata3 sys = nlhw(z3,[4 2 1],'idSigmoidNetwork','idWaveletNetwork');

Refine the model, `sys`

.

sys = nlhw(z3,sys);

### Estimate Hammerstein-Wiener Model Using an Estimation Option Set

Create estimation option set for `nlhw`

to view estimation progress, use the Levenberg-Marquardt search method, and set the maximum iteration steps to `50`

.

opt = nlhwOptions; opt.Display = 'on'; opt.SearchMethod = 'lm'; opt.SearchOptions.MaxIterations = 50;

Load data and estimate the model.

```
load iddata3
sys = nlhw(z3,[4 2 1],idSigmoidNetwork,idPiecewiseLinear,opt);
```

## Input Arguments

`Data`

— Time domain data

`iddata`

object

Time-domain estimation data, specified as an `iddata`

.

`Orders`

— Order and delays of the linear subsystem transfer function

`[nb nf nk]`

vector of positive integers | `[nb nf nk]`

vector of matrices

Order and delays of the linear subsystem transfer function,
specified as a `[nb nf nk]`

vector.

Dimensions of `Orders`

:

For a SISO transfer function,

`Orders`

is a vector of positive integers.`nb`

is the number of zeros plus 1,`nf`

is the number of poles, and`nk`

is the input delay.For a MIMO transfer function with

`n`

inputs and_{u}`n`

outputs,_{y}`Orders`

is a vector of matrices.`nb`

,`nf`

, and`nk`

are`n`

-by-_{y}`n`

matrices whose_{u}*i-j*th entry specifies the orders and delay of the transfer function from the*j*th input to the*i*th output.

`InputNL`

— Input static nonlinearity

`'idPiecewiseLinear'`

(default) | `'idSigmoidNetwork'`

| `'idWaveletNetwork'`

| `'idSaturation'`

| `'idDeadZone'`

| `'idPolynomial1D'`

| `'idUnitGain'`

| nonlinearity estimator object | array of nonlinearity estimators

Input static nonlinearity estimator, specified as one of the following.

`'idPiecewiseLinear'` or `idPiecewiseLinear` object(default) | Piecewise linear function |

`'idSigmoidNetwork'` or `idSigmoidNetwork` object | Sigmoid network |

`'idWaveletNetwork'` or `idWaveletNetwork` object | Wavelet network |

`'idSaturation'` or `idSaturation` object | Saturation |

`'idDeadZone'` or `idDeadZone` object | Dead zone |

`'idPolynomial1D'` or `idPolynomial1D` object | One-dimensional polynomial |

`'idUnitGain'` or `[]` or`idUnitGain` object | Unit gain |

`idCustomNetwork` object | Custom network — Similar to `idSigmoidNetwork` , but with a
user-defined replacement for the sigmoid function. |

Specifying a character vector, for example `'idSigmoidNetwork'`

, creates a
nonlinearity estimator object with default settings. Use object representation instead to
configure the properties of a nonlinearity
estimator.

InputNL = idWaveletNetwork; InputNL.NumberOfUnits = 10;

Alternatively, use the associated input nonlinearity estimator function with Name-Value pair arguments.

`InputNL = idWaveletNetwork('NumberOfUnits',10);`

For `n`

input channels, you can specify nonlinear
estimators individually for each input channel by setting _{u}`InputNL`

to an
`n`

-by-1 array of nonlinearity
estimators._{u}

`InputNL = [idSigmoidNetwork('NumberofUnits',5); idDeadZone([-1,2])]`

`OutputNL`

— Output static nonlinearity

`'idPiecewiseLinear'`

(default) | `'idSigmoidNetwork'`

| `'idWaveletNetwork'`

| `'idSaturation'`

| `'idDeadZone'`

| `'idPolynomial1D'`

| `'idUnitGain'`

| nonlinearity estimator object | array of nonlinearity estimators

Output static nonlinearity estimator, specified as one of the following:

`'idPiecewiseLinear'` or `idPiecewiseLinear`
object(default) | Piecewise linear function |

`'idSigmoidNetwork'` or `idSigmoidNetwork`
object | Sigmoid network |

`'idWaveletNetwork'` or `idWaveletNetwork`
object | Wavelet network |

`'idSaturation'` or `idSaturation`
object | Saturation |

`'idDeadZone'` or `idDeadZone`
object | Dead zone |

`'idPolynomial1D'` or `idPolynomial1D`
object | One-dimensional polynomial |

`'idUnitGain'` or `[]` or`idUnitGain` object | Unit gain |

`idCustomNetwork`
object | Custom network — Similar to
`idSigmoidNetwork` , but with a user-defined
replacement for the sigmoid function. |

Specifying a character vector creates a nonlinearity estimator object with default settings. Use object representation instead to configure the properties of a nonlinearity estimator.

OutputNL = idSigmoidNetwork; OutputNL.NumberOfUnits = 10;

Alternatively, use the associated input nonlinearity estimator function with Name-Value pair arguments.

`OutputNL = idSigmoidNetwork('NumberOfUnits',10);`

For `n`

output channels,
you can specify nonlinear estimators individually for each output
channel by setting _{y}`OutputNL`

to an `n`

-by-1
array of nonlinearity estimators. To specify the same nonlinearity
for all outputs, specify a single output nonlinearity estimator._{y}

`LinModel`

— Discrete time linear model

`idpoly`

| `idss`

with `K`

= `0`

| `idtf`

Discrete-time linear model used to specify the linear subsystem, specified as one of the following:

Input-output polynomial model of Output-Error (OE) structure (

`idpoly`

)State-space model with no disturbance component (

`idss`

with`K`

=`0`

)Transfer function model (

`idtf`

)

Typically, you estimate the model using `oe`

, `n4sid`

, or `tfest`

.

`sys0`

— Hammerstein-Wiener model

`idnlhw`

object

Hammerstein-Wiener model, specified as an `idnlhw`

object. `sys0`

can
be:

A model previously created using

`idnlhw`

to specify model properties.A model previously estimated using

`nlhw`

, that you want to update using a new estimation data set.You can also refine

`sys0`

using the original estimation data set. If the previous estimation stopped when the numerical search was stuck at a local minima of the cost function, use`init`

to first randomize the parameters of`sys0`

. See`sys0.Report.Termination`

for search stopping conditions. Using`init`

does not guarantee a better solution on further refinement.

`Options`

— Estimation options

`nlhwOptions`

option set

Estimation options for Hammerstein-Wiener model identification,
specified as an `nlhwOptions`

option
set.

## Output Arguments

`sys`

— Estimated Hammerstein-Wiener model

`idnlhw`

object

Estimated Hammerstein-Wiener model, returned as an `idnlhw`

object.
The model is estimated using the specified model orders and delays,
input and output nonlinearity estimators, and estimation options.

Information about the estimation results and options used is
stored in the `Report`

property of the model. `Report`

has
the following fields:

Report Field | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|

`Status` | Summary of the model status, which indicates whether the model was created by construction or obtained by estimation. | ||||||||||||||||||

`Method` | Estimation command used. | ||||||||||||||||||

`Fit` | Quantitative assessment of the estimation, returned as a structure. See Loss Function and Model Quality Metrics for more information on these quality metrics. The structure has the following fields:
| ||||||||||||||||||

`Parameters` | Estimated values of model parameters. | ||||||||||||||||||

`OptionsUsed` | Option set used for estimation. If no custom options
were configured, this is a set of default options. See | ||||||||||||||||||

`RandState` | State of the random number stream at the start of estimation. Empty,
| ||||||||||||||||||

`DataUsed` | Attributes of the data used for estimation, returned as a structure with the following fields.
| ||||||||||||||||||

`Termination` | Termination conditions for the iterative search used for prediction error minimization, returned as a structure with the following fields:
For estimation methods that do not require numerical search optimization,
the |

For more information, see Estimation Report.

## Compatibility Considerations

### Use of previous `idnlarx`

and `idnlhw`

mapping object names is not recommended.

*Not recommended starting in R2021b*

Starting in R2021b, the mapping objects (also known as nonlinearities) used in the nonlinear components of the `idnlarx`

and `idnlhw`

objects have been renamed. The following table lists the name changes.

Pre-R2021b Name | R2021b Name |
---|---|

`wavenet` | `idWaveletNetwork` |

`sigmoidnet` | `idSigmoidNetwork` |

`treepartition` | `idTreePartition` |

`customnet` | `idCustomNetwork` |

`saturation` | `idSaturation` |

`deadzone` | `idDeadZone` |

`pwlinear` | `idPiecewiseLinear` |

`poly1d` | `idPolynomial1D` |

`unitgain` | `idUnitGain` |

`linear` | `idLinear` |

`neuralnet` | `idFeedforwardNetwork` |

Scripts with the old names still run normally, although they will produce a warning. Consider using the new names for continuing compatibility with newly developed features and algorithms. There are no plans to exclude the use of these object names at this time

## Extended Capabilities

### Automatic Parallel Support

Accelerate code by automatically running computation in parallel using Parallel Computing Toolbox™.

Parallel computing support is available for estimation using the
`lsqnonlin`

search method (requires Optimization Toolbox™). To enable parallel computing, use `nlhwOptions`

, set `SearchMethod`

to
`'lsqnonlin'`

, and set
`SearchOptions.Advanced.UseParallel`

to
`true`

.

For example:

```
opt = nlhwOptions;
opt.SearchMethod = 'lsqnonlin';
opt.SearchOptions.Advanced.UseParallel = true;
```

## See Also

`idnlhw`

| `nlhwOptions`

| `idnlhw/findop`

| `linapp`

| `linearize`

| `pem`

| `init`

| `oe`

| `tfest`

| `n4sid`

| `goodnessOfFit`

| `aic`

| `fpe`

### Topics

- Estimate Multiple Hammerstein-Wiener Models
- Estimate Hammerstein-Wiener Models Initialized Using Linear OE Models
- Identifying Hammerstein-Wiener Models
- Initialize Hammerstein-Wiener Estimation Using Linear Model
- Loss Function and Model Quality Metrics
- Regularized Estimates of Model Parameters
- Estimation Report

**Introduced in R2007a**

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

# Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)