how to implement a fast filter algorithm

조회 수: 8 (최근 30일)
Kilian
Kilian 2012년 7월 28일
댓글: Royi Avital 2014년 1월 30일
I have the following filter, but it runs very slow. How can I make it faster?
if true
% code
end
function [yfilt] = HPfilter(y, fs)
N = 5001; % Filter order (time delay will be (N-1)/2)
F6dB = 1500; % 6-dB Frequency
h = fdesign.highpass('n,fc', N, F6dB, fs);
Hd = design(h, 'window');
yfilt1 = filter(Hd,y);
y2 = fliplr(y);
yfilt2 = filter(Hd,y2);
yfilt2 = fliplr(yfilt2);
offset = yfilt2(N) - yfilt1(N);
yfilt1 = yfilt1 + offset;
yfilt = [yfilt2(1:(N-1)) yfilt1(N:end)];
I run the filter twice from both sides to elminiate the effect of the impulse response.
The sampling rate of the data (fs) is 5.12 MHz. The cutoff for the high pass is 1.5 kHz. I would reduce the order number if I could, but can't accept the degradation of performance. Some of the data files have 500,000 points.
Is there any way to remove the low frequency stuff of my data in a faster way?
Thanks for your help in advance.

답변 (2개)

Wayne King
Wayne King 2012년 7월 28일
편집: Wayne King 2012년 7월 30일
I would try using filtfilt.m instead of filter() followed by your other code to do zerophase filtering.
Replace:
yfilt1 = filter(Hd,y);
with
yfilt = filtfilt(Hd.Numerator,1,y);
Or
yfilt = filtfilt(Hd.sosMatrix,Hd.ScaleValues,y);
and then eliminate the rest.
Also, why do you need to do the filter specification and design inside the function? That is expensive. I would recommend doing that outside the function in which case you just pass filtfilt() the filter design object if you follow my recommendation.
  댓글 수: 2
Kilian
Kilian 2012년 7월 30일
Thanks for your advice. However, filtfilt doesn't work on a filter object. I get an error "not enough input arguments'.
y = filtfilt(b,a,x) y = filtfilt(SOS,G,x)
How can I obtain b and a or SOS and G from the filter object?
Wayne King
Wayne King 2012년 7월 30일
편집: Wayne King 2012년 7월 30일
@Jerome, Sorry!!! I've edited the post to correct that.

댓글을 달려면 로그인하십시오.


Jan
Jan 2012년 7월 31일
Matlab's filter implementation has a potential for speed improvements. See Fex: FilterM. Unfortunately the version posted there does not exploit the simpler processing for the FIR type filter. It is updated soon.
  댓글 수: 1
Royi Avital
Royi Avital 2014년 1월 30일
Is it still faster than the latest MATLAB versions?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by