请您告诉我如何绘制下面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
答案 0 :(得分:2)
mean squared error包括计算所需和获得的结果之间的平方差之和,并对样本数进行平均。因此:
MSE=sum((d(:)-yd(:)).^2)./size(d,2);
您可以在案例中将size(d,2)
替换为N
答案 1 :(得分:1)
首先你必须计算成本函数,如
J(n) = e(n)*e(n)';
然后绘制
MSE=10*log10(mean(J,1));