Speed up FIR filter
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I have to filter large amount of data with a FIR filter. My code works, but is rather slow. Is there a trick to speed it up (apart from FilterM)?
if true
ftype='bandpass';
Fn = SamplingRate/2; % Nyquist Frequency
HP=100; % High pass
LP=1000; % Low pass
Wp = [round(HP-0.1*HP) HP LP round(LP+0.1*LP)];
mags = [0 1 0];
devs = [0.05 0.01 0.05];
[n,Wn,beta,ftype] = kaiserord(Wp,mags,devs,SamplingRate);
n = n + rem(n,2);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'scale');
FilteredSignal=filtfilt(hh,1,UnfilteredSignal); % filter step
end
2 comentarios
Christoph F.
el 17 de Oct. de 2017
Editada: Christoph F.
el 17 de Oct. de 2017
Why are you using filtfilt (which applies the filter twice, forward/backward) with a symmetric FIR filter (which is linear phase by itself and doesn't need forward-backward filtering to achieve linear phase)?
filtfilt() takes about 20 times as long as doing regular forward filtering with filter().
Avoid using filtfilt unless there is a pressing reason to do so (i.e. linear phase required when the filter itself is not linear phase). Also, keep in mind that filtfilt applies the filter twice and the frequency response will not correspond to what you see with freqz().
Also, be aware that filtfilt is, in essence, acausal. The input sample value at t0 will affect the output sample value at t1<t0, i.e. the present will be affected by the future.
Respuestas (1)
Christoph F.
el 18 de Oct. de 2017
As an answer:
Using filter() instead of filtfilt() to apply the filter will speed up the calculation by an order of magnitude.
0 comentarios
Ver también
Categorías
Más información sobre Digital and Analog Filters en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!