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

Commits on Nov 26, 2020

  1. Initial implementation of HistogramFilter. Probably only really usefu…

    …l for jitter right now due to X axis integer restrictions.
    azonenberg committed Nov 26, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5853f3b View commit details
Showing with 282 additions and 0 deletions.
  1. +4 −0 scopehal/Unit.cpp
  2. +1 −0 scopehal/Unit.h
  3. +1 −0 scopeprotocols/CMakeLists.txt
  4. +204 −0 scopeprotocols/HistogramFilter.cpp
  5. +70 −0 scopeprotocols/HistogramFilter.h
  6. +1 −0 scopeprotocols/scopeprotocols.cpp
  7. +1 −0 scopeprotocols/scopeprotocols.h
4 changes: 4 additions & 0 deletions scopehal/Unit.cpp
Original file line number Diff line number Diff line change
@@ -184,6 +184,10 @@ string Unit::PrettyPrint(double value, int sigfigs)
value_rescaled = value * 100;
break;

case UNIT_COUNTS_SCI:
unit = "#";
break;

//Dimensionless unit, no scaling applied
case UNIT_DB:
unit = "dB";
1 change: 1 addition & 0 deletions scopehal/Unit.h
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@ class Unit
UNIT_DB, //Dimensionless ratio
UNIT_DBM, //dB mW (more common than dBW)
UNIT_COUNTS, //Dimensionless ratio (histogram)
UNIT_COUNTS_SCI, //Dimensionless ratio (histogram, but scientific notation)
UNIT_LOG_BER, //Dimensionless ratio (log scale)
UNIT_SAMPLERATE, //Sample rate (Hz but displayed as S/s)
UNIT_SAMPLEDEPTH, //Memory depth (number of samples)
1 change: 1 addition & 0 deletions scopeprotocols/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ set(SCOPEPROTOCOLS_SOURCES
FallMeasurement.cpp
FFTFilter.cpp
FrequencyMeasurement.cpp
HistogramFilter.cpp
HorizontalBathtub.cpp
I2CDecoder.cpp
I2CEepromDecoder.cpp
204 changes: 204 additions & 0 deletions scopeprotocols/HistogramFilter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2020 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

#include "scopeprotocols.h"
#include "HistogramFilter.h"

using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction

HistogramFilter::HistogramFilter(const string& color)
: Filter(OscilloscopeChannel::CHANNEL_TYPE_ANALOG, color, CAT_MATH)
{
m_yAxisUnit = Unit(Unit::UNIT_COUNTS_SCI);

//Set up channels
CreateInput("data");

m_midpoint = 0.5;
m_range = 1;

ClearSweeps();
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory methods

bool HistogramFilter::ValidateChannel(size_t i, StreamDescriptor stream)
{
if(stream.m_channel == NULL)
return false;

if(i > 0)
return false;
if(stream.m_channel->GetType() == OscilloscopeChannel::CHANNEL_TYPE_ANALOG)
return true;

return false;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Accessors

void HistogramFilter::SetDefaultName()
{
char hwname[256];
snprintf(hwname, sizeof(hwname), "Histogram(%s)", GetInputDisplayName(0).c_str());
m_hwname = hwname;
m_displayname = m_hwname;
}

string HistogramFilter::GetProtocolName()
{
return "Histogram";
}

bool HistogramFilter::IsOverlay()
{
//we create a new analog channel
return false;
}

bool HistogramFilter::NeedsConfig()
{
//automatic configuration
return false;
}

double HistogramFilter::GetVoltageRange()
{
return m_range;
}

double HistogramFilter::GetOffset()
{
return -m_midpoint;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Actual decoder logic

void HistogramFilter::ClearSweeps()
{
m_min = FLT_MAX;
m_max = -FLT_MAX;
m_histogram.clear();
SetData(NULL, 0);
}

void HistogramFilter::Refresh()
{
//Make sure we've got valid inputs
if(!VerifyAllInputsOKAndAnalog())
{
SetData(NULL, 0);
return;
}

auto din = GetAnalogInputWaveform(0);
m_xAxisUnit = GetInput(0).m_channel->GetYAxisUnits();

//Calculate min/max of the input data
float nmin = FLT_MAX;
float nmax = -FLT_MAX;
for(float v : din->m_samples)
{
nmin = min(nmin, v);
nmax = max(nmax, v);
}

//Calculate bin count
auto cap = dynamic_cast<AnalogWaveform*>(GetData(0));

//If the signal is outside our current range, extend our range
bool reallocate = false;
float range = m_max - m_min;
if( (nmin < m_min) || (nmax > m_max) || (cap == NULL) )
{
m_min = min(nmin, m_min);
m_max = max(nmax, m_max);

//Extend the range by a bit to avoid constant reallocation
range = m_max - m_min;
m_min -= 0.05 * range;
m_max += 0.05 * range;
range = m_max - m_min;

reallocate = true;
}

//Calculate histogram for our incoming data
size_t bins = ceil(range);
auto data = MakeHistogram(din, m_min, m_max, bins);

//Calculate bin configuration.
//Clip bin size to nearest ps (this will stop being a problem when we move to fs)
float binsize = range / bins;

//Reallocate the histogram if we changed it
if(reallocate)
{
//Reallocate our waveform
cap = new AnalogWaveform;
cap->m_timescale = 1;
cap->m_startTimestamp = din->m_startTimestamp;
cap->m_startPicoseconds = din->m_startPicoseconds;
SetData(cap, 0);

//Set up timestamps and initial values
for(size_t i=0; i<bins; i++)
{
cap->m_offsets.push_back(m_min + binsize*i);
cap->m_durations.push_back(binsize);
cap->m_samples.push_back(0);
}

m_histogram.clear();
for(size_t i=0; i<bins; i++)
m_histogram.push_back(0);
}

//Update histogram
size_t vmax = 0;
for(size_t i=0; i<bins; i++)
{
m_histogram[i] += data[i];
vmax = max(vmax, m_histogram[i]);
}

//Generate output
for(size_t i=0; i<bins; i++)
cap->m_samples[i] = m_histogram[i];

vmax *= 1.05;
m_range = vmax + 2;
m_midpoint = m_range/2;
}
70 changes: 70 additions & 0 deletions scopeprotocols/HistogramFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2020 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

/**
@file
@author Andrew D. Zonenberg
@brief Declaration of HistogramFilter
*/
#ifndef HistogramFilter_h
#define HistogramFilter_h

class HistogramFilter : public Filter
{
public:
HistogramFilter(const std::string& color);

virtual void Refresh();

virtual bool NeedsConfig();
virtual bool IsOverlay();

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

virtual double GetVoltageRange();
virtual double GetOffset();

virtual bool ValidateChannel(size_t i, StreamDescriptor stream);

virtual void ClearSweeps();

PROTOCOL_DECODER_INITPROC(HistogramFilter)

protected:
double m_midpoint;
double m_range;

float m_min;
float m_max;

std::vector<size_t> m_histogram;
};

#endif
1 change: 1 addition & 0 deletions scopeprotocols/scopeprotocols.cpp
Original file line number Diff line number Diff line change
@@ -81,6 +81,7 @@ void ScopeProtocolStaticInit()
AddDecoderClass(FallMeasurement);
AddDecoderClass(FFTFilter);
AddDecoderClass(FrequencyMeasurement);
AddDecoderClass(HistogramFilter);
AddDecoderClass(HorizontalBathtub);
AddDecoderClass(I2CDecoder);
AddDecoderClass(I2CEepromDecoder);
1 change: 1 addition & 0 deletions scopeprotocols/scopeprotocols.h
Original file line number Diff line number Diff line change
@@ -81,6 +81,7 @@
#include "FallMeasurement.h"
#include "FFTFilter.h"
#include "FrequencyMeasurement.h"
#include "HistogramFilter.h"
#include "HorizontalBathtub.h"
#include "IBM8b10bDecoder.h"
#include "I2CDecoder.h"