My data is sampled at $f_s = 32kHz$, and for a particular analysis I'm only interested in signals with certain frequencies from $f_{highpass} = \text{0.1Hz}$ to $f_{lowpass} = \text{300 Hz}$.
When I build and apply a 4th order butterworth filter to my data I get an error and there's not much left of the signal. Here's some Matlab code:
order = 4;
[b,a] = butter(order, [0.1 300]/(32000/2), 'bandpass');
y = filtfilt(b,a,data);
The error message I get is: Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.101227e-16.
I've also tried to apply a low pass filter first, then followed by a highpass filter:
FOI = [0.1 300]
SampleRate = 32000;
[b_l,a_l] = butter(order, FOI(2)/(SampleRate/2), 'low' );
[b_h,a_h] = butter(order, FOI(1)/(SampleRate/2), 'high' );
tempData = filtfilt(b_l, a_l, data);
output = filtfilt(b_h, a_h, tempData);
But I keep getting the same result.
My questions:
- why does the filtering fail?
- why does the filtering with order 3 work but not with order 4?
- do I need to downsample the data (e.g. to 1kHz) before I can do the filtering?
EDIT: other people have hit the same problem but I'm looking for a definite answer.
EDIT2: if I change the highpass value to 1
and do the highpass filtering before the lowpass filtering, everything works. But why? Why is the cutoff of 0.1
causing problems?