Python butter filter: choosing between analog and digital filter types

I have a system that performs wireless sampling of data about every 7.5ms (133Hz). Due to it being wireless, I get occasional data drop out. I want to construct a LP butter filter with cut-off frequency of 10Hz using Python's scipy butter method and then downsample everything to a lower frequency.

One of the options that it asks for is whether I want to use analog or digital filter. Isn't running this filter offline in python automatically assume that it's digital? Or does the fact that my samples don't necessarily come in at regular intervals mean that I should stick with analog filter?

I understand how a physical analog filter differs from a digital one, but does this difference apply in the same way to a python-based butter filter?

Isn't running this filter offline in python automatically assume that it's digital?

butter() doesn't filter your signal, it just designs the filter. It can design an analog filter or a digital filter.

lfilter() is what actually filters your signal, using the filter you designed, and as you can see it is only digital filtering. It doesn't make sense to filter a digital signal with an analog filter.

If your data is regularly sampled and you want to process it in a computer, then you need a digital filter. However it sounds like it isn't:

...
my samples don't necessarily come in at regular intervals

Do you have a timestamp of when each sample was taken? If you do, then do interpolation first:

from scipy import interpolate
f = interpolate.interp1d(timestamps, measurements)
new_timestamps = np.linspace(min(timestamps), max(timestamps), len(timestamps)*3)
new_measurements = f(new_timestamps)


and then digitally filter the interpolated signal. (I'm just picking 3x oversampling arbitrarily.)

Probably your data is not bandlimited? So you need to plot the interpolation and decide which type of interpolation is the most realistic fit for the underlying data.

• I do have a timestamp of each measurement. At the moment, what I've tried doing is upscale the data by the numerator of the fraction -> filtfilt with butter(8, 0.5/downscaleFactor) design and then downscale by the denominator of the fraction. This seems to work more or less, but somehow filtering appears to be too aggressive. Thank you for your link though, I'll have a look now – user1514188 May 3 '17 at 9:42
• @user1514188 If you have timestamps, then do interpolation first (with timestamps as x and values as y and equally-spaced denser timestamps as xnew), and then digitally filter the interpolated signal. Probably your data is not bandlimited? So you need to decide which type of interpolation is the most realistic fit for the underlying data. – endolith May 3 '17 at 13:21

If you have occasional data dropout, I'm not sure that decimation is the best solution. Perhaps you could use some kind of median filter?

That being said, since you work with sampled data, analog filters don't make much sense, better stick with digital methods.