# Documentation

### This is machine translation

Translated by
Mouse over text to see original. Click the button below to return to the English verison of the page.

# dsp.RLSFilter System object

Package: dsp

Compute output, error and coefficients using Recursive Least Squares (RLS) algorithm

## Description

The `RLSFilter` object filters each channel of the input using RLS filter implementations.

To filter each channel of the input:

1. Define and set up your RLS filter. See Construction.

2. Call `step` to filter each channel of the input according to the properties of `dsp.RLSFilter`. The behavior of `step` is specific to each object in the toolbox.

 Note:   Starting in R2016b, instead of using the `step` method to perform the operation defined by the System object™, you can call the object with arguments, as if it were a function. For example, ```y = step(obj,x)``` and `y = obj(x)` perform equivalent operations.

## Construction

`rlsFilt = dsp.RLSFilter` returns an adaptive RLS filter System object, `rlsFilt`. This System object computes the filtered output, filter error and the filter weights for a given input and desired signal using the RLS algorithm.

```rlsFilt = dsp.RLSFilter('PropertyName',PropertyValue, ...)``` returns an RLS filter System object, `rlsFilt`, with each specified property set to the specified value.

```rlsFilt = dsp.RLSFilter(LEN, 'PropertyName', PropertyValue, ...)``` returns an RLS filter System object, `rlsFilt`. This System object has the Length property set to `LEN`, and other specified properties set to the specified values.

## Properties

 `Method` Method to calculate the filter coefficients You can specify the method used to calculate filter coefficients as one of | `Conventional RLS` [1] [2] | ```Householder RLS``` [3] [4] | ```Sliding-window RLS``` [5][1][2] | ```Householder sliding-window RLS``` [4] | `QR decomposition` [1] [2]. The default value is `Conventional RLS`. This property is nontunable. `Length` Length of filter coefficients vector Specify the length of the RLS filter coefficients vector as a scalar positive integer value. The default value is `32`. This property is nontunable. `SlidingWindowBlockLength` Width of the sliding window Specify the width of the sliding window as a scalar positive integer value greater than or equal to the Length property value. This property is applicable only when the Method property is set to ```Sliding-window RLS``` or `Householder sliding-window RLS`. The default value is `48`. This property is nontunable. `ForgettingFactor` RLS forgetting factor Specify the RLS forgetting factor as a scalar positive numeric value less than or equal to 1. Setting this property value to 1 denotes infinite memory, while adapting to find the new filter. The default value is `1`. This property is tunable. `InitialCoefficients` Initial coefficients of the filter Specify the initial values of the FIR adaptive filter coefficients as a scalar or a vector of length equal to the `Length` property value. The default value is `0`. This property is tunable. `InitialInverseCovariance` Initial inverse covariance Specify the initial values of the inverse covariance matrix of the input signal. This property must be either a scalar or a square matrix, with each dimension equal to the `Length` property value. If you set a scalar value, the `InverseCovariance` property is initialized to a diagonal matrix with diagonal elements equal to that scalar value. This property applies only when the `Method` property is set to `Conventional RLS` or ```Sliding-window RLS```. The default value is `1000`. This property is tunable. `InitialSquareRootInverseCovariance` Initial square root inverse covariance Specify the initial values of the square root inverse covariance matrix of the input signal. This property must be either a scalar or a square matrix with each dimension equal to the `Length` property value. If you set a scalar value, the `SquareRootInverseCovariance` property is initialized to a diagonal matrix with diagonal elements equal to that scalar value. This property applies only when the `Method` property is set to `Householder RLS` or ```Householder sliding-window RLS```. The default value is `sqrt(1000)`. This property is tunable. `InitialSquareRootCovariance` Initial square root covariance Specify the initial values of the square root covariance matrix of the input signal. This property must be either a scalar or a square matrix with each dimension equal to the `Length` property value. If you set a scalar value, the `SquareRootCovariance` property is initialized to a diagonal matrix with diagonal elements equal to the scalar value. This property applies only when the `Method` property is set to `QR-decomposition RLS`. The default value is `sqrt(1/1000)`. This property is tunable. `LockCoefficients` Lock coefficient updates Specify whether the filter coefficient values should be locked. When you set this property to `true`, the filter coefficients are not updated and their values remain the same. The default value is `false` (filter coefficients continuously updated). This property is tunable.

## Methods

 clone Create System object with same property values isLocked Locked status for input attributes and nontunable properties msesim Mean-square error for RLS filter release Allow property value and input characteristics changes reset Reset the internal states of a System object step Process inputs using RLS filter

## Examples

expand all

Use the RLS filter System object™ to determine the signal value.

Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent `step` syntax. For example, myObject(x) becomes step(myObject,x).

```hrls1 = dsp.RLSFilter(11, 'ForgettingFactor', 0.98); hfilt = dsp.FIRFilter('Numerator',fir1(10, .25)); % Unknown System x = randn(1000,1); % input signal d = hfilt(x) + 0.01*randn(1000,1); % desired signal [y,e] = hrls1(x, d); w = hrls1.Coefficients; subplot(2,1,1), plot(1:1000, [d,y,e]); title('System Identification of an FIR filter'); legend('Desired', 'Output', 'Error'); xlabel('time index'); ylabel('signal value'); subplot(2,1,2); stem([hfilt.Numerator; w].'); legend('Actual','Estimated'); xlabel('coefficient #'); ylabel('coefficient value'); ```

Noise Cancellation

```hrls2 = dsp.RLSFilter('Length', 11, 'Method', 'Householder RLS'); hfilt2 = dsp.FIRFilter('Numerator',fir1(10, [.5, .75])); x = randn(1000,1); % Noise d = hfilt2(x) + sin(0:.05:49.95)'; % Noise + Signal [y, err] = hrls2(x, d); subplot(2,1,1), plot(d), title('Noise + Signal'); subplot(2,1,2), plot(err), title('Signal'); ```

## Algorithms

The `dsp.RLSFilter` System object, when `Conventional RLS` is selected, recursively computes the least squares estimate (RLS) of the FIR filter weights. The System object estimates the filter weights or coefficients, needed to convert the input signal into the desired signal. The input signal can be a scalar or a column vector. The desired signal must have the same data type, complexity, and dimensions as the input signal. The corresponding RLS filter is expressed in matrix form as P(n) :

`$\begin{array}{l}k\left(n\right)=\frac{{\lambda }^{-1}P\left(n-1\right)u\left(n\right)}{1+{\lambda }^{-1}{u}^{H}\left(n\right)P\left(n-1\right)u\left(n\right)}\\ y\left(n\right)={w}^{T}\left(n-1\right)u\left(n\right)\\ e\left(n\right)=d\left(n\right)-y\left(n\right)\\ w\left(n\right)=w\left(n-1\right)+k\left(n\right)e\left(n\right)\\ P\left(n\right)={\lambda }^{-1}P\left(n-1\right)-{\lambda }^{-1}k\left(n\right){u}^{H}\left(n\right)P\left(n-1\right)\end{array}$`

where λ-1 denotes the reciprocal of the exponential weighting factor. The variables are as follows:

VariableDescription
nThe current time index
u(n)The vector of buffered input samples at step n
P(n)The inverse correlation matrix at step n
k(n)The gain vector at step n
w(n)The vector of filter tap 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 forgetting factor

u, w, and k are all column vectors.

## References

[1] M Hayes, Statistical Digital Signal Processing and Modeling, New York: Wiley, 1996

[2] S. Haykin, Adaptive Filter Theory, 4th Edition, Upper Saddle River, NJ: Prentice Hall, 2002

[3] A.A. Rontogiannis and S. Theodoridis, "Inverse factorization adaptive least-squares algorithms," Signal Processing, vol. 52, no. 1, pp. 35-47, July 1996.

[4] S.C. Douglas, "Numerically-robust O(N2) RLS algorithms using least-squares prewhitening," Proc. IEEE Int. Conf. on Acoustics, Speech, and Signal Processing, Istanbul, Turkey, vol. I, pp. 412-415, June 2000.

[5] A. H. Sayed, Fundamentals of Adaptive Filtering, Hoboken, NJ: John Wiley & Sons, 2003