Least Mean Square Algorithm

18 vues (au cours des 30 derniers jours)
curly133
curly133 le 24 Avr 2018
Modifié(e) : curly133 le 25 Avr 2018
Hello. I am trying to implement this pseudo code to make a Least mean square algorithm. I'm not too good at matlab yet and I got stuck with this algorithm. I need to make an LSM algorithm to help me determine my filter "h". Here is the pseudo code:
Here is what I have so far. I load a signal that gives me two variables x and y, both length 500, then I need to apply the algorithm. I am not too sure how to apply xn from the pseudo code or how to finish this off really.
load sig.mat; % loads variables x and y
N = 5; % filter length
u = .01; % learning rate
h = zeros(1,N);
for n = 0:499
xn = x(n-(N-1));
en = y(n) - (h.')*xn;
h = h + u*en*xn;
end

Réponse acceptée

Ameer Hamza
Ameer Hamza le 25 Avr 2018
In your code, the way you are accessing the values of xn is wrong. x(n-(N-1)) will assign a single number to xn not an N element array. Additionally, in the algorithm you gave, the vector index starts from 0 while in MATLAB the vector index starts from 1, so you need to take care of that as I have done in the following code. Also, the filter is using past values from vector x. At beginning e.g. n=1 you don't have past values of x i.e. x(0), x(-1), ... therefore I have added an if condition which will add extra zeros to the to xn in those cases.
load sig.mat; % loads variables x and y
N = 5; % filter length
u = .01; % learning rate
h = zeros(1, N);
for n = 1:500
if n-N < 1
xn = [x(n:-1:1); zeros(N-n, 1)];
else
xn = x(n:-1:n-N+1);
end
en = y(n) - h*xn;
h = h + (u*en*xn)';
end
  1 commentaire
curly133
curly133 le 25 Avr 2018
Modifié(e) : curly133 le 25 Avr 2018
Thank you! This makes a lot more sense now.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Standard File Formats dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by