1
$\begingroup$

guess I'm stuck with this filtering problem and I'm thinking it has something to do with my raw data but I'm not so sure. So the problem is the following, please refer to the figures below, basically, all I'm trying to do is implement a bandpass Butterworth filter to filter the raw data trace (green). The raw data consists of 2501 points and was sampled at 20 kHz (100-ms). I'd like to bandpass filter this trace between 3 Hz and 170 Hz using the Matlab function 'butter' followed by either 'filter' (top figure) or 'filtfilt' (bottom figure), preferably the latter.

My Matlab code is as follows:

A = Average(1,:); % raw data
fs_Hz = 20000; % sampling rate (Hz)
order = 3;
fcutlow = 3; % Hz
fcuthigh = 170; % Hz
[b,a]  = butter(order,[fcutlow,fcuthigh]/(fs_Hz/2), 'bandpass');
x = filtfilt(b,a,A);
plot(x);
hold on
plot(A,'color','g');
legend('filtered data','raw data'); 

enter image description here

enter image description here

As you might guess the problem is the offset that I observe after both filtering functions. These 2501 point traces actually stem from a very long data-trace, should I possibly filter this long trace prior to extracting these smaller traces? Is the reason for the offset the fluctuating pattern of the trace? I can't detrend the data as I need the y-axis information for the subsequent analysis on this data. Should I be using a completely different type of filtering method; FIR instead of IIR?? Any advice on my problem would be greatly appreciated.

IljaPilja

$\endgroup$

1 Answer 1

2
$\begingroup$

Your data have a non-zero DC component which is filtered out by the bandpass filter. So the filter output has approximately zero DC, which causes the corresponding vertical shift of the signal. If you want to retain the DC information in the signal you must use a lowpass filter instead of a bandpass filter.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.