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

Commits on Dec 1, 2020

  1. Filter: removed double-precision FindZeroCrossings(), redundant now t…

    …hat we have femtosecond timing resolution
    azonenberg committed Dec 1, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d015a6c View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    211e07f View commit details
72 changes: 26 additions & 46 deletions scopehal/Filter.cpp
Original file line number Diff line number Diff line change
@@ -36,10 +36,13 @@
#include "scopehal.h"
#include "Filter.h"

using namespace std;

Filter::CreateMapType Filter::m_createprocs;
std::set<Filter*> Filter::m_filters;
set<Filter*> Filter::m_filters;

using namespace std;
mutex Filter::m_cacheMutex;
map<pair<WaveformBase*, float>, vector<int64_t> > Filter::m_zeroCrossingCache;

Gdk::Color Filter::m_standardColors[STANDARD_COLOR_COUNT] =
{
@@ -462,45 +465,25 @@ void Filter::SampleOnAnyEdges(DigitalBusWaveform* data, DigitalWaveform* clock,
/**
@brief Find zero crossings in a waveform, interpolating as necessary
*/
void Filter::FindZeroCrossings(AnalogWaveform* data, float threshold, std::vector<int64_t>& edges)
void Filter::FindZeroCrossings(AnalogWaveform* data, float threshold, vector<int64_t>& edges)
{
//Find times of the zero crossings
bool first = true;
bool last = false;
int64_t phoff = data->m_timescale/2 + data->m_triggerPhase;
size_t len = data->m_samples.size();
for(size_t i=1; i<len; i++)
{
bool value = data->m_samples[i] > threshold;
pair<WaveformBase*, float> cachekey(data, threshold);

//Save the last value
if(first)
//Check cache
{
lock_guard<mutex> lock(m_cacheMutex);
auto it = m_zeroCrossingCache.find(cachekey);
if(it != m_zeroCrossingCache.end())
{
last = value;
first = false;
continue;
edges = it->second;
return;
}

//Skip samples with no transition
if(last == value)
continue;

//Midpoint of the sample, plus the zero crossing
int64_t t = phoff + data->m_timescale * (data->m_offsets[i] + InterpolateTime(data, i-1, threshold));
edges.push_back(t);
last = value;
}
}

/**
@brief Find zero crossings in a waveform, interpolating as necessary
*/
void Filter::FindZeroCrossings(AnalogWaveform* data, float threshold, std::vector<double>& edges)
{
//Find times of the zero crossings
bool first = true;
bool last = false;
double phoff = data->m_timescale/2 + data->m_triggerPhase;
int64_t phoff = data->m_timescale/2 + data->m_triggerPhase;
size_t len = data->m_samples.size();
for(size_t i=1; i<len; i++)
{
@@ -519,10 +502,14 @@ void Filter::FindZeroCrossings(AnalogWaveform* data, float threshold, std::vecto
continue;

//Midpoint of the sample, plus the zero crossing
double t = phoff + data->m_timescale * (data->m_offsets[i] + InterpolateTime(data, i-1, threshold));
int64_t t = phoff + data->m_timescale * (data->m_offsets[i] + InterpolateTime(data, i-1, threshold));
edges.push_back(t);
last = value;
}

//Add to cache
lock_guard<mutex> lock(m_cacheMutex);
m_zeroCrossingCache[cachekey] = edges;
}

/**
@@ -616,19 +603,6 @@ void Filter::FindFallingEdges(DigitalWaveform* data, vector<int64_t>& edges)
}
}

/**
@brief Find edges in a waveform, discarding repeated samples
No extra resolution vs the int64 version, just for interface compatibility with the analog interpolating version.
*/
void Filter::FindZeroCrossings(DigitalWaveform* data, vector<double>& edges)
{
vector<int64_t> tmp;
FindZeroCrossings(data, tmp);
for(auto e : tmp)
edges.push_back(e);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Serialization

@@ -968,3 +942,9 @@ float Filter::GetTopVoltage(AnalogWaveform* cap)
float fbin = (idx + 0.5f)/nbins;
return fbin*delta + vmin;
}

void Filter::ClearAnalysisCache()
{
lock_guard<mutex> lock(m_cacheMutex);
m_zeroCrossingCache.clear();
}
8 changes: 6 additions & 2 deletions scopehal/Filter.h
Original file line number Diff line number Diff line change
@@ -223,13 +223,13 @@ class Filter : public OscilloscopeChannel

//Find interpolated zero crossings of a signal
static void FindZeroCrossings(AnalogWaveform* data, float threshold, std::vector<int64_t>& edges);
static void FindZeroCrossings(AnalogWaveform* data, float threshold, std::vector<double>& edges);

//Find edges in a signal (discarding repeated samples)
static void FindZeroCrossings(DigitalWaveform* data, std::vector<int64_t>& edges);
static void FindRisingEdges(DigitalWaveform* data, std::vector<int64_t>& edges);
static void FindFallingEdges(DigitalWaveform* data, std::vector<int64_t>& edges);
static void FindZeroCrossings(DigitalWaveform* data, std::vector<double>& edges);

static void ClearAnalysisCache();

protected:
//Common text formatting
@@ -249,6 +249,10 @@ class Filter : public OscilloscopeChannel

//Object enumeration
static std::set<Filter*> m_filters;

//Caching
static std::mutex m_cacheMutex;
static std::map<std::pair<WaveformBase*, float>, std::vector<int64_t> > m_zeroCrossingCache;
};

#define PROTOCOL_DECODER_INITPROC(T) \
8 changes: 4 additions & 4 deletions scopeprotocols/DutyCycleMeasurement.cpp
Original file line number Diff line number Diff line change
@@ -128,7 +128,7 @@ void DutyCycleMeasurement::Refresh()
float midpoint = GetAvgVoltage(din);

//Timestamps of the edges
vector<double> edges;
vector<int64_t> edges;
FindZeroCrossings(din, midpoint, edges);
if(edges.size() < 2)
{
@@ -146,9 +146,9 @@ void DutyCycleMeasurement::Refresh()
for(size_t i=0; i < (elen - 2); i+= 2)
{
//measure from edge to 2 edges later, since we find all zero crossings regardless of polarity
double start = edges[i];
double mid = edges[i+1];
double end = edges[i+2];
int64_t start = edges[i];
int64_t mid = edges[i+1];
int64_t end = edges[i+2];

double t1 = mid-start;
double t2 = end-mid;
8 changes: 4 additions & 4 deletions scopeprotocols/FrequencyMeasurement.cpp
Original file line number Diff line number Diff line change
@@ -120,7 +120,7 @@ void FrequencyMeasurement::Refresh()
auto din = GetInputWaveform(0);
auto din_analog = GetAnalogInputWaveform(0);
auto din_digital = GetDigitalInputWaveform(0);
vector<double> edges;
vector<int64_t> edges;

//Auto-threshold analog signals at 50% of full scale range
if(din_analog)
@@ -146,10 +146,10 @@ void FrequencyMeasurement::Refresh()
for(size_t i=0; i < (elen - 2); i+= 2)
{
//measure from edge to 2 edges later, since we find all zero crossings regardless of polarity
double start = edges[i];
double end = edges[i+2];
int64_t start = edges[i];
int64_t end = edges[i+2];

double delta = end - start;
int64_t delta = end - start;
double freq = FS_PER_SECOND / delta;

cap->m_offsets.push_back(start);
12 changes: 6 additions & 6 deletions scopeprotocols/PeriodMeasurement.cpp
Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@ void PeriodMeasurement::Refresh()
float midpoint = GetAvgVoltage(din);

//Timestamps of the edges
vector<double> edges;
vector<int64_t> edges;
FindZeroCrossings(din, midpoint, edges);
if(edges.size() < 2)
{
@@ -127,16 +127,16 @@ void PeriodMeasurement::Refresh()
//Create the output
auto cap = new AnalogWaveform;

double rmin = FLT_MAX;
double rmax = 0;
int64_t rmin = LONG_MAX;
int64_t rmax = 0;

for(size_t i=0; i < (edges.size()-2); i+= 2)
{
//measure from edge to 2 edges later, since we find all zero crossings regardless of polarity
double start = edges[i];
double end = edges[i+2];
int64_t start = edges[i];
int64_t end = edges[i+2];

double delta = end - start;
int64_t delta = end - start;
cap->m_offsets.push_back(start);
cap->m_durations.push_back(delta);
cap->m_samples.push_back(delta);
10 changes: 5 additions & 5 deletions scopeprotocols/TachometerFilter.cpp
Original file line number Diff line number Diff line change
@@ -119,7 +119,7 @@ void TachometerFilter::Refresh()
float midpoint = GetAvgVoltage(din);

//Timestamps of the edges
vector<double> edges;
vector<int64_t> edges;
FindZeroCrossings(din, midpoint, edges);
if(edges.size() < 2)
{
@@ -139,15 +139,15 @@ void TachometerFilter::Refresh()
for(size_t i=0; i < (elen - 2); i+= 2)
{
//measure from edge to 2 edges later, since we find all zero crossings regardless of polarity
double start = edges[i];
double end = edges[i+2];
int64_t start = edges[i];
int64_t end = edges[i+2];

double delta = end - start;
int64_t delta = end - start;
double freq = FS_PER_SECOND / delta;
double rpm = freq * pulses_to_rpm;

cap->m_offsets.push_back(start);
cap->m_durations.push_back(round(delta));
cap->m_durations.push_back(delta);
cap->m_samples.push_back(rpm);

rmin = min(rmin, rpm);