Skip to main content

AnnotateArtifact

Namespace: RTPROCESSINGLIB  ·  Library: DSP Library

Module

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.

Python equivalent

mne.preprocessing.annotate_muscle_zscore / annotate_amplitude in MNE-Python.

#include <dsp/annotate_artifact.h>

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2026 MNE-CPP Authors.

The detectors in this header scan continuous MEG / EEG data and emit FIFFLIB::FiffAnnotation intervals marking time segments that should be excluded from downstream averaging, ICA fitting or PSD estimation. annotateMuscleZscore band-pass filters the signal in the 110–140 Hz range (typical EMG band), takes the smoothed envelope across channels and z-scores it against the global median absolute deviation; samples whose z-score exceeds a user threshold are merged into BAD_muscle annotations. annotateAmplitude flags two boundary conditions instead: per-channel peak-to-peak amplitude exceeding an upper limit ("high-amplitude" artefact) and amplitude falling below a lower limit for longer than a minimum duration ("flat" / dead channel).

Both routines mirror the semantics of their MNE-Python counterparts mne.preprocessing.annotate_muscle_zscore and mne.preprocessing.annotate_amplitude so cross-toolchain pipelines produce identical bad-segment lists.


Functions

annotateMusclZscore(data, info, sfreq, params)

[FiffAnnotations](/docs/api/fiff/fiff-annotations) annotateMusclZscore(const Eigen::MatrixXd & data, const [FiffInfo](/docs/api/fiff/fiff-info) & info, double sfreq, const AnnotateMusclParams & params);

Detect muscle artifacts via high-frequency z-score and annotate bad segments.

Algorithm: Bandpass filter data in muscle frequency band (default 110–140 Hz).

Compute Hilbert envelope (approximated via absolute value of filtered signal).

Compute z-score of the envelope across time for each MEG channel.

Average z-score across channels.

Threshold: mark time points where average z-score > threshold.

Merge adjacent annotations and apply minimum duration.

Parameters:

  • data : const Eigen::MatrixXd & Raw data matrix (n_channels × n_times).

  • info : const FiffInfo & Measurement info.

  • sfreq : double Sampling frequency in Hz.

  • params : const AnnotateMusclParams & Detection parameters.

Returns:


annotateAmplitude(data, info, sfreq, params)

[FiffAnnotations](/docs/api/fiff/fiff-annotations) annotateAmplitude(const Eigen::MatrixXd & data, const [FiffInfo](/docs/api/fiff/fiff-info) & info, double sfreq, const AnnotateAmplitudeParams & params);

Annotate segments where amplitude exceeds thresholds or is too flat.

Scans each channel independently: If any sample exceeds dPeakMax or falls below dPeakMin, that time point is annotated.

If peak-to-peak amplitude in a sliding window < dFlatMin, the window is annotated as "BAD_flat".

Parameters:

  • data : const Eigen::MatrixXd & Raw data matrix (n_channels × n_times).

  • info : const FiffInfo & Measurement info (for channel names).

  • sfreq : double Sampling frequency in Hz.

  • params : const AnnotateAmplitudeParams & Detection parameters.

Returns:


Authors of this file