# Least Mean Squares Algorithm confusion with Adaptive Line Enhancement

I'm just a bit confused about the least mean squares algorithm to separate wideband and narrowband in an adaptive filter for voice conversation. I'm interested in the narrowband part and I'm confused about the LMS equation as follows:

Is h being iterated twice here with j and n? Wouldn't that mean I have two different sets of h values?

I'm having trouble putting this into MATLAB.

I recommend you read up on the LMS algorithm and try to understand it before you start implementing it, otherwise you won't be able to find any errors in your code. In that formula, the index $$n$$ is the iteration number, and the index $$j$$ is the vector index of the filter coefficients. So at any iteration $$n$$ you have $$N+1$$ filter coefficients (indexed by $$j$$) that need to be updated according to that equation.

• Ah, so alternatively I could just write h as a column vector in bold and then just iterate the n's? – AlfroJang80 Nov 18 '18 at 18:01
• @AlfroJang80: Yes, you can do that. – Matt L. Nov 18 '18 at 18:08
• Okay, one last quesiton. In terms of the x in that equation which is meant to be the input to the ADF. In my case, I'm using a delayed version of my actual input. So I would just have xDelayed_n-j. Now, I'm just really confused how to implement that part into MATLAB? Like for my first loop iteration, how do I go back in my xDelayed values? Am I meant to start at the end of the xDelayed vector? If you know of any examples, please let me know. I understand the algorithim ,its just the implementation – AlfroJang80 Nov 18 '18 at 18:10
• @AlfroJang80: Well, then what is called $x_n$ in your equation is just $x_{n-D}$, where $D$ is the delay in samples. So your vector consists of the elements $x_{n-D},x_{n-D-1,\ldots}$. – Matt L. Nov 18 '18 at 18:18
• Hmm. I see. In terms of calculating my error on each n iteration, would I be taking my undelayed original signal value at the n'th element (x(n)) and then from that subtract h(:, n) which is all my filter coefficients times the n'th element of my delayed signal (x_delayed(n))? SO it would be e(n) = x(n) - h(:, n)*x_delayed(n) – AlfroJang80 Nov 18 '18 at 18:32

Eventhough you have an (accepted) answer as provided by MattL. I would like to point out just another explanation of that LMS update equation.

Least Mean Squares adaptive filter algorithm is the most fundamental application of (statistically) optimum Wiener filter, where the algorithm indeed performs a steepest descend (gradient based) search of the optimum operation point; best filter coefficients that provide minimum (expected value of the) error square.

The simplicity of LMS comes from its replacement of theoretical gradient estimation with very simple practical ones. And the filter coefficient update equation (for real data) becomes what you have provided:

$$\bar{w}(n+1) = \bar{w}(n) - \alpha ~ e(n) ~ \bar{x}(n)$$

Where $$\bar{w}(n)$$ is the $$N$$-tap FIR LMS filter coefficients (its impulse response) at time (or the iteration) $$n$$,

$$\bar{w}(n) = [w_0(n), w_1(n),...,w_{N-1}(n)]^T$$

and $$\bar{x}(n)$$ is the filter input of $$N$$ samples: $$\bar{x}(n) = [x(n), x(n-1),...,x(n-N+1)]^T$$ at time $$n$$ beginning with current sample $$x(n)$$.

The parameter $$\alpha$$ (actually $$\mu$$ in most textbooks) is the very important step-size parameters that controls the filter convergence behaviour vs resulting steady-state error power after convergence and the term $$e(n)$$ is the current (scalar) error at time $$n$$ given by the difference of current value of the desired response $$d(n)$$ and the current filter output $$y(n) = \bar{x}^T \bar{w} = \bar{w}^T \bar{x}$$ as $$e(n) = d(n) - y(n)$$.

$$\bar{w}(n+1)$$ is the updated (next) value, based on the current error computed via $$\bar{w}(n)$$ the current value of filter coefficients.

The equation you have provided just displays the vector equation above in terms of its individual elements.

• Are you taking about RLS ? What do you mean by desired value $d(n)$ ? – Zeyad_Zeyad Nov 18 '18 at 23:37
• @Zeyad_Zeyad its LMS not RLS and its desired signal (or response) $d(n)$ that the LMS filter is trying to estiamte by processing its input $x(n)$. – Fat32 Nov 18 '18 at 23:43
• Hi: along the lines of what Fat32 said, if you want to understanding what's happening in depth, then rather than LMS, you might be better of looking at a numerical algorithms text and and reading about the method of steepest descent. ( there are tons. if you need a suggestion, let me know ). I'm not familar with LMS ( the term) but it looks to be like the coefficients are being updated through the use of the steepest descent algorithm so understanding that algorithm is key to understanding what's happening. LMS is just the name used due to the specific application of steepest descent. – mark leeds Nov 19 '18 at 1:15
• also, "variable metric algorithm" will also be useful because the adaptive line enhancement part is probably related to that. – mark leeds Nov 19 '18 at 1:18
• @Fat32 Amazing answer. One more question. For calculating the error, say for iteration 1. I would have error(1) = x(1) - w(:, 1)*x_delayed(1). Would that be correct? The second term there is the filter output, I've seen others use that online but I feel like I should actually be using a real filter. I mean with this equation, w(:, 1) isn't just one value, so how would error(1) be one value??? – AlfroJang80 Nov 19 '18 at 1:42