StimArtifact
Namespace: RTPROCESSINGLIB · Library: DSP Library
This page documents a header-level module — a collection of free functions that share an algorithmic topic. There is no enclosing C++ class; the functions live directly in the library namespace.
mne.preprocessing.fix_stim_artifact in MNE-Python.
#include <dsp/stim_artifact.h>
SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2026 MNE-CPP Authors.
Repairs stimulus artifacts in continuous data by replacing samples in a window around each stimulus event with either linearly interpolated values (from the window boundaries) or zeros. This mirrors the functionality of MNE-Python's mne.preprocessing.fix_stim_artifact().
MatrixXd stim = data;
MatrixXi events(2, 3);
events << 500, 0, 1, 1500, 0, 1;
for (int r = 0; r < events.rows(); ++r) {
stim.block(0, events(r, 0), kEeg, 2).array() += 1e-3; // 8 ms stimulus artefact
}
fixStimArtifact(stim, events, kSFreq, 1, -0.004, 0.008); // interpolate between the clean samples at -4 and +8 ms
Functions
fixStimArtifact(data, events, sfreq, eventId, tmin, tmax, mode)
void fixStimArtifact(Eigen::MatrixXd & data, const Eigen::MatrixXi & events, double sfreq, int eventId, double tmin, double tmax, StimArtifactMode mode);
Repair stimulus artifacts by interpolating or zeroing data around events.
For each event sample, the data in the window [event + tmin_samples, event + tmax_samples] is either linearly interpolated from the boundary values or set to zero.
Parameters:
-
data : Eigen::MatrixXd & Data matrix (n_channels x n_times). Modified in-place.
-
events : const Eigen::MatrixXi & Event matrix (Nx3: [sample, before, after]). Only the sample column (col 0) is used to locate artifact windows.
-
sfreq : double Sampling frequency in Hz.
-
eventId : int If >= 0, only process events where column 2 (after) matches this value. If < 0, process all events. Default: -1.
-
tmin : double Start of artifact window in seconds relative to event (negative = before event). Default: 0.0 (event onset).
-
tmax : double End of artifact window in seconds relative to event. Default: 0.01 (10 ms after event).
-
mode : StimArtifactMode Repair mode (Linear interpolation or zero-padding). Default:
StimArtifactMode::Linear.
Example
- Full source:
src/examples/ex_dsp_artifacts/main.cpp - Build target:
ex_dsp_artifacts(runs under CTest)
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>