| Signal Processing Blockset™ | ![]() |
Filtering / Adaptive Filters
dspadpt3

The LMS Filter block can implement an adaptive FIR filter using five different algorithms. The block estimates the filter weights, or coefficients, needed to minimize the error, e(n), between the output signal y(n) and the desired signal, d(n). Connect the signal you want to filter to the Input port. This input signal can be a sample-based scalar or a single-channel frame-based signal. Connect the desired signal to the Desired port. The desired signal must have the same data type, frame status, complexity, and dimensions as the input signal. The Output port outputs the filtered input signal, which is the estimate of the desired signal. The output of the Output port has the same frame status as the input signal. The Error port outputs the result of subtracting the output signal from the desired signal.
When you select LMS for the Algorithm parameter, the block calculates the filter weights using the least mean-square (LMS) algorithm. This algorithm is defined by the following equations.

The weight update function for the LMS adaptive filter algorithm is defined as
![]()
The variables are as follows.
| Variable | Description |
|---|---|
n | The current time index |
u(n) | The vector of buffered input samples at step n |
u*(n) | The complex conjugate of the vector of buffered input samples at step n |
w(n) | The vector of filter weight estimates at step n |
y(n) | The filtered output at step n |
e(n) | The estimation error at step n |
d(n) | The desired response at step n |
µ | The adaptation step size |
When you select Normalized LMS for the Algorithm parameter, the block calculates the filter weights using the normalized LMS algorithm. The weight update function for the normalized LMS algorithm is defined as

To overcome potential numerical instability in the update of the weights, a small positive constant, epsilon, has been added in the denominator. For double-precision floating-point input, epsilon is 2.2204460492503131e-016. For single-precision floating-point input, epsilon is 1.192092896e-07. For fixed-point input, epsilon is 0.
When you select Sign-Error LMS for the Algorithm parameter, the block calculates the filter weights using the LMS algorithm equations. However, each time the block updates the weights, it replaces the error term e(n) with +1 when the error term is positive, -1 when it is negative, or 0 when it is zero.
When you select Sign-Data LMS for the Algorithm parameter, the block calculates the filter weights using the LMS algorithm equations. However, each time the block updates the weights, it replaces each sample of the input vector u (n) with +1 when the input sample is positive, -1 when it is negative, or 0 when it is zero.
When you select Sign-Sign LMS for the Algorithm parameter, the block calculates the filter weights using the LMS algorithm equations. However, each time the block updates the weights, it replaces the error term e(n) with +1 when the error term is positive, -1 when it is negative, or 0 when it is zero. It also replaces each sample of the input vector u (n) with +1 when the input sample is positive, -1 when it is negative, or 0 when it is zero.
Use the Filter length parameter to specify the length of the filter weights vector.
The Step size (mu) parameter corresponds to µ in the equations. For convergence of the normalized LMS equations, 0<µ<2. You can either specify a step size using the input port, Step-size, or by entering a value in the Block Parameters: LMS Filter dialog.
Use the Leakage factor (0 to 1) parameter to specify the leakage factor 1 – μα where 0 < 1 – μα ≤ 1 in the leaky LMS algorithm shown below.
![]()
When you select LMS from the Algorithm list, the weight update function in the above equation is the LMS weight update function. When you select Normalized LMS from the Algorithm list, the weight update function in the above equation is the normalized LMS weight update function.
Enter the initial filter weights w(0) as a vector or a scalar in the Initial value of filter weights text box. When you enter a scalar, the block uses the scalar value to create a vector of filter weights. This vector has length equal to the filter length and all of its values are equal to the scalar value.
When you select the Adapt port check box, an Adapt port appears on the block. When the input to this port is greater than zero, the block continuously updates the filter weights. When the input to this port is less than or equal to zero, the filter weights remain at their current values.
When you want to reset the value of the filter weights to their initial values, use the Reset port parameter. The block resets the filter weights whenever a reset event is detected at the Reset port. The reset signal rate must be the same rate as the data signal input.
From the Reset port list, select None to disable the Reset port. To enable the Reset port, select one of the following from the Reset port list:
Rising edge — Triggers a reset operation when the Reset input does one of the following:
Rises from a negative value to a positive value or zero
Rises from zero to a positive value, where the rise is not a continuation of a rise from a negative value to zero (see the following figure)

Falling edge — Triggers a reset operation when the Reset input does one of the following:
Falls from a positive value to a negative value or zero
Falls from zero to a negative value, where the fall is not a continuation of a fall from a positive value to zero (see the following figure)

Either edge — Triggers a reset operation when the Reset input is a Rising edge or Falling edge (as described above)
Non-zero sample — Triggers a reset operation at each sample time that the Reset input is not zero
Note When running simulations in the Simulink MultiTasking mode, sample-based reset signals have a one-sample latency, and frame-based reset signals have one frame of latency. Thus, there is a one-sample or one-frame delay between the time the block detects a reset event, and when it applies the reset. For more information on latency and the Simulink tasking modes, see Excess Algorithmic Delay (Tasking Latency) and Models with Multiple Sample Rates in the Real-Time Workshop User's Guide. |
Select the Output filter weights check box to create a Wts port on the block. For each iteration, the block outputs the current updated filter weights from this port.
The following diagrams show the data types used within the LMS Filter block for fixed-point signals; the table summarizes the definitions of variables used in the diagrams:
| Variable | Definition |
|---|---|
u | Input vector |
W | Vector of filter weights |
µ | Step size |
e | Error |
Q | Quotient,
|
Product u'u | Product data type in Energy calculation diagram |
Accumulator u'u | Accumulator data type in Energy calculation diagram |
Product W'u | Product data type in Convolution diagram |
Accumulator W'u | Accumulator data type in Convolution diagram |
Product
| Product data type in Product of step size and error diagram |
Product
| Product and accumulator data type in Weight update diagram. 1 |
1The accumulator data type for this quantity is automatically set to be the same as the product data type. The minimum, maximum, and overflow information for this accumulator is logged as part of the product information. Autoscaling treats this product and accumulator as one data type.


You can set the data type of the parameters, weights, products, quotient, and accumulators in the block mask. Fixed-point inputs, outputs, and mask parameters of this block must have the following characteristics:
The input signal and the desired signal must have the same word length, but their fraction lengths can differ.
The step size and leakage factor must have the same word length, but their fraction lengths can differ.
The output signal and the error signal have the same word length and the same fraction length as the desired signal.
The quotient and the product output of the u'u, W'u,
, and
operations must
have the same word length, but their fraction lengths can differ.
The accumulator data type of the u'u and W'u operations must have the same word length, but their fraction lengths can differ.
The output of the multiplier is in the product output data type if at least one of the inputs to the multiplier is real. If both of the inputs to the multiplier are complex, the result of the multiplication is in the accumulator data type. For details on the complex multiplication performed, see Multiplication Data Types.
The Main pane of the LMS Filter block dialog appears as follows.

Choose the algorithm used to calculate the filter weights.
Enter the length of the FIR filter weights vector.
Select Dialog to enter a value for step size in the Block parameters: LMS Filter dialog. Select Input port to specify step size using the Step-size input port.
Enter the step size μ. Tunable.
Enter the leakage factor, 0 < 1 – μα ≤ 1. Tunable.
Specify the initial values of the FIR filter weights.
Select this check box to enable the Adapt input port.
Select this check box to enable the Reset input port.
Select this check box to export the filter weights from the Wts port.
The Fixed-point pane of the LMS Filter block dialog appears as follows.

Select the rounding mode for fixed-point operations.
Select the overflow mode for fixed-point operations.
This parameter is visible if, for the Specify step size via parameter, you choose Dialog. Choose how you specify the word length and the fraction length of the leakage factor and step size:
When you select Same word length as first input, the word length of the leakage factor and step size match that of the first input to the block. In this mode, the fraction length of the leakage factor and step size is automatically set to the binary-point only scaling that provides you with the best precision possible given the value and word length of the coefficients.
When you select Specify word length, you can enter the word length of the leakage factor and step size, in bits. In this mode, the fraction length of the leakage factor and step size is automatically set to the binary-point only scaling that provides you with the best precision possible given the value and word length of the coefficients.
When you select Binary point scaling, you can enter the word length and the fraction length of the leakage factor and step size, in bits. The leakage factor and the step size must have the same word length, but the fraction lengths can differ.
When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the leakage factor and step size. The leakage factor and the step size must have the same word length, but the slopes can differ. This block requires a power-of-two slope and a bias of zero.
If, for the Specify step size via parameter, you choose Input port, the word length of the leakage factor is the same as the word length of the step size input at the Step size port. The fraction length of the leakage factor is automatically set to the best precision possible based on the word length of the leakage factor.
Choose how you specify the word length and fraction length of the filter weights of the block:
When you select Same as first input, the word length and fraction length of the filter weights match those of the first input to the block.
When you select Binary point scaling, you can enter the word length and the fraction length of the filter weights, in bits.
When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the filter weights. This block requires a power-of-two slope and a bias of zero.
Choose how you specify the word length and fraction length of u'u, W'u,
,
, and the quotient,
Q. Here, u is the input vector, W is the vector of filter weights, μ is
the step size, e is the error, and Q is
the quotient, which is defined as
![]()
When you select Same as first input, the word length and fraction length of these quantities match those of the first input to the block.
When you select Binary point scaling, you can enter the word length and the fraction length of these quantities, in bits. The word length of the quantities must be the same, but the fraction lengths can differ.
When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of these quantities. The word length of the quantities must be the same, but the slopes can differ. This block requires a power-of-two slope and a bias of zero.
Use this parameter to specify how you would like to designate the word and fraction lengths of the accumulators for the u'u and W'u operations.
Note
This parameter is not used to designate
the word and fraction lengths of the accumulator for the
|
See Fixed-Point Data Types and Multiplication Data Types for illustrations depicting the use of the accumulator data type in this block:
When you select Same as first input, these characteristics match those of the input to the block.
When you select Binary point scaling, you can enter the word length and the fraction length of the accumulators, in bits. The word length of both the accumulators must be the same, but the fraction lengths can differ.
When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the accumulators. The word length of both the accumulators must be the same, but the slopes can differ. This block requires a power-of-two slope and a bias of zero.
Hayes, M.H. Statistical Digital Signal Processing and Modeling. New York: John Wiley & Sons, 1996.
| Port | Supported Data Types |
|---|---|
Input |
|
Desired |
|
Step-size |
|
Adapt |
|
Reset |
|
Output |
|
Error |
|
Wts |
|
| Kalman Adaptive Filter (Obsolete) | Signal Processing Blockset |
| RLS Filter | Signal Processing Blockset |
| Block LMS Filter | Signal Processing Blockset |
| Fast Block LMS Filter | Signal Processing Blockset |
See Adaptive Filters for related information.
![]() | LMS Adaptive Filter (Obsolete) | Lowpass Filter | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |