RtAveragingWorker
Namespace: RTPROCESSINGLIB · Library: DSP Library
#include <dsp/rt_averaging.h>
class RTPROCESSINGLIB::RtAveragingWorker
Real-time averaging worker.
Background worker thread that accumulates and averages epochs in real time.
RtAveragingWorker averager(10, 20, 80, 0, 0, 2, info); // up to 10 epochs, 20 pre / 80 post samples, trigger row 2
FiffEvokedSet evokedSet;
QObject::connect(&averager, &RtAveragingWorker::resultReady,
[&](const FiffEvokedSet& set, const QStringList&) { evokedSet = set; });
for (const MatrixXd& block : blocks) {
averager.doWork(block); // runs synchronously; RtAveraging moves this worker to a thread
}
Inheritance
Public Methods
RtAveragingWorker(numAverages, iPreStimSamples, iPostStimSamples, iBaselineFromMSecs, iBaselineToMSecs, iTriggerIndex, pFiffInfo)
Creates the real-time averaging object.
Parameters:
-
numAverages : quint32 Number of evkos to average.
-
iPreStimSamples : quint32 Number of samples averaged before the stimulus.
-
iPostStimSamples : quint32 Number of samples averaged after the stimulus (including the stimulus).
-
iBaselineFromMSecs : qint32 Start of baseline area which was/is used for correction in msecs.
-
iBaselineToMSecs : qint32 End of baseline area which was/is used for correction in msecs.
-
iTriggerIndex : quint32 Row in dex of channel which is to be scanned for triggers.
-
pFiffInfo : FIFFLIB::FiffInfo::SPtr Associated Fiff Information.
doWork(matData)
Perform one averaging step on new incoming data.
Parameters:
- matData : const Eigen::MatrixXd & Data to average.
setAverageNumber(numAve)
Sets the number of averages.
Parameters:
- numAve : qint32 new number of averages.
setPreStim(samples, secs)
Sets the number of pre stimulus samples.
Parameters:
-
samples : qint32 new number of pre stimulus samples.
-
secs : qint32 new number of pre stimulus seconds.
setPostStim(samples, secs)
Sets the number of post stimulus samples.
Parameters:
-
samples : qint32 new number of post stimulus samples.
-
secs : qint32 new number of pre stimulus seconds.
setTriggerChIndx(idx)
Sets the index of the trigger channel which is to be scanned fo triggers.
Parameters:
- idx : qint32 trigger channel index.
setArtifactReduction(mapThresholds)
Sets the artifact reduction.
Parameters:
- mapThresholds : const QMap< QString, double > & The new map including the current thresholds for the channels.
setBaselineActive(activate)
Sets the baseline correction on or off.
Parameters:
- activate : bool activate baseline correction.
setBaselineFrom(fromSamp, fromMSec)
Sets the from mSeconds of the baseline area.
Parameters:
-
fromSamp : int from of baseline area in samples.
-
fromMSec : int from of baseline area in mSeconds.
setBaselineTo(toSamp, toMSec)
Sets the to mSeconds of the baseline area.
Parameters:
-
toSamp : int to of baseline area in samples.
-
toMSec : int to of baseline area in mSeconds.
reset()
Resets the averaged data stored.
Example
- Full source:
src/examples/ex_dsp_rt/main.cpp - Build target:
ex_dsp_rt(runs under CTest) - Data: mne-cpp-test-data
Used in examples
ex_dsp_rt
DSP real-time workers: averaging, covariance, noise spectrum, connectivity, HPI fitting and inverse operators.
RtAveragingWorker averager(10, 20, 80, 0, 0, 2, info); // up to 10 epochs, 20 pre / 80 post samples, trigger row 2
FiffEvokedSet evokedSet;
QObject::connect(&averager, &RtAveragingWorker::resultReady,
[&](const FiffEvokedSet& set, const QStringList&) { evokedSet = set; });
for (const MatrixXd& block : blocks) {
averager.doWork(block); // runs synchronously; RtAveraging moves this worker to a thread
}
// Average of k = 1..4 is 2.5 after the trigger and 0 before it; MEG0121 stays at -2
bool avgOk = evokedSet.evoked.size() == 1;
if (avgOk) {
const FiffEvoked& evoked = evokedSet.evoked.first();
avgOk = evoked.nave == nBlocks && evoked.data.cols() == 100 && evoked.comment == "1" && std::fabs(evoked.data(0, 30) - 2.5) < 1e-12 && std::fabs(evoked.data(0, 10)) < 1e-12 && std::fabs(evoked.data(1, 60) + 2.0) < 1e-12 && std::fabs(evoked.times(20)) < 1e-6;
}
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>