Compute output, error, and weights using LMS adaptive algorithm
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. The input signal can be a scalar or a column vector. Connect the desired signal to the Desired port. The desired signal must have the same data type, complexity, and dimensions as the input signal. The Output port outputs the filtered input signal, which is the estimate of the desired 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 meansquare (LMS) algorithm. This algorithm is defined by the following
equations.
$$\begin{array}{c}y(n)={w}^{T}(n1)u(n)\\ e(n)=d(n)y(n)\\ w(n)=\alpha w(n1)+f(u(n),e(n),\mu )\end{array}$$
The various LMS adaptive filter algorithms available in this block are defined as:
LMS:
$$f(u(n),e(n),\mu )=\mu e(n){u}^{*}(n)$$
Normalized LMS:
$$f(u(n),e(n),\mu )=\mu e(n)\frac{{u}^{\ast}(n)}{\epsilon +{u}^{H}(n)u(n)}$$
SignError LMS:
$$f(u(n),e(n),\mu )=\mu sign(e(n))u*(n)$$
SignData LMS:
$$f(u(n),e(n),\mu )=\mu e(n)sign(u(n))$$
where u(n) is real.
SignSign LMS:
$$f(u(n),e(n),\mu )=\mu sign(e(n))sign(u(n))$$
where u(n) is real.
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 
α  The leakage factor (0 < α ≤ 1) 
In NMLS, to overcome potential numerical instability in the update of the weights, a small positive constant, epsilon, has been added in the denominator. For doubleprecision floatingpoint input, epsilon is 2.2204460492503131e016. For singleprecision floatingpoint input, epsilon is 1.192092896e07. For fixedpoint input, epsilon is 0.
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, Stepsize, or by entering a value in the Block Parameters: LMS Filter dialog.
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)
Nonzero sample
—
Triggers a reset operation at each sample time that the Reset input
is not zero
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 fixedpoint 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, $$Q=\frac{\mu \cdot e}{u\text{'}u}$$ 
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 $$\mu \cdot e$$  Product data type in Product of step size and error diagram 
Product $$Q\cdot u$$  Product and accumulator data type in Weight update diagram. ^{1} 
^{1}The 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. Fixedpoint 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, $$\mu \cdot e$$, and $$Q\cdot u$$ 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 Stepsize 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 Data Types pane of the LMS Filter block dialog appears as follows.
Select the rounding mode for fixedpoint operations.
Select the overflow mode for fixedpoint 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 binarypoint 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 binarypoint 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 poweroftwo 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 poweroftwo slope and a bias of zero.
Choose how you specify the word length and fraction length of u'u, W'u, $$\mu \cdot e$$, $$Q\cdot 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 $$Q=\frac{\mu \cdot e}{u\text{'}u}$$
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 poweroftwo 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 $$Q\cdot u$$ operation. The 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. 
See FixedPoint 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 poweroftwo slope and a
bias of zero.
Select this parameter to prevent the fixedpoint tools from overriding the data types you specify on the block mask.
This block supports HDL code generation using HDL Coder™. HDL Coder provides additional configuration options that affect HDL implementation and synthesized logic. For more information on implementations, properties, and restrictions for HDL code generation, see LMS Filter.
Hayes, M.H. Statistical Digital Signal Processing and Modeling. New York: John Wiley & Sons, 1996.
Port  Supported Data Types 

Input 

Desired 

Stepsize 

Adapt 

Reset 

Output 

Error 

Wts 

Kalman Adaptive Filter (Obsolete)  DSP System Toolbox 
RLS Filter  DSP System Toolbox 
Block LMS Filter  DSP System Toolbox 
Fast Block LMS Filter  DSP System Toolbox 
See Adaptive Filters in Simulink for related information.