Least Mean Square Algorithm
조회 수: 4 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Ameer Hamza
2018년 4월 25일
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!