Skip to content

Commit de0f949

Browse files
committed
enh: implement variable fitting window size as well
1 parent 6eb150a commit de0f949

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

applications/mne_scan/plugins/hpi/hpi.cpp

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ constexpr const int defaultFittingWindowSize(300);
8787

8888
Hpi::Hpi()
8989
: m_iNumberBadChannels(0)
90-
, m_iRepetitionWindowSize(defaultFittingWindowSize)
90+
, m_iRepetitionTimeInSamples(defaultFittingWindowSize)
9191
, m_dAllowedMeanErrorDist(10)
9292
, m_dAllowedMovement(3)
9393
, m_dAllowedRotation(5)
@@ -524,7 +524,7 @@ void Hpi::onContHpiStatusChanged(bool bChecked)
524524
void Hpi::setFittingWindowSize(double dRepetitionTime)
525525
{
526526
QMutexLocker locker(&m_mutex);
527-
m_iRepetitionWindowSize = dRepetitionTime * m_pFiffInfo->sfreq;
527+
m_iRepetitionTimeInSamples = dRepetitionTime * m_pFiffInfo->sfreq;
528528
}
529529

530530
//=============================================================================================================
@@ -554,7 +554,7 @@ int Hpi::computeMinimalWindowsize()
554554
}
555555

556556
// sort vector in increasing order
557-
std::sort(vecFreqs.constBegin(), vecFreqs.constEnd());
557+
std::sort(vecFreqs.begin(), vecFreqs.end());
558558

559559
// get minimimal required frequency difference
560560
int iMinDeltaF = dSFreq;
@@ -613,38 +613,55 @@ void Hpi::run()
613613
double dMovement = 0.0;
614614
double dRotation = 0.0;
615615

616+
int iRepetitionIndexCounter = 0;
616617
int iDataIndexCounter = 0;
617618
MatrixXd matData;
618619

619620
m_mutex.lock();
620-
int fittingWindowSize = m_iRepetitionWindowSize;
621+
int iFittingWindowSize = m_iFittingWindowSize;
622+
int iRepetitionTimeInSamples = m_iRepetitionTimeInSamples;
623+
621624
m_mutex.unlock();
622625

623-
MatrixXd matDataMerged(m_pFiffInfo->chs.size(), fittingWindowSize);
626+
MatrixXd matDataMerged(m_pFiffInfo->chs.size(), iFittingWindowSize);
624627
bool bOrder = false;
625628
QElapsedTimer timer;
626629
timer.start();
627630

628631
while(!isInterruptionRequested()) {
629632
m_mutex.lock();
630-
if(fittingWindowSize != m_iRepetitionWindowSize) {
631-
fittingWindowSize = m_iRepetitionWindowSize;
632-
std::cout << "Fitting window size: " << fittingWindowSize << "\n";
633-
matDataMerged.resize(m_pFiffInfo->chs.size(), fittingWindowSize);
634-
iDataIndexCounter = 0;
633+
// check if fitting window size has changed and resize matData if necessary
634+
if(iFittingWindowSize != m_iFittingWindowSize) {
635+
iFittingWindowSize = m_iFittingWindowSize;
636+
std::cout << "Fitting window size: " << iFittingWindowSize << "\n";
637+
matDataMerged.resize(m_pFiffInfo->chs.size(), iFittingWindowSize);
638+
iRepetitionIndexCounter = 0;
639+
}
640+
641+
// check if time between fits has changed
642+
if(iRepetitionTimeInSamples != m_iRepetitionTimeInSamples) {
643+
iRepetitionTimeInSamples = m_iRepetitionTimeInSamples;
644+
std::cout << "Repetition time in samples: " << iRepetitionTimeInSamples << "\n";
645+
iRepetitionIndexCounter = 0;
635646
}
636647
m_mutex.unlock();
648+
637649
//pop matrix
638650
if(m_pCircularBuffer->pop(matData)) {
639-
if(iDataIndexCounter + matData.cols() < matDataMerged.cols()) {
651+
if(iRepetitionIndexCounter + matData.cols() < iRepetitionTimeInSamples) {
652+
iRepetitionIndexCounter += matData.cols();
653+
qDebug() << "Samples im repetition counter:" << iRepetitionIndexCounter << "From: " << iRepetitionTimeInSamples;
654+
655+
} else if(iDataIndexCounter + matData.cols() < iFittingWindowSize) {
640656
matDataMerged.block(0, iDataIndexCounter, matData.rows(), matData.cols()) = matData;
641657
iDataIndexCounter += matData.cols();
642-
qDebug() << "Data im counter:" << iDataIndexCounter;
658+
qDebug() << "Samples im data counter:" << iDataIndexCounter << "From: " << iFittingWindowSize;
643659

644660
} else {
645661
qDebug() << "Time elapsed:" << timer.restart();
646662
qDebug() << "matDataMerged samples:" << matDataMerged.cols();
647-
qDebug() << "fittingWindowSize:" << fittingWindowSize;
663+
qDebug() << "fittingWindowSize:" << iFittingWindowSize;
664+
qDebug() << "repetition time in samples:" << iRepetitionTimeInSamples;
648665

649666
m_mutex.lock();
650667
if(m_bDoSingleHpi) {
@@ -720,6 +737,7 @@ void Hpi::run()
720737
}
721738
}
722739

740+
iRepetitionIndexCounter = 0;
723741
iDataIndexCounter = 0;
724742
}
725743
}

applications/mne_scan/plugins/hpi/hpi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ class HPISHARED_EXPORT Hpi : public SCSHAREDLIB::AbstractAlgorithm
298298
*
299299
* @return optimal Windowsize
300300
*/
301-
int computeOptimalWindowsize();
301+
int computeMinimalWindowsize();
302302

303303

304304

@@ -311,7 +311,7 @@ class HPISHARED_EXPORT Hpi : public SCSHAREDLIB::AbstractAlgorithm
311311
QString m_sFilePathDigitzers; /**< The file path to the current digitzers. */
312312

313313
qint16 m_iNumberBadChannels; /**< The number of bad channels.*/
314-
qint16 m_iRepetitionWindowSize; /**< The number of samples to wait between fits.*/
314+
qint16 m_iRepetitionTimeInSamples; /**< The number of samples to wait between fits.*/
315315
int m_iFittingWindowSize; /**< The number of samples in each fitting window.*/
316316
double m_dAllowedMeanErrorDist; /**< The allowed error distance in order for the last fit to be counted as a good fit.*/
317317
double m_dAllowedMovement; /**< The allowed head movement regarding reference head position.*/

0 commit comments

Comments
 (0)