📄 testnlms.m
字号:
% NLMS used in a simple system identification application.
% By the end of this script the adaptive filter w
% should have the same coefficients as the unknown filter h.
iter = 5000; % Number of samples to process
% Complex unknown impulse response
h = [.9 + i*.4; 0.7+ i*.2; .5; .3+i*.1; .1];
xn = 2*(rand(iter,1)-0.5); % Input signal, zero mean random.
%xn = filter(.4, [1 -.6], xn);
% although xn is real, dn will be complex since h is complex
dn = filter(h,1,xn); % Unknown filter output
en = zeros(iter,1); % vector to collect the error
% Initialize the NLMS algorithm with a filter of 10 coef.
[w,x,d,y,e,p]=init_nlms(10);
%% Processing Loop
for (m=1:iter)
x = [xn(m,:); x(1:end-1,:)]; % update the input delay line
d = dn(m,:) + 1e-3*rand; % additive noise of var = 1e-6
% call NLMS to calculate the filter output, estimation error
% and update the coefficients.
[w,y,e,p]= asptnlms(x,w,d,0.05,p,0.98);
% save the last error sample to plot later
en(m,:) = e;
end;
% display the results
subplot(2,2,1);stem([real(w) imag(conj(w))]); grid;
xlabel('filter after convergence')
subplot(2,2,2);
eb = filter(0.1, [1 -.9] , en .* conj(en));
plot(10*log10(eb ));grid
axis([0 5000 -80 0]);
ylabel('estimation error [dB]')
xlabel('Learning curve')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -