Skip to main content

Xdawn

Namespace: RTPROCESSINGLIB  ·  Library: DSP Library

Python equivalent

mne.preprocessing.Xdawn in MNE-Python.

#include <dsp/xdawn.h>

class UTILSLIB::Xdawn

Event-related response enhancement with xDAWN spatial filtering.

src/examples/ex_dsp_preprocessing/main.cpp
const XdawnResult xdawn = Xdawn::fit(epochs, 1, 1); // enhance the response to event code 1
const MatrixXd component = Xdawn::apply(epochs[0].epoch, xdawn);

Static Methods​

fit(epochs, iTargetEvent, nComponents, dReg)​

Fit xDAWN spatial filters for a target event code.

Uses non-rejected epochs only. The target signal covariance is estimated from the average of epochs whose MNEEpochData::event equals iTargetEvent. The noise covariance is estimated from residuals around the class-wise average for each event type.

Parameters:

  • epochs : const QVector< MNEEpochData > & Input epochs.

  • iTargetEvent : int Event code whose ERP/ERF should be enhanced.

  • nComponents : int Number of xDAWN components to retain.

  • dReg : double Relative diagonal regularisation added to the noise covariance.

Returns:


apply(matEpoch, result)​

Project one epoch into xDAWN component space.

Parameters:

  • matEpoch : const Eigen::MatrixXd & Epoch data (n_channels x n_samples).

  • result : const XdawnResult & Result from fit().

Returns:

  • Eigen::MatrixXd — Component activations (n_components x n_samples).

denoise(matEpoch, result, nComponents)​

Reconstruct one epoch from the first nComponents xDAWN components.

If nComponents <= 0 or exceeds the fitted dimensionality, all fitted components are used.

Parameters:

  • matEpoch : const Eigen::MatrixXd & Epoch data (n_channels x n_samples).

  • result : const XdawnResult & Result from fit().

  • nComponents : int Number of leading xDAWN components to keep.

Returns:

  • Eigen::MatrixXd — Denoised epoch (n_channels x n_samples).

denoiseEpochs(epochs, result, nComponents)​

Apply denoise() to all epochs in the vector, preserving metadata.

Parameters:

  • epochs : const QVector< MNEEpochData > & Input epochs.

  • result : const XdawnResult & Result from fit().

  • nComponents : int Number of leading xDAWN components to keep.

Returns:

  • QVector< MNEEpochData > — Copy of the input epochs with denoised epoch matrices.

Example​

Used in examples​

ex_dsp_preprocessing​

Preprocessing tools of the dsp library on synthetic data with a known ground truth.

src/examples/ex_dsp_preprocessing/main.cpp, line 186
const XdawnResult xdawn = Xdawn::fit(epochs, 1, 1); // enhance the response to event code 1
const MatrixXd component = Xdawn::apply(epochs[0].epoch, xdawn);
const VectorXd pattern = xdawn.matPatterns.col(0) / xdawn.matPatterns.col(0).cwiseAbs().maxCoeff();
ok &= expect(xdawn.bValid && component.rows() == 1 && std::fabs(std::fabs(pattern(1) / pattern(0)) - 0.5) < 0.1 && std::fabs(pattern(2)) < 0.15,
QString("xDAWN pattern ratio ch1/ch0 %1 (0.5), ch2 %2 (0)").arg(pattern(1) / pattern(0)).arg(pattern(2)));

Authors of this file​