Filtering (filtrate)

Filtering removes or reduces some unwanted components (such as noise) from an observation sequence according to some window size and one of two methods: median and mean filtering.

Suppose we have an observation sequence \(\mathbf{o}^{(1)}\mathbf{o}^{(2)}\ldots\mathbf{o}^{(T)}\) and we are filtering with a window size of \(n\). Filtering replaces every observation \(\mathbf{o}^{(t)}\) with either the mean or median of the window of observations of size \(n\) containing \(\mathbf{o}^{(t)}\) in its centre.

  • For median filtering: \(\mathbf{o}^{(t)\prime}=\mathrm{med}\underbrace{\left[\ldots, \mathbf{o}^{(t-1)}, \mathbf{o}^{(t)}, \mathbf{o}^{(t+1)}, \ldots\right]}_n\)
  • For mean filtering: \(\mathbf{o}^{(t)\prime}=\mathrm{mean}\underbrace{\left[\ldots, \mathbf{o}^{(t-1)}, \mathbf{o}^{(t)}, \mathbf{o}^{(t+1)}, \ldots\right]}_n\)

For further information, please see the preprocessing tutorial notebook.

Example

1
2
3
4
5
6
7
8
import numpy as np
from sequentia.preprocessing import filtrate

# Create some sample data
X = [np.random.random((10 * i, 3)) for i in range(1, 4)]

# Filter the data with window size 5 and median filtering
X = filtrate(X, n=5, method='median')

API reference

sequentia.preprocessing.filtrate(X, n, method='median')[source]

Applies a median or mean filter to the input observation sequence(s).

Parameters:
X: numpy.ndarray or List[numpy.ndarray]

An individual observation sequence or a list of multiple observation sequences.

n: int

Window size.

method: {‘median’, ‘mean’}

The filtering method.

Returns:
filtered: numpy.ndarray or List[numpy.ndarray]

The filtered input observation sequence(s).