diff --git a/Plugins/LfpDisplayNode/LfpChannelDisplay.cpp b/Plugins/LfpDisplayNode/LfpChannelDisplay.cpp index 532231a73..faf7313f0 100644 --- a/Plugins/LfpDisplayNode/LfpChannelDisplay.cpp +++ b/Plugins/LfpDisplayNode/LfpChannelDisplay.cpp @@ -243,7 +243,7 @@ void LfpChannelDisplay::pxPaint() double a = (canvasSplit->getYCoordMax(chan, index)/range*channelHeightFloat); double b = (canvasSplit->getYCoordMin(chan, index)/range*channelHeightFloat); - double mean = (canvasSplit->getMean(chan)/range*channelHeightFloat); + double mean = (canvasSplit->getScreenBufferMean(chan)/range*channelHeightFloat); if (drawWithOffsetCorrection) { @@ -508,7 +508,7 @@ void LfpChannelDisplay::pxPaintHistory(int playhead, int rightEdge, int maxScree double a = (canvasSplit->getYCoordMax(chan, index) / range * channelHeightFloat); double b = (canvasSplit->getYCoordMin(chan, index) / range * channelHeightFloat); - double mean = (canvasSplit->getMean(chan) / range * channelHeightFloat); + double mean = (canvasSplit->getScreenBufferMean(chan) / range * channelHeightFloat); if (drawWithOffsetCorrection) { diff --git a/Plugins/LfpDisplayNode/LfpChannelDisplayInfo.cpp b/Plugins/LfpDisplayNode/LfpChannelDisplayInfo.cpp index f65a08f92..e91af3586 100644 --- a/Plugins/LfpDisplayNode/LfpChannelDisplayInfo.cpp +++ b/Plugins/LfpDisplayNode/LfpChannelDisplayInfo.cpp @@ -247,7 +247,7 @@ void LfpChannelDisplayInfo::paint(Graphics& g) g.setColour(Colours::grey); g.drawText(String(canvasSplit->getStd(chan)), 5, center+110,41,10,Justification::centred,false); - g.drawText(String(canvasSplit->getMean(chan)), 5, center+60,41,10,Justification::centred,false); + g.drawText(String(canvasSplit->getDisplayBufferMean(chan)), 5, center+60,41,10,Justification::centred,false); if (x > 0) { diff --git a/Plugins/LfpDisplayNode/LfpDisplayCanvas.cpp b/Plugins/LfpDisplayNode/LfpDisplayCanvas.cpp index 18087a32e..5b5aa6c0b 100644 --- a/Plugins/LfpDisplayNode/LfpDisplayCanvas.cpp +++ b/Plugins/LfpDisplayNode/LfpDisplayCanvas.cpp @@ -1548,7 +1548,7 @@ uint16 LfpDisplaySplitter::getChannelStreamId(int channel) return processor->getContinuousChannel(channel)->getStreamId(); } -float LfpDisplaySplitter::getMean(int chan) +float LfpDisplaySplitter::getScreenBufferMean(int chan) { float total = 0.0f; float numPts = 0; @@ -1566,16 +1566,51 @@ float LfpDisplaySplitter::getMean(int chan) return total / numPts; } +float LfpDisplaySplitter::getDisplayBufferMean(int chan) +{ + float total = 0.0f; + float numPts = 0; + + float sample = 0.0f; + + // use 0.1s of sample to compute Mean and Std + float totalPoints = 0.1 * sampleRate; + + for (int samp = displayBufferIndex[chan] - totalPoints; samp < displayBufferIndex[chan]; samp += 1) + { + if (samp >= 0) // read the beginning of the buffer + sample = *displayBuffer->getReadPointer(chan, samp); + else // read the end of the buffer if negative index + sample = *displayBuffer->getReadPointer(chan, displayBuffer->getNumSamples() - samp); + + total += sample; + numPts++; + } + + //std::cout << sample << std::endl; + + return total / numPts; +} + float LfpDisplaySplitter::getStd(int chan) { float std = 0.0f; + float sample = 0.0f; - float mean = getMean(chan); + float mean = getDisplayBufferMean(chan); float numPts = 1; - for (int samp = 0; samp < (lfpDisplay->getWidth() - leftmargin); samp += 10) + // use 0.1s of sample to compute Mean and Std + float totalPoints = 0.1 * sampleRate; + + for (int samp = displayBufferIndex[chan] - totalPoints; samp < displayBufferIndex[chan]; samp += 1) { - std += pow((*screenBufferMean->getReadPointer(chan, samp) - mean),2); + if (samp >= 0) // read the beginning of the buffer + sample = *displayBuffer->getReadPointer(chan, samp); + else // read the end of the buffer if negative index + sample = *displayBuffer->getReadPointer(chan, displayBuffer->getNumSamples() - samp); + + std += pow((sample - mean),2); numPts++; } diff --git a/Plugins/LfpDisplayNode/LfpDisplayCanvas.h b/Plugins/LfpDisplayNode/LfpDisplayCanvas.h index 884a81edc..83d3b76e0 100644 --- a/Plugins/LfpDisplayNode/LfpDisplayCanvas.h +++ b/Plugins/LfpDisplayNode/LfpDisplayCanvas.h @@ -263,8 +263,11 @@ class LfpDisplaySplitter : public Component, /** Gets the event channel state for a particular sample */ const float getEventState(int samp); - /** Returns the mean of a given channel */ - float getMean(int chan); + /** Returns the mean of a given channel, computed from the screen buffer */ + float getScreenBufferMean(int chan); + + /** Returns the mean of a given channel, computed from the display buffer */ + float getDisplayBufferMean(int chan); /** Returns the standard deviation of a given channnel*/ float getStd(int chan);