File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1554,9 +1554,17 @@ float LfpDisplaySplitter::getMean(int chan)
15541554 float numPts = 0 ;
15551555
15561556 float sample = 0 .0f ;
1557- for (int samp = 0 ; samp < (lfpDisplay->getWidth () - leftmargin); samp += 10 )
1557+
1558+ // use 0.1s of sample to compute Mean and Std
1559+ float totalPoints = 0.1 * sampleRate;
1560+
1561+ // avoid crash if no signal
1562+ if ((displayBufferIndex[chan] - totalPoints) <= 0 )
1563+ return 0 ;
1564+
1565+ for (int samp = displayBufferIndex[chan] - totalPoints; samp < displayBufferIndex[chan]; samp += 1 )
15581566 {
1559- sample = *screenBufferMean ->getReadPointer (chan, samp);
1567+ sample = *displayBuffer ->getReadPointer (chan, samp);
15601568 total += sample;
15611569 numPts++;
15621570 }
@@ -1573,9 +1581,16 @@ float LfpDisplaySplitter::getStd(int chan)
15731581 float mean = getMean (chan);
15741582 float numPts = 1 ;
15751583
1576- for (int samp = 0 ; samp < (lfpDisplay->getWidth () - leftmargin); samp += 10 )
1584+ // use 0.1s of sample to compute Mean and Std
1585+ float totalPoints = 0.1 * sampleRate;
1586+
1587+ // avoid crash if no signal
1588+ if ((displayBufferIndex[chan] - totalPoints) <= 0 )
1589+ return 0 ;
1590+
1591+ for (int samp = displayBufferIndex[chan] - totalPoints; samp < displayBufferIndex[chan]; samp += 1 )
15771592 {
1578- std += pow ((*screenBufferMean ->getReadPointer (chan, samp) - mean),2 );
1593+ std += pow ((*displayBuffer ->getReadPointer (chan, samp) - mean),2 );
15791594 numPts++;
15801595 }
15811596
You can’t perform that action at this time.
0 commit comments