gastropy.remove_movement_artifacts#
- gastropy.remove_movement_artifacts(data, sfreq, freq=0.05, window=1.0)[source]#
Attenuate movement artifacts using an LMMSE Wiener filter.
Estimates local signal variance within sliding windows and computes a Wiener-like (LMMSE) correction that suppresses time segments dominated by movement noise while preserving the gastric rhythm.
The algorithm:
For each sample, compute the local mean
E[y]and variancevar_yin a window of lengthwindow / freqseconds.Estimate the signal-of-interest variance
var_eas the mean of all local variances.Compute the predicted noise contribution:
x_hat = E[y] + clip(var_y - var_e, 0) / max(var_y, var_e) * (y - E[y])
Return the residual
y - x_hat.
- Parameters:
data (array_like) – EGG signal(s). Accepts shape
(n_samples,)or(n_channels, n_samples).sfreq (float) – Sampling frequency in Hz.
freq (float, optional) – Centre frequency of interest in Hz. Used to set the window length (
window / freqseconds). Default is 0.05 Hz (normogastric centre, 3 cpm).window (float, optional) – Window length in cycles of
freq. Default is 1.0.
- Returns:
cleaned – Movement-corrected signal. Same shape as input.
- Return type:
np.ndarray
Notes
The filter always subtracts the estimated noise component
x_hat, which contains the local meanE[y]. As a result the output is effectively mean-centered within each sliding window, and any DC offset in the original signal will be removed. A constant (zero-variance) signal maps to all zeros. This is the expected behaviour for EGG preprocessing, where a zero-mean signal is assumed, but should be noted when applying to signals with a meaningful baseline.References
Gharibans, A. A., Smarr, B., Kunkel, D. C., Kriegsfeld, L. J., Mousa, H., & Coleman, T. P. (2018). Artifact rejection methodology enables continuous, noninvasive measurement of gastric myoelectric activity in ambulatory subjects. Scientific Reports, 8, 5019. https://doi.org/10.1038/s41598-018-23302-9
Dalmaijer, E. S. (2025). electrography v1.1.1. esdalmaijer/electrography
Examples
>>> import numpy as np >>> from gastropy.signal import remove_movement_artifacts >>> t = np.arange(0, 300, 0.1) >>> sig = np.sin(2 * np.pi * 0.05 * t) >>> cleaned = remove_movement_artifacts(sig, sfreq=10.0) >>> cleaned.shape == sig.shape True