71void EpochExtractor::applyBaseline(MatrixXd& matEpoch,
int iBase0,
int iBase1)
73 if (iBase0 > iBase1 || iBase0 < 0 || iBase1 >= matEpoch.cols())
return;
74 const int nBaseSamp = iBase1 - iBase0 + 1;
76 VectorXd baseline = matEpoch.block(0, iBase0, matEpoch.rows(), nBaseSamp).rowwise().mean();
77 matEpoch.colwise() -= baseline;
85 const QVector<int>& eventSamples,
88 const QVector<int>& eventCodes)
90 QVector<MNEEpochData> epochs;
92 if (matData.size() == 0 || eventSamples.isEmpty())
return epochs;
94 qWarning() <<
"EpochExtractor::extract: invalid sampling frequency.";
98 const int nSamp =
static_cast<int>(matData.cols());
99 const int nCh =
static_cast<int>(matData.rows());
102 const int iOffset0 =
static_cast<int>(std::round(params.
dTmin * dSFreq));
103 const int iOffset1 =
static_cast<int>(std::round(params.
dTmax * dSFreq));
104 const int epochLen = iOffset1 - iOffset0 + 1;
107 qWarning() <<
"EpochExtractor::extract: tmax must be > tmin.";
112 const int iBase0 =
static_cast<int>(std::round((params.
dBaseMin - params.
dTmin) * dSFreq));
113 const int iBase1 =
static_cast<int>(std::round((params.
dBaseMax - params.
dTmin) * dSFreq));
115 const bool bHaveCodes = (eventCodes.size() == eventSamples.size());
117 for (
int ev = 0; ev < eventSamples.size(); ++ev) {
118 const int evSamp = eventSamples[ev];
119 const int s0 = evSamp + iOffset0;
120 const int s1 = evSamp + iOffset1;
123 if (s0 < 0 || s1 >= nSamp)
continue;
126 epoch.
epoch = matData.block(0, s0, nCh, epochLen);
127 epoch.
tmin =
static_cast<float>(params.
dTmin);
128 epoch.
tmax =
static_cast<float>(params.
dTmax);
129 epoch.
event = bHaveCodes ? eventCodes[ev] : 1;
134 applyBaseline(epoch.
epoch, iBase0, iBase1);
139 for (
int ch = 0; ch < nCh; ++ch) {
140 const RowVectorXd row = epoch.
epoch.row(ch);
141 double ptp = row.maxCoeff() - row.minCoeff();
149 epochs.append(epoch);
163 if (ep.bReject)
continue;
164 if (result.size() == 0) {
167 if (ep.epoch.rows() != result.rows() || ep.epoch.cols() != result.cols()) {
168 qWarning() <<
"EpochExtractor::average: epoch dimension mismatch, skipping.";
176 if (nGood > 1) result /=
static_cast<double>(nGood);
184 QVector<MNEEpochData> good;
185 good.reserve(epochs.size());
187 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)
FIFFLIB::fiff_int_t event