【发布时间】:2015-05-01 10:12:00
【问题描述】:
我正在研究最小均方算法并看到了这段代码。根据算法步骤,误差和权重更新的计算看起来没问题。但是,它无法给出正确的输出。有人可以帮忙解决问题吗?代码取自:
http://www.mathworks.com/matlabcentral/fileexchange/35670-lms-algorithm-implementation/content/lms.m
clc
close all
clear all
N=input('length of sequence N = ');
t=[0:N-1];
w0=0.001; phi=0.1;
d=sin(2*pi*[1:N]*w0+phi);
x=d+randn(1,N)*0.5;
w=zeros(1,N);
mu=input('mu = ');
for i=1:N
e(i) = d(i) - w(i)' * x(i);
w(i+1) = w(i) + mu * e(i) * x(i);
end
for i=1:N
yd(i) = sum(w(i)' * x(i));
end
subplot(221),plot(t,d),ylabel('Desired Signal'),
subplot(222),plot(t,x),ylabel('Input Signal+Noise'),
subplot(223),plot(t,e),ylabel('Error'),
subplot(224),plot(t,yd),ylabel('Adaptive Desired output')
编辑
答案中的代码:
N = 200;
M = 5;
w=zeros(M,N);
mu=0.2;%input('mu = ');
y(1) = 0.0;
y(2) = 0.0;
for j = 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):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
存储系数的权重矩阵 w 全部为零,这意味着 LMS 方程不能正常工作。
【问题讨论】:
-
你从哪里得到错误?对于 N=10 和 mu=0.1,代码有效。
-
没有语法错误。但是,所需输出的图表甚至与实际信号相差甚远。其次,当我应用此代码对自回归模型 AR(2) 进行参数估计时,我没有得到正确的权重/参数。我的目标是估计 AR(2) 模型的参数,其中 d(I) = 0.95*d(i-1) - 0.195*d(I-2); x = d+randn(1,N)*0.5;算法的输出应该给我 w_estimates 接近 w_actual = [0.95 -0.195]
标签: matlab least-squares