matlab 讲解 回声消除 我有程序但是运行很久不知道原因
function [e,mse,ce] = nlms(ylong,xlong,L,hEP)
% adaptive filter here with the following inputs and outputs:
%ylong this is a lngexp by 1 vector of far-end signal
%xlong a lngexp by 1 of near-end signal
%L, the length of the adaptive filter scalar
%hEP, the L by 1 vector is the true echo path vector
%e is a lngexp by 1 vector of cancelled echo
%mse is a lngexp by 1 vector of filtered error energy expressed in dB
%ce is a lngexp by 1 length vector of coefficient error expressed in dB
mu=0.5;
delta=0.01;
alpha=0.95;
ylngexp = length(ylong);
xlngexp = length(xlong);
lngexp = min(xlngexp,ylngexp);
e=zeros(lngexp,1);
mse=zeros(lngexp,1);
ce=zeros(lngexp,1);
w=zeros(L,1);
y=zeros(L,1);
hEP=hEP(:);
for n=1:lngexp
y=[ylong(n);y(1:L-1)];
x = y'*w;
e(n)=xlong(n) - x;
wdelta=mu*y*e(n)/(delta+y'*y);
w=w+wdelta;
if n>=2
mse(n)=alpha*mse(n-1)+(1-alpha)*e(n)^2;
else
mse(n)=alpha*0+(1-alpha)*e(n)^2;
end
ce(n)=10*log10(((hEP-w)'*(hEP-w))/(hEP'*hEP));
end
mse=10*log10(mse);