Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LFPViewer - fix mean+std calculation #616

Merged
merged 6 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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