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?

  • $\begingroup$ Just for fun, is your requirement for a highpass over 0.1 Hz really important here? It could totally be! But maybe not actually if you know that no significant frequency component is likely to be present. I already came through a project where people where bandpass filtering a signal with a very low highpass frequency only because it was about (with a margin) the lowest frequency their signal could be. But in the end after a Fourier analysis no lower frequency component was present so they just dropped the highpass. Just a thought! $\endgroup$
    – Doombot
    Nov 20, 2014 at 17:57

1 Answer 1


Yes, you can get much better results if you downsample your data first. The problem occurs because the width of your transition band relative to the original data sample rate is very small. This can cause numerical problems when designing or implementing digital filters. The problem only gets worse as the filter order increases, especially with IIR filters.

With that said, in some cases, you might have more success (i.e. better numerical stability) if you convert the filter to second-order sections. However, for this case, I think the right answer is to downsample the data first.

The problem likely occurs because of the very small cutoff frequency on the low end of your bandpass filter. There is very little room for the transition band (less than 0.1 Hz, which is 1/320000-th of the sample rate), which is difficult to implement. If you downsample the data as much as possible, then you can at least increase this ratio by a good amount, which should give you better results.

I would also try using FIR filter implementations if possible, as they typically have superior numerical stability due to their lack of feedback.

  • $\begingroup$ thanks. Can you elaborate a bit on why 0.1Hz doesn't work? I have no problems with a cutoff of 1Hz. Furthermore, if I downsample (through resampling) does this have a (potentially bad effect) on my signal frequencies (for example if I'm interested in certain phases of the signal?) $\endgroup$
    – memyself
    Nov 20, 2014 at 16:34
  • $\begingroup$ @memyself before you downsample you want to apply an anti-aliasing filter $\endgroup$ Nov 20, 2014 at 17:09
  • $\begingroup$ @DavidWurtz what kind of anti-aliasing filter would you use? $\endgroup$
    – memyself
    Nov 20, 2014 at 17:14
  • 1
    $\begingroup$ @memyself you could, for example, apply a 4th order butterworth low-pass filter at 500 Hz, then keep every 16th sample. This would bring your sample rate 2000 Hz (and Nyquist down to 1000 Hz). The anti-aliasing filter will give you 24dB of attenuation at Nyquist. The anti-aliasing filter will have a noticeable affect on the phase in your band of interest (down to about 50 Hz, a decade below the cutoff). You can look at a bode plot of your anti-aliasing filter to see how much phase shift you'll get. $\endgroup$ Nov 20, 2014 at 17:30

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.