Skip to main content

ChannelDerivation

Namespace: UTILSLIB  ·  Library: Utilities Library

#include <utils/channel_derivation.h>

class UTILSLIB::ChannelDerivation

Channel derivation and re-referencing utilities.

Provides methods to build bipolar and common-average re-referencing schemes, apply arbitrary linear derivation rules to data matrices, and read/write derivation definition files.

src/examples/ex_dsp_preprocessing/main.cpp
const QStringList names = {"LH1", "LH2", "LH3", "RA1"};
const QVector<DerivationRule> bipolar = ChannelDerivation::buildBipolar(names); // LH1-LH2, LH2-LH3
const QVector<DerivationRule> average = ChannelDerivation::buildCommonAverage(names);
const auto [bipolarData, bipolarNames] = ChannelDerivation::apply(raw, names, bipolar);
const auto [averageData, averageNames] = ChannelDerivation::apply(raw, names, average);

Static Methods​

buildBipolar(channelNames)​

Build bipolar derivation rules from sequential electrode pairs.

Channels are grouped by shaft prefix (all leading alphabetic characters and apostrophes before the first digit). Within each group, consecutive pairs are subtracted: channel[i] − channel[i+1].

Parameters:

  • channelNames : const QStringList & List of channel names, e.g. {"LH1","LH2","LH3","RA1","RA2"}.

Returns:


buildCommonAverage(channelNames)​

Build common-average reference derivation rules.

Each output channel equals the original channel minus the mean of all channels: out_i = ch_i − (1/N) Σ ch_j.

Parameters:

  • channelNames : const QStringList & List of channel names.

Returns:


apply(matData, channelNames, rules)​

Apply derivation rules to a data matrix.

Parameters:

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

  • channelNames : const QStringList & Channel names corresponding to rows of matData.

  • rules : const QVector< DerivationRule > & Derivation rules to apply.

Returns:

  • QPair< Eigen::MatrixXd, QStringList > — A pair of (derived data matrix, derived channel names). The output matrix has n_rules rows × n_times columns.

readDefinitionFile(path)​

Read derivation rules from an MNE-C derivation text file (MNELIB::MNEDerivSet::readText).

# comment
"LH1-LH2" = "LH1" - "LH2"
"C3-avg" = 0.75 * "C3" - 0.25 * "C4" - 0.25 * "Cz" - 0.25 * "Pz"

Parameters:

  • path : const QString & Path to the definition file.

Returns:


writeDefinitionFile(path, rules)​

Write derivation rules in MNE-C derivation text syntax, readable by readDefinitionFile and mne_make_derivations.

Parameters:

  • path : const QString & Path to the output file.

  • rules : const QVector< DerivationRule > & Derivation rules to write.

Returns:

  • bool — True if the file was written successfully.

Example​

Authors of this file​