ewrls

Recursive least square adaptive filtered average.

Syntax
y = ewrls(data,p,lambda)
y = ewrls(data,p,lambda,nPreAvg)
y = ewrls(data,p,lambda,nPreAvg,delta)
y = ewrls(data,p,lambda,nPreAvg,delta,dir)
ewrls(...)
Description

This function computes a filtered average of the input data, using an adaptive filter method called exponentially weighted recursive least squares (RLS or EWRLS) filtering.

It takes an 2D input array data containing the spectral data. Each column should represent one scan, and there should be multiple scans. It returns the filtered average in y.

The filter contains two parameters: The filter length p is typically in the range 5-50 and determines how many consecutive points are used to predict the next point. The memory factor lambda is a positive number slightly smaller than 1 (typically 0.9-0.99) and determines the memory of the filter, larger lambda values corresponding to longer memory.

The parameter nPreAvg determines how many scans are used to estimate a target signal. This number should be smaller than the number of scans in the data array, or it can be zero. If it is zero, all the scans are used. This is the preferred setting, and also the default.

delta is the regularization parameter and is used to initialize the matrix P in the recursive least squares algorithm. Usually, there is no need to set this value.

dir determines the direction the filter is applied. 'f' is the forward direction, 'b' is the backward direction, and 'fb' computes an average of the forward and the backward direction. This is the default.

Examples

Let's generate some artificial data

nScans = 100;
nPoints = 1001;
t = linspace(-1,1,nPoints);
signal = gaussian(t,0.2,0.3,1) + gaussian(t,-0.2,0.15,1)/2;
signal = signal(:)/max(signal);
for k = 1:nScans
  datamatrix(:,k) = addnoise(signal,2,'n');
end

Now let's compute a filtered average using ewrls, and have the function plot the result:

p = 20; % filter length
lambda = 0.96; % memory factor
nPreAverage = 0;
delta = 100; % regularization parameter
ewrls(datamatrix,p,lambda,nPreAverage,delta,'fb');
References
The method implemented in ewrl is described in
See also

addnoise rcfilt datasmooth