gastropy.mad_filter

Contents

gastropy.mad_filter#

gastropy.mad_filter(data, n_sigma=3.0)[source]#

Remove outliers using a global median absolute deviation filter.

Computes a single global median and MAD across the entire signal. Samples deviating by more than n_sigma * 1.4826 * MAD are replaced by the global median. Faster than hampel_filter but less adaptive to signal drift.

Parameters:
  • data (array_like) – EGG signal(s). Accepts shape (n_samples,) or (n_channels, n_samples).

  • n_sigma (float, optional) – Outlier threshold in scaled MAD units. Default is 3.0.

Returns:

cleaned – Signal with global outliers replaced by the median. Same shape as input.

Return type:

np.ndarray

References

Dalmaijer, E. S. (2025). electrography v1.1.1. esdalmaijer/electrography

Examples

>>> import numpy as np
>>> from gastropy.signal import mad_filter
>>> rng = np.random.default_rng(0)
>>> sig = rng.standard_normal(1000)
>>> sig[200] = 50.0  # inject a large global outlier
>>> cleaned = mad_filter(sig)
>>> np.abs(cleaned[200]) < 5.0
True