Matlab: How to fix Least Mean square algorithm code -


I am studying at least the Mean Square algorithm and have seen this code. Based on the algorithmic steps, the calculation of the update of the error and weight looks fine. However, it fails to deliver the correct output. Can anyone help fix the problem? The code has been taken from:

  clc all clear all N = input (length of 'sequence N ='); T = [0: N1]; W0 = 0.001; Phi = 0.1; D = sin (2 * pi * [1: n] * w0 + fay); X = d + randn (1, n) * 0.5; W = zero (1, n); Mu = input ('mu ='); For I = 1: NE (I) = D (I) - W (i) '* x (i); W (i + 1) = w (i) + mu * e (i) * x (i); I = 1 for end n yd (i) = yoga (w (i) '* x (i)); End (221), Plot (T, D), Ibabel ('Desired Signal'), Subplot (222), Plot (T, X), Ibabel ('Input Signal + Noise'), Subplot (223), Plot T, E), ylabel ('error'), subplot (224), plot (t, wd), ylabel ('adaptive desired output')  

edit

Answer code:

  N = 200; M = 5; W = zero (m, n); Mu = 0.2;% Input ('mu ='); Y (1) = 0.0; Y (2) = 0.0; Jammu = 3: n Y (j) = 0.95 * y (j-1) - 0.195 * y (j-2); End x = y + randn (1, n) * 0.5; % X = y; D = y; For I = (M + 1): NE (I) = D (i) - x ((i- (m) + 1): i) * w (:, i); W (:, i + 1) = w (:, i) + mu * e (i) * x ((i- (m) + 1): i) '; I = (m + 1) for end n yd (i) = x ((i- (m) + 1): i) * w (:, i); End  

The weight matrix W, which stores the coefficients, all are zero, which means that the LMS equations are not working properly.

I do not find any mistakes in your code. But I suspect that this algorithm is suitable for such noise. When using the higher order (in this case M) you will get better results:

  M = 5; W = zero (m, n); Mu = 0.2;% Input ('mu ='); For I = (M + 1): NE (I) = D (i) - x ((i- (m) + 1): i) * w (:, i); W (:, i + 1) = w (:, i) + mu * e (i) * x ((i- (m) + 1): i) '; I = (m + 1) for end n yd (i) = x ((i- (m) + 1): i) * w (:, i); End  

Comments