Low pass Linear Filter in python

Viewed 349

I have red a lot about filtering time series but I really have difficulties to understand properly the scipy scipy.signal.filtfilt.

In particular its parameters a and b. For example how I should reproduce the following filter? Even with others libs if is easier.

enter image description here

Can anyone help me? I give you a starting point:

np.random.seed(123)
N = 100
rng = pd.date_range('2019-01-01', freq='min', periods=N)
df = pd.DataFrame(np.random.rand(N, 1), index=rng)

1 Answers

You say your plot shows a low-pass linear filter. I assume the plot shows the coefficients of a FIR filter. If so, you can pass those coefficients as the b argument of scipy.signal.lfilter (or scipy.signal.filtfilt, but using filtfilt with a FIR filter is probably not what you want). Set the a parameter to 1.

You could also apply the filter to a signal with a convolution function, such as numpy.convolve, scipy.signal.convolve or scipy.ndimage.convolve1d. Take a look at the article Applying a FIR Filter (but note that the performance results shown there are not up to date--both NumPy and SciPy continue to develop, and the relative performance of the different methods discussed there can change between versions).

Related