主要内容

LMS Filter

R2026b

Minimize error between observed and desired signals

Since R2023a

  • LMS Filter block

Libraries:
DSP HDL Toolbox / Filtering

Description

The LMS Filter block estimates the filter weights and minimizes the error between a desired signal and an observed signal using the mean squared error (MSE) criteria. The block adapts its weights until the error between the data and the desired data is minimal. The block accepts scalar and vector inputs of type real and complex. The block supports two architecture options: transposed form delayed least mean square (LMS) and serial direct form LMS.

You can use this block for resource-constrained FPGAs/SoCs and low-throughput applications, such as audio and speech processing as well as for high-throughput FPGA/SoC implementations and high-data-rate applications, such as wireless communications. The block provides an architecture suitable for HDL code generation and hardware deployment.

Note

You can also generate HDL code for this hardware-optimized algorithm, without creating a Simulink® model, by using the DSP HDL IP Designer app. The app provides the same interface and configuration options as the Simulink block.

Examples

Ports

Input

expand all

Input data, specified as a scalar or column vector of real or complex values. The input vector size must be in the range [2, 64] and it must be less than the filter length. The block can only support input word lengths of up to 32 bits.

The Transposed form delayed LMS architecture supports both scalar and vector inputs, whereas the Serial direct form LMS architecture supports scalar inputs only.

Use double and single data types for simulation, but not for HDL code generation. For HDL code generation, the input date type must be signed fixed point.

Data Types: single | double | fixed point
Complex Number Support: Yes

Desired input data, specified as a scalar or column vector of real or complex values. The input vector size must be in the range [2, 64] and it must be less than filter length. The desired port must have the same data type, complexity, and dimensions as the input data port.

The Transposed form delayed LMS architecture supports both scalar and vector inputs, whereas the Serial direct form LMS architecture supports scalar inputs only.

Use double and single data types for simulation, but not for HDL code generation. For HDL code generation, the input date type must be signed fixed point.

Data Types: single | double | fixed point
Complex Number Support: Yes

Control signal that indicates if the input data is valid. When valid is 1 (true), the block captures the values from the input ports data and desired. When valid is 0 (false), the block ignores the values from the input ports data and desired.

Data Types: Boolean

Specify the step size to control convergence and stability of the filter. The recommended step size must be less than 1/(2 x Input power x Filter length).

You can use double and single data types for simulation, but not for HDL code generation. For HDL code generation, the input date type must be unsigned fixed point.

Dependencies

To enable this port, on the Main tab, set the Step-size source parameter to Input port.

Data Types: double | single | fixed point

When adapt is 1 (true) and input valid is 1 (true), the block adapts to the new filter weights for every input valid. When the adapt is 0 (false) and the input valid is 1 (true) or 0 (false), the block remains at its previous filter weights.

Dependencies

To enable this port, on the Main tab, select the Enable adapt input port parameter.

Data Types: Boolean

Control signal that clears internal states. When reset is 1 (true), the block stops the current calculation, clears internal states, and sets to the initial values of filter weights specified on the block mask. When the reset is 0 (false) and the input valid is 1 (true), the block captures data for processing.

For more reset considerations, see the Reset Signal section on the Hardware Control Signals page.

Dependencies

To enable this port, on the Control Ports tab, select the Enable reset input port parameter.

Data Types: Boolean

Output

expand all

Filtered output data, returned as a scalar or column vector of real or complex values. The dimensions of the output match the dimensions of the input.

When the input data is a floating-point type, the output data inherits the data type of the input data. When the input data is a fixed-point type, the output data is a fixed point with word length and fractional length incremented by 1.

The block has an output ready signal that indicates when the block is ready to process new input data when you set the Architecture parameter to Serial direct form LMS. Your design can react to the ready signal to provide the next input sample, or you can space your input data with enough cycles in between that the block can process each sample. For more information, see Backpressure Signal.

Data Types: single | double | fixed point
Complex Number Support: Yes

Control signal that indicates if the data from the output data port is valid. When valid is 1 (true), the block returns valid data from the output data port. When valid is 0 (false), the values from the output data port are not valid.

Data Types: Boolean

Outputs the result of subtracting the filtered output signal from the desired signal when the output valid is 1 (true).

If the input data and desired is a scalar or a column vector, the error signal has the same dimension and complexity as the input data. When the input data is a floating-point type, the output data inherits the data type of the input data. When the input data is a fixed-point type, the output data is fixed point with word length incremented by 2 and fractional length incremented by 1.

Dependencies

To enable this port, on the Main tab, select the Enable filter error output port parameter.

Data Types: Boolean

For each iteration, the block outputs the current updated filter weights from this port when the output valid is 1 (true).

For floating-point inputs, the weights data type must match the input type. For fixed-point signals, the input must match the data type set to the Weights parameter.

Dependencies

To enable this port, on the Main tab, select the Enable filter weights output port parameter.

Data Types: Boolean

Since R2026b

Control signal that indicates the block can accept new input data. The block sets this output to 1 (true) when it can accept data, and to 0 (false) when it is processing and cannot accept more data. For more information, see Backpressure Signal.

Dependencies

To enable this port, set the Architecture parameter to Serial direct form LMS.

Data Types: Boolean

Parameters

expand all

Note

These parameters apply when configuring a block in Simulink or an algorithm in the DSP HDL IP Designer app.

Main

Since R2026b

Select the architecture type.

  • Serial direct form LMS — Use this option for resource-constrained FPGAs and low-throughput applications, such as audio and speech processing.

  • Transposed form delayed LMS — Use this option for high-throughput FPGA implementations and high-data-rate applications, such as wireless communications.

Specify the length of the LMS filter as a positive integer less than or equal to 2048.

Select whether the block specifies the step size through property or input port.

  • Property — Specify step size by using the Step size (mu) parameter.

  • Input port — Specify step size by using the stepSize port.

Specify the step size as a positive scalar numeric value. The recommended step size must be less than 1/(2 x Input power x Filter length).

Dependencies

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

Enter the initial filter weights as a scalar or row vector of size equal to filter length.

When you specify a scalar value, the block considers it as a row vector equivalent to the specified scalar value.

Select this parameter to enable the adapt input port.

Select this parameter to enable the weights output port.

For each iteration, the block outputs the current updated filter weights from this port.

Select this parameter to enable the error output port.

Data Types

Rounding mode for type-casting the output to the data type specified by the Output parameter. When the input data type is floating point, the block ignores this parameter. For more details, see Rounding Modes.

Overflow handling for type-casting the output to the data type specified by the Output parameter. When the input data type is floating point, the block ignores this parameter. For more details, see Overflow Handling.

Specify the step size data type.

Dependencies

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

Specify the data type for the filter weights.

If you specify an unsigned data type for this parameter, the filter uses the unsigned values and converts them to a signed data type. The signed data type is required to map the design onto DSP slices on an FPGA.

Specify the step size error product.

Control Ports

Select this check box to enable the reset input port. The reset signal implements a local synchronous reset of the data path registers.

For more reset considerations, see the Reset Signal section on the Hardware Control Signals page.

Select this check box to connect the generated HDL global reset signal to the data path registers. This parameter does not change the appearance of the block or modify simulation behavior in Simulink. When you clear this check box, the generated HDL global reset clears only the control path registers. The generated HDL global reset can be synchronous or asynchronous depending on the HDL Code Generation > Global Settings > Reset type parameter in the model Configuration Parameters.

For more reset considerations, see the Reset Signal section on the Hardware Control Signals page.

Algorithms

expand all

The following figures show the high-level block diagrams of the LMS Filter block for Transposed form delayed LMS and Serial direct form LMS architectures.

Transposed Form Delayed LMS - Scalar

The following figure shows the high-level block diagram of the LMS Filter block for the Transposed form delayed LMS architecture with scalar input. An observed signal is provided as input to the Input Memory block and also to the Transpose Filter block, which is configured with a Discrete FIR Filter block. The output of the Transpose Filter block is subtracted from the Desired input signal to output the Filter Error signal. The Filter Error signal is multiplied with the Step-Size input signal and the resulted step-error product is converted to the required data type. The step-error product is multiplied with the corresponding tap delay line conjugate from the Input Memory block. In the Integrator block, the multiplied output is added to the previous weight, Unit Delay, to output new filter weights. These filter weights are routed back to the Transpose Filter block for the next weight updates.

Transposed form delayed LMS - Scalar

Serial Direct Form LMS - Scalar

The following figure shows the high-level architecture block diagram of the LMS Filter block for a Serial direct form LMS architecture with scalar input. This architecture is similar to the previous configuration, but implements the non-delayed version of the LMS algorithm. In this structure, the input data is regulated through a controller so that each weight update is aligned with the next clock-cycle sample of data. The filter is configured as a partly-serial systolic FIR structure, with NumCycles = 2 × FilterLength. This choice serializes the multiply-accumulate operations across multiple clock cycles, reducing hardware resources.

Serial Direct Form LMS - Scalar

Transposed Form Delayed LMS - Vector

The following figure shows the high-level architecture block diagram of the LMS Filter block for Transposed form delayed LMS with vector input. The vector architecture is almost similar to the scalar architecture. In the vector architecture, step-error product vectors are multiplied with the corresponding tap delay line conjugates from the Input Memory block and then summed up in the Summation block. In the Integrator block, the summed output is added to the previous weight vector Unit Delay to output new filter weights. These filter weights are routed back to the Transpose Filter block for the next weight updates.

Transposed form delayed LMS - Vector

For hardware implementation, all these operations are pipelined, which takes around D number of delays to update the filter weights, where D is the latency of the block.

References

[1] Hayes, M.H. Statistical Digital Signal Processing and Modeling. New York: John Wiley & Sons, 1996.

Extended Capabilities

expand all

Version History

Introduced in R2023a

expand all