Compute output, error, and weights using LMS adaptive algorithm
DSP System Toolbox / Filtering / Adaptive Filters
DSP System Toolbox HDL Support / Filtering
The LMS Filter block can implement an adaptive FIR filter by 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). The output is 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.
Under specific conditions, this block also supports SIMD code generation. For details, see Code Generation.
Input
— Input signalConnect the signal that you want to filter, specified as a scalar or column vector.
When the input is fixedpoint, it must be signed.
Data Types: single
 double
 fixed point
Desired
— Desired signalConnect the desired signal, specified as a vector or matrix. The
desired signal must have the same data type, complexity, and dimensions
as the Input
signal.
When Input is fixedpoint, the desired signal must be a signed fixedpoint.
Data Types: single
 double
 fixed point
Stepsize
— StepsizeEnter the step size μ. For convergence of the
normalized LMS equations, 0<µ<2. Input type
must match the type of the Input
port.
When Input is fixedpoint, the stepsize must be a signed fixedpoint.
This port appears only when you set the Specify step size via
parameter to
Input port
.
Data Types: single
 double
 fixed point
Adapt
— Update filter weightsWhen 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.
This port appears only when you set the Adapt port
parameter to
on
.
Data Types: single
 double
 int8
 int16
 int32
 Boolean
Reset
— Reset filter weightsSignal to reset the value of the filter weights to their initial values, specified as a vector. 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.
For reset event types, see the Reset
parameter.
This port appears only when you set the Reset
port parameter to Rising
edge
, Falling edge
,
Either edge
, or Nonzero
sample
.
Data Types: single
 double
 int8
 int16
 int32
 Boolean
Output
— Output signalOutputs the filtered input signal, which is the estimate of the desired signal. It is the same size and complexity as the input signal.
The output signal has the same data type as the desired signal.
Data Types: single
 double
 fixed point
Error
— Error between Output and Desired signalsOutputs the result of subtracting the output signal from the desired signal.
The error signal has the same data type as the desired signal.
Data Types: single
 double
 fixed point
Wts
— Updated filter weightsFor each iteration, the block outputs the current updated filter weights from this port.
The weights data type must match the type of the Input
port for floatingpoint signals. Obeys the
Weights
parameter for fixedpoint signals.
This port appears only when you set the Output filter weights
parameter to
On
.
Data Types: single
 double
 fixed point
Algorithm
— Select algorithmLMS
(default)  Normalized LMS
 SignError LMS
 SignData LMS
 SignSign LMS
Choose the algorithm used to calculate the filter weights.
Filter length
— Filter length32
(default)  scalarEnter the length of the FIR filter weights vector.
Specify step size via
— Specify step size viaDialog
(default)  Input port
Dialog
–– Specify step size by
using the Step size (mu)
parameter.
Input port
–– Specify step size
by using the Stepsize
port.
Step size (mu)
— Step size0.1
(default)  positive scalarEnter the step size μ. For convergence of the normalized LMS equations, 0<µ<2.
Tunable: Yes
This parameter appears only when you set the Specify step size via
parameter to
Dialog
.
Leakage factor (0 to 1)
— Leakage factor1.0
(default)  scalarEnter the leakage factor, 0 < 1 – μα ≤ 1.
Tunable: Yes
Initial value of filter weights
— Initial value of filter weights0
(default)  vector  scalarEnter the initial filter weights w(0) as a vector or a scalar. When you enter a scalar, the block uses the scalar value to create a vector of filter weights. This vector length is equal to the filter length and all of its values are equal to the scalar value.
Adapt port
— Enable Adapt porton
(default)  off
Select this check box to enable the Adapt
input port.
Reset port
— Reset portNone
(default)  Rising edge
 Falling edge
 Either edge
 Nonzero sample
When you want to reset the value of filter weights to their initial values, use the Reset port parameter. The reset signal must be the same rate as the data signal input.
Select None
to disable the Reset
port. To enable the Reset
port, select one of the following from the 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
Nonzero sample
— Triggers a
reset operation at each sample time that the Reset input is not
zero
Output filter weights
— Output filter weightson
(default)  off
Select the Output filter weights parameter to
export the filter weights from the Wts
port. For each iteration, the block outputs the
current updated filter weights from this port.
Rounding mode
— Method of rounding operationFloor
(default)  Ceiling
 Convergent
 Nearest
 Round
 Simplest
 Zero
Specify the rounding mode for fixedpoint operations as one of the following:
Floor
Ceiling
Convergent
Nearest
Round
Simplest
Zero
For more details, see rounding mode.
Saturate on integer overflow
— Method of overflow actionWhen you select this parameter, the block saturates the result of its
fixedpoint operation. When you clear this parameter, the block wraps
the result of its fixedpoint operation. For details on
saturate
and wrap
, see overflow
mode for fixedpoint operations.
Parameters
— ParametersSame word length as first
input
(default)  Specify word length
 Binary point scaling
Choose how you specify the word length and the fraction length of the leakage factor and step size:
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.
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.
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.
For the Specify
step size via
parameter, if 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 Stepsize
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.
This parameter is visible only if you set the Specify
step size via parameter to
Dialog
Weights
— Word and fraction length of filter weightsSame as first input
(default)  Binary point scaling
Choose how you specify the word length and fraction length of the filter weights of the block:
Same as first input
–– The word
length and fraction length of the filter weights match those of
the first input to the block.
Binary point scaling
–– You can
enter the word length and the fraction length of the filter
weights, in bits.
Product and quotient
— Word and fraction length of product and quotientSame as first input
(default)  Binary point scaling
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}$$
Same as first input
–– The word
length and fraction length of these quantities match those of
the first input to the block.
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.
Accumulator
— Word and fraction lengths of accumulatorsSame as first input
(default)  Binary point scaling
Use this parameter to specify how you want to designate the word and fraction lengths of the accumulators for the u'u and W'u operations.
Note
Do not use this parameter 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.
Same as first input
–– These
characteristics match those of the input to the block.
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.
For illustrations depicting the use of the accumulator data type in this block, see Fixed Point and Multiplication Data Types.
Lock data type settings against changes by the fixedpoint tools
— Prevent fixedpoint tools from overriding data typesoff
(default)  on
Select this parameter to prevent the fixedpoint tools from overriding the data types you specify in the block dialog box.
Data Types 

Direct Feedthrough 

Multidimensional Signals 

VariableSize Signals 

ZeroCrossing Detection 

When you select LMS
for the Algorithm
parameter, the block calculates the filter weights by
using the least meansquare (LMS) algorithm. This algorithm is defined by these 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)}$$
In Normalized LMS, to overcome potential numerical instability in the update of the weights, a small positive constant, ε, has been added in the denominator. For doubleprecision floatingpoint input, ε is 2.2204460492503131e016. For singleprecision floatingpoint input, ε is 1.192092896e07. For fixedpoint input, ε is 0.
SignError LMS ––
$$f(u(n),e(n),\mu )=\mu \text{sign}(e(n)){u}^{*}(n)$$
SignData LMS ––
$$f(u(n),e(n),\mu )=\mu e(n)\text{sign}(u(n))$$
where u(n) is real.
SignSign LMS ––
$$f(u(n),e(n),\mu )=\mu \text{sign}(e(n))\text{sign}(u(n))$$
where u(n) is real.
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) 
ε  A constant that corrects any potential numerical instability that occurs during the update of weights. 
[1] Hayes, M.H. Statistical Digital Signal Processing and Modeling. New York: John Wiley & Sons, 1996.
Generated code relies on memcpy
or
memset
functions (string.h
) under certain
conditions.
The LMS Filter block supports SIMD code generation using Intel AVX2 technology under these conditions:
Algorithm is set to
LMS
or Normalized
LMS
.
Input signal is realvalued.
Input signal has a data type of single
or
double
.
The SIMD technology significantly improves the performance of the generated code.
HDL Coder™ provides additional configuration options that affect HDL implementation and synthesized logic.
By default, the LMS Filter implementation uses a linear sum for the FIR section of the filter.
The LMS Filter implements a tree summation (which has a shorter critical path) under the following conditions:
The LMS Filter is used with real data.
The word length of the Accumulator W'u data type is at least ceil(log2(filter
length))
bits wider than the word length of the Product
W'u data type.
The Accumulator W'u data type has the same fraction length as the Product W'u data type.
ConstrainedOutputPipeline  Number of registers to place at
the outputs by moving existing delays within your design. Distributed
pipelining does not redistribute these registers. The default is

InputPipeline  Number of input pipeline stages
to insert in the generated code. Distributed pipelining and constrained
output pipelining can move these registers. The default is

OutputPipeline  Number of output pipeline stages
to insert in the generated code. Distributed pipelining and constrained
output pipelining can move these registers. The default is

This block supports code generation for complex signals.
HDL Coder does not support the Normalized
LMS
algorithm of the LMS Filter.
The Reset
port supports only
Boolean
and unsigned
inputs.
The Adapt
port supports only
Boolean
inputs.
Filter length must be greater than or equal to 2.
If the input is fixed point, it must be signed integer or signed fixed point with poweroftwo slope and zero bias.
FixedPoint Data Types
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 these 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, see Multiplication Data Types.
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
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: .
Select web siteYou can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.