Speed up FIR filter

15 次查看(过去 30 天)
Peter
Peter 2017-10-17
回答: Christoph F. 2017-10-18
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 个评论
Christoph F.
Christoph F. 2017-10-17
编辑:Christoph F. 2017-10-17
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.
Peter
Peter 2017-10-17
Thanks for your advice - you are absolutly right. The filtfilt stemmed from a former butterworth filter, where it is eesential...

请先登录,再进行评论。

回答(1 个)

Christoph F.
Christoph F. 2017-10-18
As an answer:
Using filter() instead of filtfilt() to apply the filter will speed up the calculation by an order of magnitude.

类别

Help CenterFile Exchange 中查找有关 Digital Filter Design 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by