Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 562e174ec31f
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 929fa824f1cc
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Oct 11, 2020

  1. Copy the full SHA
    929fa82 View commit details
Showing with 46 additions and 14 deletions.
  1. +39 −14 scopeprotocols/MovingAverageFilter.cpp
  2. +7 −0 scopeprotocols/MovingAverageFilter.h
53 changes: 39 additions & 14 deletions scopeprotocols/MovingAverageFilter.cpp
Original file line number Diff line number Diff line change
@@ -43,6 +43,11 @@ MovingAverageFilter::MovingAverageFilter(string color)
m_depthname = "Depth";
m_parameters[m_depthname] = FilterParameter(FilterParameter::TYPE_INT, Unit(Unit::UNIT_SAMPLEDEPTH));
m_parameters[m_depthname].SetFloatVal(0);

m_range = 1;
m_offset = 0;
m_min = FLT_MAX;
m_max = -FLT_MAX;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -64,12 +69,12 @@ bool MovingAverageFilter::ValidateChannel(size_t i, StreamDescriptor stream)

double MovingAverageFilter::GetVoltageRange()
{
return m_inputs[0].m_channel->GetVoltageRange();
return m_range;
}

double MovingAverageFilter::GetOffset()
{
return m_inputs[0].m_channel->GetOffset();
return m_offset;
}

string MovingAverageFilter::GetProtocolName()
@@ -102,6 +107,14 @@ void MovingAverageFilter::SetDefaultName()
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Actual decoder logic

void MovingAverageFilter::ClearSweeps()
{
m_range = 1;
m_offset = 0;
m_min = FLT_MAX;
m_max = -FLT_MAX;
}

void MovingAverageFilter::Refresh()
{
if(!VerifyAllInputsOKAndAnalog())
@@ -114,33 +127,45 @@ void MovingAverageFilter::Refresh()
auto din = GetAnalogInputWaveform(0);
size_t len = din->m_samples.size();
size_t depth = m_parameters[m_depthname].GetIntVal();
if(len < depth)
{
SetData(NULL, 0);
return;
}

m_xAxisUnit = m_inputs[0].m_channel->GetXAxisUnits();
m_yAxisUnit = m_inputs[0].m_channel->GetYAxisUnits();

//Do the average
auto cap = new AnalogWaveform;
cap->Resize(len);
cap->CopyTimestamps(din);
#pragma omp parallel for
for(size_t i=0; i<len; i++)
size_t nsamples = len - depth;
size_t off = depth/2;
cap->Resize(nsamples);
float vmin = FLT_MAX;
float vmax = -FLT_MAX;
//#pragma omp parallel for
for(size_t i=0; i<nsamples; i++)
{
float v = 0;
size_t navg = 0;
for(size_t j=0; j<depth; j++)
{
if(j > i)
break;
v += din->m_samples[i+j];
v /= depth;

v += din->m_samples[i-j];
navg ++;
}
v /= navg;
vmin = min(vmin, v);
vmax = max(vmax, v);

cap->m_offsets[i] = din->m_offsets[i+off];
cap->m_durations[i] = din->m_durations[i+off];
cap->m_samples[i] = v;
}
SetData(cap, 0);

//Calculate bounds
m_max = max(m_max, vmax);
m_min = min(m_min, vmin);
m_range = (m_max - m_min) * 1.05;
m_offset = -( (m_max - m_min)/2 + m_min );

//Copy our time scales from the input
cap->m_timescale = din->m_timescale;
}
7 changes: 7 additions & 0 deletions scopeprotocols/MovingAverageFilter.h
Original file line number Diff line number Diff line change
@@ -45,6 +45,8 @@ class MovingAverageFilter : public Filter
virtual bool NeedsConfig();
virtual bool IsOverlay();

virtual void ClearSweeps();

static std::string GetProtocolName();
virtual void SetDefaultName();

@@ -56,6 +58,11 @@ class MovingAverageFilter : public Filter

protected:
std::string m_depthname;

float m_min;
float m_max;
float m_range;
float m_offset;
};

#endif