Skip to main content

EogRegression

Namespace: RTPROCESSINGLIB  ·  Library: DSP Library

Python equivalent

mne.preprocessing.EOGRegression in MNE-Python.

#include <dsp/eog_regression.h>

class UTILSLIB::EogRegression

Remove EOG artifacts via linear regression.

As mne.preprocessing.EOGRegression: fits data_ch = beta * EOG + residual on time-demeaned signals for every good data channel and subtracts beta times the demeaned EOG.

src/examples/ex_dsp_artifacts/main.cpp
MatrixXd cleaned = data;
EogRegression regression;
regression.fit(cleaned, info); // EOG channels are found by kind
regression.apply(cleaned, info);

Public Methods​

EogRegression()​

Constructs a default EogRegression object.


fit(data, info, eogChannels)​

Fit regression coefficients from EOG to all other channels.

Ordinary least squares on demeaned signals: beta = T * E^T * (E * E^T)^{-1}, T being the good data channels (FiffInfoBase::pick_data_channels without the bads).

Parameters:

  • data : const Eigen::MatrixXd & Data matrix (n_channels x n_times).

  • info : const FiffInfo & Measurement info (identifies EOG channels by kind == FIFFV_EOG_CH).

  • eogChannels : const QStringList & Optional explicit EOG channel names. If empty, the good channels of kind FIFFV_EOG_CH.


apply(data, info)​

Apply the fitted regression to remove EOG artifacts in-place.

Subtracts beta times the demeaned EOG from the channels fit() regressed. fit() must be called first.

Parameters:

  • data : Eigen::MatrixXd & Data matrix (n_channels x n_times). Modified in-place.

  • info : const FiffInfo & Measurement info.


coefficients()​

Returns the fitted regression coefficients.

Returns:

  • const Eigen::MatrixXd & — Matrix (n_non_eog_channels x n_eog_channels).

isFitted()​

Returns true if fit() has been called successfully.

Returns:

  • bool — True if regression coefficients are available, false otherwise.

Static Methods​

fitApply(data, info, eogChannels)​

Convenience: fit and apply in one step.

Parameters:

  • data : Eigen::MatrixXd & Data matrix (n_channels x n_times). Modified in-place.

  • info : const FiffInfo & Measurement info.

  • eogChannels : const QStringList & Optional explicit EOG channel names.


Example​

Used in examples​

ex_dsp_artifacts​

Artifact detection and repair with the dsp library on a recording with planted defects.

src/examples/ex_dsp_artifacts/main.cpp, line 180
MatrixXd cleaned = data;
EogRegression regression;
regression.fit(cleaned, info); // EOG channels are found by kind
regression.apply(cleaned, info);
// Deflection around the second blink peak against the channel mean; averaging 21 samples keeps the noise small
const auto blinkDeflection = [](const RowVectorXd& row) {
return row.segment(1115, 21).mean() - row.mean();
};
const double beforeBlink = blinkDeflection(data.row(0));
const double afterBlink = blinkDeflection(cleaned.row(0));
ok &= expect(std::fabs(regression.coefficients()(0, 0) - 0.4) < 0.02 && std::fabs(afterBlink) < 0.1 * std::fabs(beforeBlink),
QString("EOG regression: beta %1 (0.4), blink on EEG0 %2 -> %3 V").arg(regression.coefficients()(0, 0)).arg(beforeBlink).arg(afterBlink));

Authors of this file​