필터 지우기
필터 지우기

Speed up FIR filter

조회 수: 13 (최근 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 and Analog Filters에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by