@@ -87,7 +87,7 @@ constexpr const int defaultFittingWindowSize(300);
87
87
88
88
Hpi::Hpi ()
89
89
: m_iNumberBadChannels(0 )
90
- , m_iRepetitionWindowSize (defaultFittingWindowSize)
90
+ , m_iRepetitionTimeInSamples (defaultFittingWindowSize)
91
91
, m_dAllowedMeanErrorDist(10 )
92
92
, m_dAllowedMovement(3 )
93
93
, m_dAllowedRotation(5 )
@@ -524,7 +524,7 @@ void Hpi::onContHpiStatusChanged(bool bChecked)
524
524
void Hpi::setFittingWindowSize (double dRepetitionTime)
525
525
{
526
526
QMutexLocker locker (&m_mutex);
527
- m_iRepetitionWindowSize = dRepetitionTime * m_pFiffInfo->sfreq ;
527
+ m_iRepetitionTimeInSamples = dRepetitionTime * m_pFiffInfo->sfreq ;
528
528
}
529
529
530
530
// =============================================================================================================
@@ -554,7 +554,7 @@ int Hpi::computeMinimalWindowsize()
554
554
}
555
555
556
556
// sort vector in increasing order
557
- std::sort (vecFreqs.constBegin (), vecFreqs.constEnd ());
557
+ std::sort (vecFreqs.begin (), vecFreqs.end ());
558
558
559
559
// get minimimal required frequency difference
560
560
int iMinDeltaF = dSFreq;
@@ -613,38 +613,55 @@ void Hpi::run()
613
613
double dMovement = 0.0 ;
614
614
double dRotation = 0.0 ;
615
615
616
+ int iRepetitionIndexCounter = 0 ;
616
617
int iDataIndexCounter = 0 ;
617
618
MatrixXd matData;
618
619
619
620
m_mutex.lock ();
620
- int fittingWindowSize = m_iRepetitionWindowSize;
621
+ int iFittingWindowSize = m_iFittingWindowSize;
622
+ int iRepetitionTimeInSamples = m_iRepetitionTimeInSamples;
623
+
621
624
m_mutex.unlock ();
622
625
623
- MatrixXd matDataMerged (m_pFiffInfo->chs .size (), fittingWindowSize );
626
+ MatrixXd matDataMerged (m_pFiffInfo->chs .size (), iFittingWindowSize );
624
627
bool bOrder = false ;
625
628
QElapsedTimer timer;
626
629
timer.start ();
627
630
628
631
while (!isInterruptionRequested ()) {
629
632
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 ;
635
646
}
636
647
m_mutex.unlock ();
648
+
637
649
// pop matrix
638
650
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) {
640
656
matDataMerged.block (0 , iDataIndexCounter, matData.rows (), matData.cols ()) = matData;
641
657
iDataIndexCounter += matData.cols ();
642
- qDebug () << " Data im counter:" << iDataIndexCounter;
658
+ qDebug () << " Samples im data counter:" << iDataIndexCounter << " From: " << iFittingWindowSize ;
643
659
644
660
} else {
645
661
qDebug () << " Time elapsed:" << timer.restart ();
646
662
qDebug () << " matDataMerged samples:" << matDataMerged.cols ();
647
- qDebug () << " fittingWindowSize:" << fittingWindowSize;
663
+ qDebug () << " fittingWindowSize:" << iFittingWindowSize;
664
+ qDebug () << " repetition time in samples:" << iRepetitionTimeInSamples;
648
665
649
666
m_mutex.lock ();
650
667
if (m_bDoSingleHpi) {
@@ -720,6 +737,7 @@ void Hpi::run()
720
737
}
721
738
}
722
739
740
+ iRepetitionIndexCounter = 0 ;
723
741
iDataIndexCounter = 0 ;
724
742
}
725
743
}
0 commit comments