Carrying filter state from adaptive to non-adaptive
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I would like to develop a simple simulation of using an adaptive filter to track a signal over a training period. And then to use the final coefficients of that adaptive filter on a regular, non-adaptive filter. So I made the following code snippet, however there is a significant jump during the transition. Is there an example of how to do this correctly, please?
I thought I had done it correctly by:
%%training period
[Est1n,Err1n] = filter(AdaptH, xn(1:Ntraining), yn(1:Ntraining));
hEst = AdaptH.coefficients;
hState = AdaptH.states;
%%fixed filter period
[Est2n] = filter(hEst, 1, xn(Ntraining+1:end), hState);
Err2n = yn(Ntraining+1:end) - Est2n;
I have also tried stating:
Nfilt = 10; mu = 0.8; offset = 10; AdaptH = adaptfilt.nlms(Nfilt,mu,1,offset);
AdaptH.Persistent = 1;
But still it didn't work.
Full demo code follows.
Thanks in advance.
Julius
clear all;
Nsignal = 1024;
Ntraining = 128;
xn = randn(Nsignal,1);
hTrue = [1 -0.2 0 0 0.1 0.5 0 -0.2].';
tn = filter(hTrue,1,xn);
yn = tn + 0.02*randn(Nsignal,1);
Nfilt = 10; mu = 0.8; offset = 10; AdaptH = adaptfilt.nlms(Nfilt,mu,1,offset);
%%training period
[Est1n,Err1n] = filter(AdaptH, xn(1:Ntraining), yn(1:Ntraining), hState);
hEst = AdaptH.coefficients;
hState = AdaptH.states;
%%fixed filter period
[Est2n] = filter(hEst, 1, xn(Ntraining+1:end));
Err2n = yn(Ntraining+1:end) - Est2n;
%%show results
figure;
subplot(211);
plot((1:Nsignal), tn, 'b', 'linewidth', 1.5); hold on;
plot((1:Ntraining), Est1n, 'ok', 'linewidth', 1.5);
plot((Ntraining+1:Nsignal), Est2n, 'og', 'linewidth', 1.5); hold off;
legend('Ideal noiseless signal', 'Estimate during training', 'Estimate after training');
subplot(212);
plot((1:Nsignal), [Err1n; Err2n], 'r', 'linewidth', 1.5);
legend('Error signal');
0 comentarios
Respuestas (1)
Puneet Rana
el 17 de Mzo. de 2015
Instead of adaptfilt.nlms, try the recent dsp.LMSFilter object:
This object has the property 'AdaptInputPort' that lets you provide a control input which decides if the filter weights should be adapted or not. See the second example on the above page. I have modified it slightly to show how to turn off adaptation after initial training period:
hlms2 = dsp.LMSFilter('Length',11, ...
'Method','Normalized LMS',...
'AdaptInputPort',true, ...
'StepSizeSource','Input port', ...
'WeightsOutputPort',false);
hfilt2 = dsp.FIRFilter('Numerator', fir1(10,[.5, .75]));
x1 = randn(1000,1); % Noise
d1 = step(hfilt2,x1) + sin(0:.05:49.95)'; % Noise + Signal
x2 = randn(1000,1); % Noise
d2 = step(hfilt2,x2) + sin(0:.05:49.95)'; % Noise + Signal
a = 1; % adaptation control
mu = 0.05; % step size
[y1, err1] = step(hlms2,x1,d1,mu,a); % training period
a = 0;
[y2, err2] = step(hlms2,x2,d2,mu,a); % fixed filter period
figure;
subplot(2,1,1);
plot([d1;d2]);
title('Noise + Signal');
subplot(2,1,2);
plot([err1;err2]);
title('Signal');
0 comentarios
Ver también
Categorías
Más información sobre Adaptive Filters en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!