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: 1b6bd4682dd5
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 16d6822c7ef8
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Oct 11, 2020

  1. Copy the full SHA
    16d6822 View commit details
Showing with 33 additions and 4 deletions.
  1. +32 −4 scopeprotocols/ThresholdFilter.cpp
  2. +1 −0 scopeprotocols/ThresholdFilter.h
36 changes: 32 additions & 4 deletions scopeprotocols/ThresholdFilter.cpp
Original file line number Diff line number Diff line change
@@ -44,6 +44,10 @@ ThresholdFilter::ThresholdFilter(string color)
m_threshname = "Threshold";
m_parameters[m_threshname] = FilterParameter(FilterParameter::TYPE_FLOAT, Unit(Unit::UNIT_VOLTS));
m_parameters[m_threshname].SetFloatVal(0);

m_hysname = "Hysteresis";
m_parameters[m_hysname] = FilterParameter(FilterParameter::TYPE_FLOAT, Unit(Unit::UNIT_VOLTS));
m_parameters[m_hysname].SetFloatVal(0);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -96,14 +100,38 @@ void ThresholdFilter::Refresh()
auto din = GetAnalogInputWaveform(0);
auto len = din->m_samples.size();

//Threshold all of our samples
//Setup
float midpoint = m_parameters[m_threshname].GetFloatVal();
float hys = m_parameters[m_hysname].GetFloatVal();
DigitalWaveform* cap = new DigitalWaveform;
cap->Resize(len);
cap->CopyTimestamps(din);
#pragma omp parallel for
for(size_t i=0; i<len; i++)
cap->m_samples[i] = din->m_samples[i] > midpoint;

//Threshold all of our samples
//Optimized inner loop if no hysteresis
if(hys == 0)
{
#pragma omp parallel for
for(size_t i=0; i<len; i++)
cap->m_samples[i] = din->m_samples[i] > midpoint;
}
else
{
bool cur = din->m_samples[0] > midpoint;
float thresh_rising = midpoint + hys/2;
float thresh_falling = midpoint - hys/2;

for(size_t i=0; i<len; i++)
{
float f = din->m_samples[i];
if(cur && (f < thresh_falling))
cur = false;
else if(!cur && (f > thresh_rising))
cur = true;
cap->m_samples[i] = cur;
}
}

SetData(cap, 0);

//Copy our time scales from the input
1 change: 1 addition & 0 deletions scopeprotocols/ThresholdFilter.h
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@ class ThresholdFilter : public Filter

protected:
std::string m_threshname;
std::string m_hysname;
};

#endif