EegReference
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.set_eeg_reference in MNE-Python.
#include <dsp/eeg_reference.h>
SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2026 MNE-CPP Authors.
Every EEG measurement is implicitly a potential difference between an active electrode and a reference; changing that reference is therefore a linear operation on the data matrix. The functions in this header build and apply the most widely used reference operators: subtraction of a single electrode (or the average of a few), the common-average reference (CAR), and — where a forward model is supplied — the reference electrode standardisation technique (REST) which projects the data to the equivalent reference at infinity.
Re-referencing is implemented as a single matrix multiplication so that channel covariances and inverse operators remain valid after re- referencing, provided the same operator is also applied to the noise covariance.
MatrixXd averageRef = data;
setEegReference(averageRef, info); // average of the EEG channels; EOG/ECG rows untouched
Functions
setEegReference(data, info, refChannels, projection)
void setEegReference(Eigen::MatrixXd & data, [FiffInfo](/docs/api/fiff/fiff-info) & info, const QStringList & refChannels, bool projection);
Re-reference EEG channels to average, specific channel(s), or REST.
Only modifies rows of good EEG channels (kind == FIFFV_EEG_CH, not in info.bads), as mne.set_eeg_reference does. Bad and non-EEG channels are left untouched.
Parameters:
-
data : Eigen::MatrixXd & Data matrix (n_channels x n_times). Modified in-place.
-
info : FiffInfo & Measurement info (identifies EEG channels; receives the projector).
-
refChannels : const QStringList & Reference channel name(s). - Empty or "average" -> average reference (mean of all good EEG channels). - Single channel name -> re-reference to that channel. - Multiple channel names -> re-reference to mean of those channels.
-
projection : bool Average reference only: append an inactive average-reference projector over the good EEG channels to info.projs (mne make_eeg_average_ref_proj) and leave the data unchanged. Nothing is added if one is already present.
addReferenceChannels(data, info, chNames)
void addReferenceChannels(Eigen::MatrixXd & data, [FiffInfo](/docs/api/fiff/fiff-info) & info, const QStringList & chNames);
Add reference channel(s) back as zero-filled rows.
When EEG data was recorded with a physical reference electrode, that channel is implicit (all zeros after re-referencing). This function adds it back explicitly so it can participate in average re-referencing or source localization.
Parameters:
-
data : Eigen::MatrixXd & Data matrix. Rows are added at the end.
-
info : FiffInfo & Measurement info. New EEG channels are appended.
-
chNames : const QStringList & Names of the reference channel(s) to add.
setBipolarReference(data, info, anodes, cathodes, dropOriginals)
void setBipolarReference(Eigen::MatrixXd & data, [FiffInfo](/docs/api/fiff/fiff-info) & info, const QStringList & anodes, const QStringList & cathodes, bool dropOriginals);
Create bipolar derivations from EEG channels.
Creates new bipolar channels by subtracting cathode from anode for each pair. The original channels are replaced with the bipolar derivations.
Parameters:
-
data : Eigen::MatrixXd & Data matrix. Replaced with bipolar derivation rows.
-
info : FiffInfo & Measurement info. Updated with new bipolar channel info.
-
anodes : const QStringList & List of anode channel names.
-
cathodes : const QStringList & List of cathode channel names (same length as anodes).
-
dropOriginals : bool If true, remove the original anode/cathode channels from the output (default: true).
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>