Documentation Center |
Normalized least mean squares adaptive filter
ha = adaptfilt.nlms(l,step,leakage,offset,coeffs,states)
ha = adaptfilt.nlms(l,step,leakage,offset,coeffs,states) constructs a normalized least-mean squares (NLMS) FIR adaptive filter object named ha.
For information on how to run data through your adaptive filter object, see the Adaptive Filter Syntaxes section of the reference page for filter.
Entries in the following table describe the input arguments for adaptfilt.nlms.
Input Argument | Description |
---|---|
l | Adaptive filter length (the number of coefficients or taps) and it must be a positive integer. l defaults to 10. |
step | NLMS step size. It must be a scalar between 0 and 2. Setting this step size value to one provides the fastest convergence. step defaults to 1. |
leakage | NLMS leakage factor. It must be a scalar between zero and one. When it is less than one, a leaky NLMS algorithm results. leakage defaults to 1 (no leakage). |
offset | Specifies an optional offset for the denominator of the step size normalization term. You must specify offset to be a scalar greater than or equal to zero. Nonzero offsets can help avoid a divide-by-near-zero condition that causes errors. Use this to avoid dividing by zero (or by very small numbers) when the square of the input data norm becomes very small (when the input signal amplitude becomes very small). When you omit it, offset defaults to zero. |
coeffs | Vector composed of your initial filter coefficients. Enter a length l vector. coeffs defaults to a vector of zeros with length equal to the filter order. |
states | Your initial adaptive filter states appear in the states vector. It must be a vector of length l-1. states defaults to a length l-1 vector with zeros for all of the elements. |
In the syntax for creating the adaptfilt object, the input options are properties of the object you create. This table lists the properties for normalized LMS objects, their default values, and a brief description of the property.
Property | Range | Property Description |
---|---|---|
Algorithm | None | Reports the adaptive filter algorithm the object uses during adaptation |
Coefficients | Vector of elements | Vector containing the initial filter coefficients. It must be a length l vector where l is the number of filter coefficients. coeffs defaults to length l vector of zeros when you do not provide the argument for input. |
FilterLength | Any positive integer | Reports the length of the filter, the number of coefficients or taps |
Leakage | 0 to 1 | NLMS leakage factor. It must be a scalar between zero and one. When it is less than one, a leaky NLMS algorithm results. leakage defaults to 1 (no leakage). |
Offset | 0 or greater | Specifies an optional offset for the denominator of the step size normalization term. You must specify offset to be a scalar greater than or equal to zero. Nonzero offsets can help avoid a divide-by-near-zero condition that causes errors. Use this to avoid dividing by zero (or by very small numbers) when the square of the input data norm becomes very small (when the input signal amplitude becomes very small). When you omit it, offset defaults to zero. |
PersistentMemory | false or true | Determine whether the filter states and coefficients get restored to their starting values for each filtering operation. The starting values are the values in place when you create the filter. PersistentMemory returns to zero any property value that the filter changes during processing. Property values that the filter does not change are not affected. Defaults to false. |
States | Vector of elements, data type double | Vector of the adaptive filter states. states defaults to a vector of zeros which has length equal to (l - 1). |
StepSize | 0 to 1 | NLMS step size. It must be a scalar between zero and one. Setting this step size value to one provides the fastest convergence. step defaults to one. |
To help you compare this algorithm's performance to other LMS-based algorithms, such as BLMS or LMS, this example demonstrates the NLMS adaptive filter in use to identify the coefficients of an unknown FIR filter of order equal to 32 — an example used in other adaptive filter examples.
x = randn(1,500); % Input to the filter b = fir1(31,0.5); % FIR system to be identified n = 0.1*randn(1,500); % Observation noise signal d = filter(b,1,x)+n; % Desired signal mu = 1; % NLMS step size offset = 50; % NLMS offset ha = adaptfilt.nlms(32,mu,1,offset); [y,e] = filter(ha,x,d); subplot(2,1,1); plot(1:500,[d;y;e]); legend('Desired','Output','Error'); title('System Identification of FIR Filter'); xlabel('Time Index'); ylabel('Signal Value'); subplot(2,1,2); stem([b', ha.coefficients']); legend('Actual','Estimated'); grid on; xlabel('Coefficient #'); ylabel('Coefficient Value');
As you see from the figure, the nlms variant again closely matches the actual filter coefficients in the unknown FIR filter.
adaptfilt.ap | adaptfilt.apru | adaptfilt.lms | adaptfilt.rls | adaptfilt.swrls