Filtering the time series data
Removing the noise via smoothing is only one of the techniques. In this recipe, we will see how to use convolution and other filters to extract only certain frequencies from our data.
Getting ready
To execute this recipe, you will need pandas
, Statsmodels
, NumPy
, Scipy
, and Matplotlib
. No other prerequisites are required.
How to do it…
Convolution, in layman terms, can be understood as an overlap between a function f
(our time series) and some function g
(our filter). Convolution blurs the time series (and in this sense can be understood as a smoothing technique).
Note
A good introduction to convolution can be found at http://www.songho.ca/dsp/convolution/convolution.html.
The following script can be found in td_filtering.py
:
# prepare different filters MA_filter = [1] * 12 linear_filter = [d * (1/12) for d in range(0,13)] gaussian = sc.signal.gaussian(12, 2) # convolve conv_ma = riverFlows.apply( lambda col: sm.tsa.filters.convolution_filter( ...