请告诉我如何绘制下面的Matlab代码的LMS算法的MSE曲线。提前谢谢。

clc
close all
clear all
N=input('length of sequence N = '); % filter length
t=[0:N-1];
w0=0.001;  phi=0.1;
d=sin(2*pi*[1:N]*w0+phi); %desired signal
x=d+randn(1,N)*0.5; % input of the filter
w=zeros(1,N); %initial weight
mu=input('mu = '); % alpha
for i=1:N
    e(i) = d(i) - w(i)' * x(i);  %error (desired-real output)
    w(i+1) = w(i) + mu * e(i) * x(i); % weight update of the filter
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');
end

最佳答案

mean squared error包括计算期望结果和获得结果之间的平方差之和,并在样本数上求其平均值。因此:

MSE=sum((d(:)-yd(:)).^2)./size(d,2);

在您的案例中,可以用size(d,2)替换N

10-06 14:58