Skip to content

Commit

Permalink
Merge branch 'florian6973_fix-std' of https://github.com/florian6973/…
Browse files Browse the repository at this point in the history
…plugin-GUI into development
  • Loading branch information
anjaldoshi committed Jul 19, 2024
2 parents 7955c74 + daf7b81 commit f1577fa
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Plugins/LfpDisplayNode/LfpChannelDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion Plugins/LfpDisplayNode/LfpChannelDisplayInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
43 changes: 39 additions & 4 deletions Plugins/LfpDisplayNode/LfpDisplayCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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++;
}

Expand Down
7 changes: 5 additions & 2 deletions Plugins/LfpDisplayNode/LfpDisplayCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f1577fa

Please sign in to comment.