# LMS Update

Estimate weights of LMS adaptive filter

• Library:
• DSP System Toolbox / Filtering / Adaptive Filters

## Description

The LMS Update block estimates the weights of an LMS adaptive filter. Specify data and error as inputs and the block computes the filter weights based on the algorithm specified in the Algorithm parameter. For more details on the algorithms, see Algorithms.

You can configure the block to operate as a tapped-delay line FIR filter or as an adaptive linear combiner using the Adaptive filter mode parameter. The block can also adapt multiple filters independently when you specify the Number of adaptive filters parameter to a value greater than 1.

You can use this block to compute the adaptive filter weights in applications such as system identification, inverse modeling, and filtered-x LMS algorithms, which are used in acoustic noise cancellation. For more details, see References.

## Ports

### Input

expand all

Data input to the adaptive filter, specified as one of these:

• Scalar –– When you set the Adaptive filter mode parameter to ```Tapped delay-line FIR filter```, the input to the block should be a scalar.

The block algorithm buffers the input samples to generate the vector $u\left(n\right)=\left[\text{u}\left(n\right),\text{u}\left(n-1\right),...,\text{u}\left(n-L+1\right)\right]$, where L is the length of the adaptive filter and n is the time index. The block algorithm then passes the vector through the filter.

• Column vector of length L –– When you set the Adaptive filter mode parameter to `Adaptive linear combiner`, the block does not buffer the input samples, and the input to the block should be in the form of a column vector. The block multiplies the vector with the filter weights to generate the filter output. In this case, there is no relationship between the input samples.

When you set the Number of adaptive filters parameter to a value greater than 1, the block assumes that all filters run on the same input.

When you set the Algorithm parameter to `Sign—Error LMS`, `Sign—Data LMS`, or `Sign—Sign LMS`, the data input through the Input port must be real.

Data Types: `single` | `double`
Complex Number Support: Yes

Specify the error between the output signal and the desired signal as a:

• Scalar when the number of adaptive filters N = 1.

• Column vector of length N when N > 1.

When you set the Algorithm parameter to `Sign—Error LMS`, `Sign—Data LMS`, or `Sign—Sign LMS`, the error input through the Error port must be real.

Data Types: `single` | `double`
Complex Number Support: Yes

Specify the filter adaptation step size as a scalar in the range [0,1].

#### Dependency

To enable this port, set Step size source to `Input port`.

Data Types: `single` | `double`

The input to this port can be one of these:

• Scalar –– If the number of adaptive filters (N) is greater than 1, then the block updates the filter weights for all filters if the value at the port is nonzero and does not update if the value at the port is 0.

• Vector of length N –– If the number of adaptive filters (N) is greater than 1, then the block determines whether to update each filter during run time depending on the value of the corresponding element in the Adapt vector input. When the Adapt port input element is not 0, the block updates the filter weights. When the input is 0, the filter weights do not change.

For an example, see Adapt Multiple Filters Using LMS Update block.

#### Dependency

To enable this port, select the Enable adapt input parameter on the block dialog.

Data Types: `single` | `double` | `Boolean` | `int16` | `int32` | `int64` | `int8` | `uint16` | `uint32` | `uint64` | `uint8`

When the input to this port is not 0, the block resets the filter weights to their initial values. When the input to this port is 0, the filter weights do not change.

#### Dependency

To enable this port, select the Enable reset input parameter on the block dialog.

Data Types: `single` | `double` | `Boolean` | `int16` | `int32` | `int64` | `int8` | `uint16` | `uint32` | `uint64` | `uint8`

### Output

expand all

The block outputs the filter weights as a 1-by-L row vector or a N-by-L matrix, where N is the number of adaptive filters, and L is the length of each filter.

Data Types: `single` | `double`

## Parameters

expand all

The block uses one of the listed algorithms to compute the filter weights. For more details on the algorithms, see Algorithms.

Specify the length of each adaptive filter L as a positive integer.

When there are N adaptive filters, the weights vector the block generates through the Wts output port is an N-by-L matrix.

Specify the number of adaptive filters N the block supports as a positive integer.

When you specify this value to be an integer greater than 1, each filter can be chosen to adapt independently during run time by providing the Adapt input as a logical vector of length N. All filters are assumed to run on the same input and have a common step size, leakage factor, and reset input.

The weights the block generates through the Wts output port is an N-by-L matrix, where L is the length of each filter.

For an example that shows how to adapt multiple filters, see Adapt Multiple Filters Using LMS Update block.

• `Property` — Specify the filter adaptation size using the Step size (mu) parameter.

• `Input port` — Pass filter adaptation size using the Mu input port.

Step size (mu) indicates the amount by which the filter weights are updated in each iteration. Choose an optimal step size so that the filter is stable and the convergence speed is optimal.

This parameter is tunable. You can change its value even during the simulation.

Tunable: Yes

#### Dependency

To enable this parameter, set Step size source to `Property`.

Leakage factor (0 to 1) prevents unbounded growth of the filter coefficients by reducing the drift of the coefficients from their optimum values. A leakage factor of `1.0` indicates no leakage. If you encounter coefficient drift, that is, large fluctuation about the optimum solution, decrease the leakage factor until the coefficient fluctuation becomes small.

This parameter is tunable. You can change its value even during the simulation.

Tunable: Yes

Specify the initial value of filter weights as one of the following:

• Scalar

• Vector of size 1-by-L –– N is set to 1

• Matrix of size N-by-L –– N > 1 and L > 1

where N is the number of adaptive filters specified in Number of adaptive filters and L is the length of each filter specified in Filter length.

This parameter specifies the initial value of the filter weights w(n−1). The block uses this value to compute the weights w(n), when n = 1. For more information, see Algorithms.

Specify the adaptive filter mode as one of the following:

• `Tapped delay-line FIR filter` –– The block assumes the variable portion of the adaptive filter to be a tapped delay-line FIR filter. In this mode, the input samples are related using this equation:

`$u\left(n\right)=\left[\text{u}\left(n\right),\text{u}\left(n-1\right),...,\text{u}\left(n-L+1\right)\right]$`

where n is the current time index and L is the length of the adaptive filter specified in the Filter length parameter.

The block accepts scalar input samples in this mode. The block algorithm buffers the samples to form the u(n) vector.

• `Adaptive linear combiner` –– The block does not buffer the input samples, and the input you provide to the block must be a column vector equal in length to the Filter length parameter. In this case, there is no relationship between the input samples.

For more details, see Algorithms.

When you select this check box, the Adapt input port appears on the block. When the input to this port is greater than 0, the block updates the filter weights. When the input to this port is less than or equal to 0, the filter weights do not change.

When you select this check box, the Reset input port appears on the block. When the input to this port is greater than 0, the block resets the filter weights to their initial values. When the input to this port is less than or equal to 0, the filter weights do not change.

Specify the type of simulation to run as one of the following:

• `Code generation` –– Simulate model using generated C code. The first time you run a simulation, Simulink® generates C code for the block. The C code is reused for subsequent simulations, as long as the model does not change. This option requires additional startup time but provides faster simulation speed than `Interpreted execution`.

• `Interpreted execution` –– Simulate model using the MATLAB®  interpreter. This option shortens startup time but has slower simulation speed than `Code generation`.

## Block Characteristics

 Data Types `double` | `single` Direct Feedthrough `no` Multidimensional Signals `no` Variable-Size Signals `no` Zero-Crossing Detection `no`

## Algorithms

expand all

In a closed loop adaptive filter, the weights or coefficients of the filter are adjusted until the error is minimized. The error is the difference between the filter output and the desired signal. In this block, the error signal is specified through the Error input port.

The block computes filter weight estimates using $w\left(n\right)=\alpha w\left(n-1\right)+f\left(u\left(n\right),e\left(n\right),\mu \right)$.

The function $f\left(u\left(n\right),e\left(n\right),\mu \right)$ is defined according to the LMS algorithm you specify through the Algorithm parameter:

• `LMS`$f\left(u\left(n\right),e\left(n\right),\mu \right)=\mu e\left(n\right){u}^{*}\left(n\right)$

• `Normalized LMS`$f\left(u\left(n\right),e\left(n\right),\mu \right)=\mu e\left(n\right)\frac{{u}^{\ast }\left(n\right)}{\epsilon +{u}^{H}\left(n\right)u\left(n\right)}$

In the `Normalized LMS` algorithm, ε is a small positive constant that overcomes the potential numerical instability in the update of weights.

For double-precision floating-point input, ε is the output of the `eps` function. For single-precision floating-point input, ε is the output of `eps("single")`. For fixed-point input, ε is 0.

• `Sign-Error LMS`$f\left(u\left(n\right),e\left(n\right),\mu \right)=\mu \text{sign}\left(e\left(n\right)\right){u}^{*}\left(n\right)$

• `Sign-Data LMS`$f\left(u\left(n\right),e\left(n\right),\mu \right)=\mu e\left(n\right)\text{sign}\left(u\left(n\right)\right)$, where u(n) is real

• `Sign-Sign LMS`$f\left(u\left(n\right),e\left(n\right),\mu \right)=\mu \text{sign}\left(e\left(n\right)\right)\text{sign}\left(u\left(n\right)\right)$, where u(n) is real

In the equations:

• n — The current time index.

• u(n) — The vector of input samples at step n.

When you set the Adaptive filter mode parameter to `Tapped delay-line FIR filter`, the input to the block is a scalar value and the block buffers the input samples to generate the u(n) vector.

When you set the Adaptive filter mode parameter to `Adaptive linear combiner`, the block does not buffer the samples. The input to the block should be in the form of a column vector. In this case, there is no relationship between the input samples.

• u*(n) — The complex conjugate of the vector of input samples at step n.

• w(n) — The vector of filter weight estimates at step n.

• e(n) — The estimation error at step n.

• µ — The adaptation step size.

• α — The leakage factor (0 ≤ α ≤ 1).

## References

[1] Madisetti, Vijay, and Douglas Williams. "Introduction to Adaptive Filters." The Digital Signal Processing Handbook. Boca Raton, FL: CRC Press, 1999.

[2] Akhtar, M. T., M. Abe, M. Kawamata. "Modified-filtered-x LMS algorithm based active noise control systems with improved online secondary-path modeling." IEEE Symposium on Circuits and Systems, 2004.

[3] Orfanidis, Sophocles J. Optimum Signal Processing. An Introduction. 2nd Ed. Englewood Cliffs, NJ: Prentice-Hall, 1996.http://eceweb1.rutgers.edu/%7Eorfanidi/osp2e/osp2e.pdf

## Version History

Introduced in R2016b