0

I am fairly new to the signal processing world and that being said I have little to no experience. The problem that I am having is that I am not quite sure how to use dsp.RLSFilter. So far I have only used highpass filter and it was straight forward - I had to just decide on the cutting frequency, type of highpass and sampling frequency, whereas for the RLS filter I have a ton of parameters to choose from. For example, how to decide on the method to calculate the filter coefficients? Furthermore, in the documentation it is stated:

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.

and in the example step is not used:

rls1 = dsp.RLSFilter(11, 'ForgettingFactor', 0.98);
filt = dsp.FIRFilter('Numerator',fir1(10, .25)); % Unknown System
x = randn(1000,1);                       % input signal
d = filt(x) + 0.01*randn(1000,1); % desired signal
[y,e] = rls1(x, d);
w = rls1.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([filt.Numerator; w].');
legend('Actual','Estimated');
xlabel('coefficient #'); ylabel('coefficient value');

So what is the difference between using step and using the method in the example? When I try using the same the same way as in the example I get the following error message: Array formation and parentheses-style indexing with objects of class 'dsp.RLSFilter' is not allowed. Use objects of class 'dsp.RLSFilter' only as scalars or use a cell array. I tried using num2cell on x and d, however, I had 0 success.

dsax7
  • 271
  • 3
  • 13

1 Answers1

3

Unlike a standard high pass filter where you set a cut-off frequency and other design parameters for a fixed filter result with a pass band ripple, stop band rejection, phase response etc.. the "recursive least squares filter" is an adaptive filter commonly used for channel equalization.

As a high level working example of a LMS equalizer, please see my post here where I derived and used the Wiener-Hopf equations to solve for the LMS filter coefficients. This would be an approach to equalization when the coefficients are solved for a block of data and then applied; most applicable to fixed filtering solutions such as compensating for distortions introduced in the RF portion of a receiver (compensating for analog filters for example).

Compensating Loudspeaker frequency response in an audio signal

To adaptively solve for the same coefficients, such as compensating for changing channel effects, two common algorithms are referred to as "LMS: Least-Mean Squared" and "RLS: Recursive Least Squares". I compare the two in my slide copied below, and for more details please refer to the following references

Rappaport, T.S. Wireless Communications Principles and Practice, Second Edition, Prentice Hall 2002

Proakis, J. “Adaptive Equalization for TDMA Digital Mobile Radio,“ IEEE Transactions on Vehicular Technology, Vol. 40, No. 2 pp 333-341, May 1991

Sayed, Ali, Fundamentals of Adaptive Filtering, Wiley, 2003

Bingham, J.A.C., The Theory and Practice of Modem Design, 1988

Adaptive Algorithms

The comparison of the implementation for the LMS and RLS adaptive equalizer is shown in the figures below, where vectors are indicated by single bars and matrices with double bars:

LMS: Easy!

LMS Equalizer

RLS: Fast!

RLS Equalizer

Finally to note that a least-squares equalizing filter is NOT the best choice for a channel with severe frequency selective fading as noise enhancement will result where deep fading nulls occur. For this condition, a decision feedback equalizer is often a better choice if time-domain equalization is to be used.

Dan Boschen
  • 50,942
  • 2
  • 57
  • 135
  • A really good answer that covers perfectly the difference between LMS and RLS, sadly I cannot upvote it as in the dsp section I have no reputation. I do think that now I understand the way RLS works, however, I still have problems building the RLS filter with matlab to process the signals as in the dsp.RLSFilter command in matlab I can have multipe parameters that are briefly covered in the documentation + in the documentation it is said to use step and in the example it is done otherwise. – dsax7 May 13 '17 at 13:45
  • @filtfilt Thanks, I think you can select it as the "right answer" if you like even if you don't have enough reputation, no? I will look at the documentation and see if "step" is obvious to me – Dan Boschen May 13 '17 at 13:58
  • @filtfilt Did you read this documentation https://www.mathworks.com/help/dsp/ref/dsp.rlsfilter-class.html and this specifically: https://www.mathworks.com/help/dsp/ref/dsp.rlsfilter.step.html – Dan Boschen May 13 '17 at 13:59
  • Exactly those 2 I read. What I used was: y = step(rlsFilt,x,d) recursively adapts the reference input, x, to match the desired signal, d, using the System object, rlsFilt. and it did not work. In the second link you gave, under examples it is done without step,however, as I mentioned at the begining that does not work for me as well and I get an error message. – dsax7 May 13 '17 at 14:29
  • Refer to this as well https://www.mathworks.com/help/matlab/matlab_prog/what-are-system-objects.html which states that "step" is just Matlab's way of calling methods on system objects (such aes rlsFilt) which can just as easily be called as it it were a function, for example y = rlsFilt(x,d). I haven't used this system object but assume that each step is one iteration and the algorithm takes several iterations to converge on the final result (this is an assumption but you can verify that). – Dan Boschen May 13 '17 at 15:02
  • Verify by observing the mean-square error for the RLS filter after each update and see if it is converging toward a minimum (this is one of the methods listed). From everything I read in the documentation it appears that my assumption is correct, otherwise we would need to define a minimum error for which the algorithm to declare success or stop converging, but would be preferable (for me) if I could control how many updates I want it to make. – Dan Boschen May 13 '17 at 15:06
  • Ok, I will try it and post the results. Yet I have a question for the LMS equalizer you posted. Why haven't you used dsp.LMSFilter offered by matlab? – dsax7 May 13 '17 at 15:14
  • Only because of its instructional value (it is used to demonstrate how the LMS filter works under the hood for a DSP class I teach). And also in that case an adaptive algorithm was not necessary since I was dealing with a stationary condition; so used the Wiener-Hopf equation specifically. (Which does converge in one step). – Dan Boschen May 13 '17 at 15:20
  • I tried and yet no luck. My code looks something like this: rls1=dsp.RLSFilter();[y,e]=step(rls1,mySignal,desiredSignal);MSE=msesim(rls1,mySignal,desiredSignal);figure;plot(e) I plot the error because my desired signal is the signal that I want to be removed from the original signal. After running MSE they are converging to minimum,however, the signal is not being processed. I may be doing something wrong (most probably I am as I am new to the signal processing world). – dsax7 May 14 '17 at 15:18
  • @filtfilt I have not used that implementation but my immediate suspicion is that it is solving for your filter coefficients with which you still need to filter your signal. Good news that it is converging to a minimum error, look for anything that would return the filter coefficients and then try filtering your signal either with such a method if the object provides that or more traditionally with "filter": out = filter(b,a,in). Your implementation will be an FIR, so a =1 and b is the vector of the coefficients. – Dan Boschen May 14 '17 at 15:23
  • Thanks for the insanely fast answer. I will try it now, but basically, what I want to achieve is also mentioned in this thread,however, it is not answered and based on the papers that I read using RLS will do the job perfectly. Fingers crossed I get it working soon. – dsax7 May 14 '17 at 15:35
  • @filtfilt ok and if you have the benefit of being able to do post processing (as in you do not need an implementation that does streaming processing real time) then my solution that I showed with the loudspeaker example would likely be your best solution. The RLS and other adaptive solutions are best when you don't have the luxury of post processing large blocks of data. – Dan Boschen May 14 '17 at 15:39
  • The problem that I may be having with your solution is that I do not know the desired signal (TX), however, I can easily give the undesired signal and that is why I wanted to plot the error in my previous post. – dsax7 May 14 '17 at 15:49
  • Interesting. Is this similar to your application: https://dsp.stackexchange.com/questions/37902/adaptive-filtering-optimum-filter-length-and-delay ? – Dan Boschen May 14 '17 at 16:06
  • Yes, as I want to remove the hearth pulse from the signal and I can easily find it with a QRS Detector, so instead of having the desired signal I have the error. – dsax7 May 14 '17 at 16:12
  • Using the recursive least square filter is not as easy as I thought.. I still cannot get it to work and I also used a couple already made RLS filters like this one. – dsax7 May 14 '17 at 19:27
  • I started using this filter and it is almost working, but I can't seem to figure out what parameters I should take for the filter order and the forgetting factor. According to the papers, I should be using 0.999 for the forgetting factor and above order 20. However, this does not seem to work. After a decent amount of trying I ended up with order 2 and 0.1 as forgetting factor and this gave me an SNR of 13.76dB, but still the signal is not fully cleared. Sampling frequency is 1500Hz. – dsax7 May 19 '17 at 17:21