50void EpochExtractor::applyBaseline(MatrixXd& matEpoch,
int iBase0,
int iBase1)
52 if (iBase0 > iBase1 || iBase0 < 0 || iBase1 >= matEpoch.cols())
return;
53 const int nBaseSamp = iBase1 - iBase0 + 1;
55 VectorXd baseline = matEpoch.block(0, iBase0, matEpoch.rows(), nBaseSamp).rowwise().mean();
56 matEpoch.colwise() -= baseline;
64 const QVector<int>& eventSamples,
67 const QVector<int>& eventCodes)
69 QVector<MNEEpochData> epochs;
71 if (matData.size() == 0 || eventSamples.isEmpty())
return epochs;
73 qWarning() <<
"EpochExtractor::extract: invalid sampling frequency.";
77 const int nSamp =
static_cast<int>(matData.cols());
78 const int nCh =
static_cast<int>(matData.rows());
81 const int iOffset0 =
static_cast<int>(std::round(params.
dTmin * dSFreq));
82 const int iOffset1 =
static_cast<int>(std::round(params.
dTmax * dSFreq));
83 const int epochLen = iOffset1 - iOffset0 + 1;
86 qWarning() <<
"EpochExtractor::extract: tmax must be > tmin.";
91 const int iBase0 =
static_cast<int>(std::round((params.
dBaseMin - params.
dTmin) * dSFreq));
92 const int iBase1 =
static_cast<int>(std::round((params.
dBaseMax - params.
dTmin) * dSFreq));
94 const bool bHaveCodes = (eventCodes.size() == eventSamples.size());
96 for (
int ev = 0; ev < eventSamples.size(); ++ev) {
97 const int evSamp = eventSamples[ev];
98 const int s0 = evSamp + iOffset0;
99 const int s1 = evSamp + iOffset1;
102 if (s0 < 0 || s1 >= nSamp)
continue;
105 epoch.
epoch = matData.block(0, s0, nCh, epochLen);
106 epoch.
tmin =
static_cast<float>(params.
dTmin);
107 epoch.
tmax =
static_cast<float>(params.
dTmax);
108 epoch.
event = bHaveCodes ? eventCodes[ev] : 1;
113 applyBaseline(epoch.
epoch, iBase0, iBase1);
118 for (
int ch = 0; ch < nCh; ++ch) {
119 const RowVectorXd row = epoch.
epoch.row(ch);
120 double ptp = row.maxCoeff() - row.minCoeff();
128 epochs.append(epoch);
142 if (ep.bReject)
continue;
143 if (result.size() == 0) {
146 if (ep.epoch.rows() != result.rows() || ep.epoch.cols() != result.cols()) {
147 qWarning() <<
"EpochExtractor::average: epoch dimension mismatch, skipping.";
155 if (nGood > 1) result /=
static_cast<double>(nGood);
163 QVector<MNEEpochData> good;
164 good.reserve(epochs.size());
166 if (!ep.bReject) good.append(ep);
Declaration of EpochExtractor — segments continuous MEG/EEG data into trials.
Core MNE data structures (source spaces, source estimates, hemispheres).
Shared utilities (I/O helpers, spectral analysis, layout management, warp algorithms).
static QVector< MNELIB::MNEEpochData > rejectMarked(const QVector< MNELIB::MNEEpochData > &epochs)
static QVector< MNELIB::MNEEpochData > extract(const Eigen::MatrixXd &matData, const QVector< int > &eventSamples, double dSFreq, const Params ¶ms=Params(), const QVector< int > &eventCodes=QVector< int >())
EpochExtractorParams Params
static Eigen::MatrixXd average(const QVector< MNELIB::MNEEpochData > &epochs)
Single epoch (trial slice) of sensor data with timing and rejection metadata.
FIFFLIB::fiff_int_t event