Speed up FIR filter
이전 댓글 표시
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.
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
2017년 10월 17일
답변 (1개)
Christoph F.
2017년 10월 18일
1 개 추천
As an answer:
Using filter() instead of filtfilt() to apply the filter will speed up the calculation by an order of magnitude.
카테고리
도움말 센터 및 File Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!