Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 如何绘制LMS算法的均方误差_Algorithm_Matlab - Fatal编程技术网

Algorithm 如何绘制LMS算法的均方误差

Algorithm 如何绘制LMS算法的均方误差,algorithm,matlab,Algorithm,Matlab,请告诉我如何为下面的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); %initi

请告诉我如何为下面的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  
其关键在于计算期望结果和获得结果之间的平方差之和,并在样本数上求平均值。因此:

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

您可以用
N
替换
大小(d,2)
,在您的情况下

首先您必须计算成本函数,如下所示

J(n) = e(n)*e(n)';
然后画出

MSE=10*log10(mean(J,1));

你能不能:1)正确格式化你的代码,2)解释什么是MSE和LMS。LMS是最小均方误差。MSE是均方误差对不起,我是新来的,我不知道如何格式化我的代码。如果您对代码本身有任何疑问,我想我可以回答。谢谢,我做到了。谢谢@Ander Biguri,请查看我的更新(在我回答下面的评论中)。另外,非常重要的是,请浏览网页了解其工作原理:并阅读如何询问@Rock,您可以将整个
尺寸(d,2)
替换为
N
,而不是
d
替换为
N
!如果要计算每次迭代的MSE,则需要将其另存为
MSE(i)
@Rock无忧;)跟上进度,想什么时候来就什么时候来!(但下次要更加小心;)