I'm having some trouble implementing my LMS Adaptive Filter in MATLAB to separate wideband and narrowband signals from a voice signal.

I'm using a delayed version of my input as a reference as well as the error term.

step = 0.01;
w = zeros(1, N);
xDelayed = [zeros(1, 100) x']'; % delaying input

for n=1:length(x)
e = x(n) - w(1)*xDelayed(n);
w = w - step*e*xDelayed(n);
end


It's essentially an implementation of this

$$w(n+1) = w(n) - \alpha e(n) x(n)$$

For some reason, my entire w (N long) vector is all the same value. UPDATE:

M = 5;
N = length(sound)
w = zeros(M, N);
STEP_SIZE = 0.01;
d = sound;
x = sound_delayed(1:N);

for i=(M+1):N
e(i) = d(i) -  x((i-(M)+1):i)*w(:,i);
w(:,i+1) = w(:,i) + mu * e(i) * x((i-(M)+1):i)';
end
for i=(M+1):N
yd(i) = x((i-(M)+1):i)*w(:,i);
end


There are several problems in your code. First, it looks like you're confusing iteration and vector indices. The computation of e should use all values of the current (delayed) data vector, filtered with the current filter coefficients. In the update equation, you subtract a scalar from a vector, which is not what you want. Again you should be using all values of the current data vector (the length of which must equal the chosen filter length).
• @AlfroJang80: Doesn't your code produce an error? How can you multiply w and xDelayed if they have different lengths? – Matt L. Nov 19 '18 at 12:17
• @AlfroJang80: yes, you must use the most recent $N$ values of the (delayed) data vector. – Matt L. Nov 19 '18 at 12:22