main content

compute output, error and coefficients using recursive least squares (rls) algorithm -凯发k8网页登录

compute output, error and coefficients using recursive least squares (rls) algorithm

description

the dsp.rlsfilter system object™ filters each channel of the input using rls filter implementations.

to filter each channel of the input:

  1. create the dsp.rlsfilter object and set its properties.

  2. call the object with arguments, as if it were a function.

to learn more about how system objects work, see what are system objects?

creation

description

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.

example

rlsfilt = dsp.rlsfilter(len) returns an rls filter system object, rlsfilt. this system object has the length property set to len.

rlsfilt = dsp.rlsfilter(name,value) returns an rls filter system object with each specified property set to the specified value. enclose each property name in single quotes. unspecified properties have default values.

properties

unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. objects lock when you call them, and the function unlocks them.

if a property is tunable, you can change its value at any time.

for more information on changing property values, see .

you can specify the method used to calculate filter coefficients as conventional rls [1] [2], householder rls [3] [4], sliding-window rls [5][1][2], householder sliding-window rls [4], or qr decomposition [1] [2]. this property is nontunable.

specify the length of the rls filter coefficients vector as a scalar positive integer value. this property is nontunable.

data types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

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 nontunable.

dependencies

this property applies only when the method property is set to sliding-window rls or householder sliding-window rls.

data types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

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.

tunable: yes

data types: single | double

specify the initial values of the fir adaptive filter coefficients as a scalar or a vector of length equal to the length property value.

tunable: yes

data types: single | double

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.

tunable: yes

dependencies

this property applies only when the method property is set to conventional rls or sliding-window rls.

data types: single | double

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.

tunable: yes

dependencies

this property applies only when the method property is set to householder rls or householder sliding-window rls.

data types: single | double

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.

tunable: yes

dependencies

this property applies only when the method property is set to qr-decomposition rls.

data types: single | double

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).

tunable: yes

usage

description

example

y = rlsfilt(x,d) recursively adapts the reference input, x, to match the desired signal, d, using the system object, rlsfilt. the desired signal, d, is the signal desired plus some undesired noise.

[y,e] = rlsfilt(x,d) shows the output of the rls filter along with the error, e, between the reference input and the desired signal. the filters adapts its coefficients until the error e is minimized. you can access these coefficients by accessing the coefficients property of the object. this can be done only after calling the object. for example, to access the optimized coefficients of the rlsfilt filter, call rlsfilt.coefficients after you pass the input and desired signal to the object.

input arguments

the signal to be filtered by the rls filter. the input, x, and the desired signal, d, must have the same size and data type.

the input can be a variable-size signal. you can change the number of elements in the column vector even when the object is locked. the system object locks when you call the object to run its algorithm.

data types: single | double
complex number support: yes

the rls filter adapts its coefficients to minimize the error, e, and converge the input signal x to the desired signal d as closely as possible.

the input, x, and the desired signal, d, must have the same size and data type.

the desired signal, d, can be a variable-size signal. you can change the number of elements in the column vector even when the object is locked. the system object locks when you call the object to run its algorithm.

data types: single | double
complex number support: yes

output arguments

filtered output, returned as a scalar or a column vector. the object adapts its filter coefficients to converge the input signal x to match the desired signal d. the filter outputs the converged signal.

data types: single | double
complex number support: yes

difference between the output signal y and the desired signal d, returned as a scalar or a column vector. the objective of the rls filter is to minimize this error. the object adapts its coefficients to converge toward optimal filter coefficients that produce an output signal that matches closely with the desired signal. for more details on how e is computed, see algorithms. to access the rls filter coefficients, call rlsfilt.coefficients after you pass the input and desired signal to the object.

data types: single | double
complex number support: yes

object functions

to use an object function, specify the system object as the first input argument. for example, to release system resources of a system object named obj, use this syntax:

release(obj)
estimated mean squared error for adaptive filters
run system object algorithm
release resources and allow changes to system object property values and input characteristics
reset internal states of system object

examples

use a recursive least squares (rls) filter to identify an unknown system modeled with a lowpass fir filter. compare the frequency responses of the unknown and estimated systems.

initialization

create a dsp.firfilter object that represents the system to be identified. pass the signal x to the fir filter. the output of the unknown system is the desired signal d, which is the sum of the output of the unknown system (fir filter) and an additive noise signal n.

filt = dsp.firfilter('numerator',fir1(10,.25));
x = randn(1000,1);
n = 0.01*randn(1000,1);
d = filt(x)   n;

adaptive filter

create a dsp.rlsfilter object to create an rls filter. set the length of the filter to 11 taps and the forgetting factor to 0.98. pass the primary input signal x and the desired signal d to the rls filter. the output y of the adaptive filter is the signal converged to the desired signal d thereby minimizing the error e between the two signals.

rls = dsp.rlsfilter(11, 'forgettingfactor', 0.98);
[y,e] = rls(x,d);
w = rls.coefficients;

plot the results

the output signal matches the desired signal, making the error between the two close to zero.

plot(1:1000, [d,y,e]);
title('system identification of an fir filter');
legend('desired', 'output', 'error');
xlabel('time index'); 
ylabel('signal value');

figure contains an axes object. the axes object with title system identification of an fir filter, xlabel time index, ylabel signal value contains 3 objects of type line. these objects represent desired, output, error.

compare the weights

the weights vector w represents the coefficients of the rls filter that is adapted to resemble the unknown system (fir filter). to confirm the convergence, compare the numerator of the fir filter and the estimated weights of the rls filter.

the estimated filter weights closely match the actual filter weights, confirming the results seen in the previous signal plot.

stem([filt.numerator; w].');
legend('actual','estimated');
xlabel('coefficient #'); 
ylabel('coefficient value');

figure contains an axes object. the axes object with xlabel coefficient #, ylabel coefficient value contains 2 objects of type stem. these objects represent actual, estimated.

this example demonstrates the rls adaptive algorithm using the inverse system identification model shown here.

cascading the adaptive filter with an unknown filter causes the adaptive filter to converge to a solution that is the inverse of the unknown system.

if the transfer function of the unknown system and the adaptive filter are h(z) and g(z), respectively, the error measured between the desired signal and the signal from the cascaded system reaches its minimum when g(z)×h(z) = 1. for this relation to be true, g(z) must equal 1/h(z), the inverse of the transfer function of the unknown system.

to demonstrate that this is true, create a signal s to input to the cascaded filter pair.

s = randn(3000,1);

in the cascaded filters case, the unknown filter results in a delay in the signal arriving at the summation point after both filters. to prevent the adaptive filter from trying to adapt to a signal it has not yet seen (equivalent to predicting the future), delay the desired signal by 12 samples, which is the order of the unknown system.

generally, you do not know the order of the system you are trying to identify. in that case, delay the desired signal by number of samples equal to half the order of the adaptive filter. delaying the input requires prepending 12 zero-value samples to the input s.

delay = zeros(12,1);
d = [delay; s(1:2988)]; % concatenate the delay and the signal.

you have to keep the desired signal vector d the same length as x, so adjust the signal element count to allow for the delay samples.

although not generally the case, for this example you know the order of the unknown filter, so add a delay equal to the order of the unknown filter.

for the unknown system, use a lowpass, 12th-order fir filter.

filt = dsp.firfilter;
filt.numerator = fir1(12,0.55,'low');

filtering s provides the input data signal for the adaptive algorithm function.

x = filt(s);

to use the rls algorithm, create a dsp.rlsfilter object and set its length, forgettingfactor, and initialinversecovariance properties.

for more information about the input conditions to prepare the rls algorithm object, refer to dsp.rlsfilter.

p0 = 2 * eye(13);
lambda = 0.99;
rls = dsp.rlsfilter(13,'forgettingfactor',lambda,...
   'initialinversecovariance',p0);

this example seeks to develop an inverse solution, you need to be careful about which signal carries the data and which is the desired signal.

earlier examples of adaptive filters use the filtered noise as the desired signal. in this case, the filtered noise (x) carries the unknown system's information. with gaussian distribution and variance of 1, the unfiltered noise d is the desired signal. the code to run this adaptive filter is:

[y,e] = rls(x,d);

where y returns the filtered output and e contains the error signal as the filter adapts to find the inverse of the unknown system.

obtain the estimated coefficients of the rls filter.

b = rls.coefficients;

view the frequency response of the adapted rls filter (inverse system, g(z)) using freqz. the inverse system looks like a highpass filter with linear phase.

freqz(b,1)

figure contains 2 axes objects. axes object 1 with title phase, xlabel normalized frequency (\times\pi rad/sample), ylabel phase (degrees) contains an object of type line. axes object 2 with title magnitude, xlabel normalized frequency (\times\pi rad/sample), ylabel magnitude (db) contains an object of type line.

view the frequency response of the unknown system, h(z). the response is that of a lowpass filter with a cutoff frequency of 0.55.

freqz(filt.numerator,1)

figure contains 2 axes objects. axes object 1 with title phase, xlabel normalized frequency (\times\pi rad/sample), ylabel phase (degrees) contains an object of type line. axes object 2 with title magnitude, xlabel normalized frequency (\times\pi rad/sample), ylabel magnitude (db) contains an object of type line.

the result of the cascade of the unknown system and the adapted filter is a compensated system with an extended cutoff frequency of 0.8.

overallcoeffs = conv(filt.numerator,b);
freqz(overallcoeffs,1)

figure contains 2 axes objects. axes object 1 with title phase, xlabel normalized frequency (\times\pi rad/sample), ylabel phase (degrees) contains an object of type line. axes object 2 with title magnitude, xlabel normalized frequency (\times\pi rad/sample), ylabel magnitude (db) contains an object of type line.

cancel additive noise n added to an unknown system using an rls filter. the rls filter adapts its coefficients until its transfer function matches the transfer function of the unknown system as closely as possible. the difference between the output of the adaptive filter and the output of the unknown system is the error signal e, which represents the additive white noise. minimizing this error signal is the objective of the adaptive filter.

initialization

create a dsp.firfilter system object™ to represent the unknown system. create a dsp.rlsfilter object and set the length to 11 taps. set the method to 'householder rls'. create a sine wave to represent the noise added to the unknown system. view the signals in a time scope.

framesize = 100;
niter = 10;
rls = dsp.rlsfilter('length',11,...
    'method','householder rls');
filt = dsp.firfilter('numerator',...
    fir1(10,[.5,.75]));
sinewave = dsp.sinewave('frequency',0.01,...
    'samplerate',1,...
    'samplesperframe',framesize);
scope = timescope('layoutdimensions',[2 1],...
    'numinputports',2, ...
    'timeunits','seconds',...
    'ylimits',[-2.5 2.5], ...
    'bufferlength',2*framesize*niter,...
    'activedisplay',1,...
    'showlegend',true,...
    'channelnames',{'noisy signal'},...
    'activedisplay',2,...
    'showlegend',true,...
    'channelnames',{'error signal'});
for k = 1:niter
    x = randn(framesize,1);
    d = filt(x)   sinewave();
    [y,e] = rls(x,d);
    w = rls.coefficients;
    scope(d,e)
end
release(scope)

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) :

k(n)=λ1p(n1)u(n)1 λ1uh(n)p(n1)u(n)y(n)=wt(n1)u(n)e(n)=d(n)y(n)w(n)=w(n1) k*(n)e(n)p(n)=λ1p(n1)λ1k(n)uh(n)p(n1)

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 conjugate of the inverse correlation matrix at step n
k(n)the gain vector at step n
k*(n)complex conjugate of k
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.

extended capabilities

version history

introduced in r2013a

see also

objects

topics

    网站地图