statsmodels.tsa.filters.filtertools.convolution_filter¶
-
statsmodels.tsa.filters.filtertools.
convolution_filter
(x, filt, nsides=2)[source]¶ Linear filtering via convolution. Centered and backward displaced moving weighted average.
Parameters: - x (array_like) – data array, 1d or 2d, if 2d then observations in rows
- filt (array_like) – Linear filter coefficients in reverse time-order. Should have the
same number of dimensions as x though if 1d and
x
is 2d will be coerced to 2d. - nsides (int, optional) – If 2, a centered moving average is computed using the filter coefficients. If 1, the filter coefficients are for past values only. Both methods use scipy.signal.convolve.
Returns: y – Filtered array, number of columns determined by x and filt. If a pandas object is given, a pandas object is returned. The index of the return is the exact same as the time period in
x
Return type: ndarray, 2d
Notes
In nsides == 1, x is filtered
y[n] = filt[0]*x[n-1] + ... + filt[n_filt-1]*x[n-n_filt]
where n_filt is len(filt).
If nsides == 2, x is filtered around lag 0
y[n] = filt[0]*x[n - n_filt/2] + ... + filt[n_filt / 2] * x[n] + ... + x[n + n_filt/2]
where n_filt is len(filt). If n_filt is even, then more of the filter is forward in time than backward.
If filt is 1d or (nlags,1) one lag polynomial is applied to all variables (columns of x). If filt is 2d, (nlags, nvars) each series is independently filtered with its own lag polynomial, uses loop over nvar. This is different than the usual 2d vs 2d convolution.
Filtering is done with scipy.signal.convolve, so it will be reasonably fast for medium sized data. For large data fft convolution would be faster.