@@ -1557,14 +1557,16 @@ float LfpDisplaySplitter::getMean(int chan)
15571557
15581558 // use 0.1s of sample to compute Mean and Std
15591559 float totalPoints = 0.1 * sampleRate;
1560-
1561- // avoid crash if no signal
1562- if ((displayBufferIndex[chan] - totalPoints) <= 0 )
1563- return 0 ;
15641560
15651561 for (int samp = displayBufferIndex[chan] - totalPoints; samp < displayBufferIndex[chan]; samp += 1 )
15661562 {
1567- sample = *displayBuffer->getReadPointer (chan, samp);
1563+ float sample = 0 ;
1564+
1565+ if (samp >= 0 ) // read the beginning of the buffer
1566+ sample = *displayBuffer->getReadPointer (chan, samp);
1567+ else // read the end of the buffer if negative index
1568+ sample = *displayBuffer->getReadPointer (chan, displayBuffer->getNumSamples () - samp);
1569+
15681570 total += sample;
15691571 numPts++;
15701572 }
@@ -1586,14 +1588,14 @@ float LfpDisplaySplitter::getStd(int chan)
15861588
15871589 for (int samp = displayBufferIndex[chan] - totalPoints; samp < displayBufferIndex[chan]; samp += 1 )
15881590 {
1589- float value = 0 ;
1591+ float sample = 0 ;
15901592
15911593 if (samp >= 0 ) // read the beginning of the buffer
1592- value = *displayBuffer->getReadPointer (chan, samp);
1594+ sample = *displayBuffer->getReadPointer (chan, samp);
15931595 else // read the end of the buffer if negative index
1594- value = *displayBuffer->getReadPointer (chan, displayBuffer->getNumSamples () - samp);
1596+ sample = *displayBuffer->getReadPointer (chan, displayBuffer->getNumSamples () - samp);
15951597
1596- std += pow ((value - mean),2 );
1598+ std += pow ((sample - mean),2 );
15971599 numPts++;
15981600 }
15991601 LOGD (" \t Returning " , sqrt (std / numPts));
0 commit comments