Filters¶
Filters are a common preprocessing method for reducing noise in signal processing.
mean_filter()
and median_filter()
can be applied to individual sequences.
See also
Consider using IndependentFunctionTransformer
to apply these filters to multiple sequences.
API reference¶
Methods¶
|
Applies a mean filter of size |
|
Applies a median filter of size |
- sequentia.preprocessing.transforms.mean_filter(x, *, k=5)¶
Applies a mean filter of size
k
independently to each feature of the sequence, retaining the original input shape by using appropriate padding.This is implemented as a 1D convolution with a kernel of size
k
and values1 / k
.- Parameters:
- Returns:
The filtered array.
- Return type:
Examples
Applying a
mean_filter()
to a single sequence and multiple sequences (independently viaIndependentFunctionTransformer
) from the spoken digits dataset.from sequentia.preprocessing import IndependentFunctionTransformer, mean_filter from sequentia.datasets import load_digits # Fetch MFCCs of spoken digits data = load_digits() # Apply the mean filter to the first sequence x, _ = data[0] xt = mean_filter(x, k=7) # Create an independent mean filter transform transform = IndependentFunctionTransformer(mean_filter, kw_args={"k": 7}) # Apply the transform to all sequences Xt = transform.transform(data.X, lengths=data.lengths)
- sequentia.preprocessing.transforms.median_filter(x, *, k=5)¶
Applies a median filter of size
k
independently to each feature of the sequence, retaining the original input shape by using appropriate padding.- Parameters:
- Returns:
The filtered array.
- Return type:
Examples
Applying a
median_filter()
to a single sequence and multiple sequences (independently viaIndependentFunctionTransformer
) from the spoken digits dataset.from sequentia.preprocessing import IndependentFunctionTransformer, median_filter from sequentia.datasets import load_digits # Fetch MFCCs of spoken digits data = load_digits() # Apply the median filter to the first sequence x, _ = data[0] xt = median_filter(x, k=7) # Create an independent median filter transform transform = IndependentFunctionTransformer(median_filter, kw_args={"k": 7}) # Apply the transform to all sequences Xt = transform.transform(data.X, lengths=data.lengths)