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

Commits on Nov 29, 2020

  1. Copy the full SHA
    960a504 View commit details
  2. Copy the full SHA
    c9959b5 View commit details
2 changes: 2 additions & 0 deletions scopeprotocols/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ set(SCOPEPROTOCOLS_SOURCES
DSIPacketDecoder.cpp
DutyCycleMeasurement.cpp
DVIDecoder.cpp
EmphasisRemovalFilter.cpp
Ethernet10BaseTDecoder.cpp
Ethernet100BaseTDecoder.cpp
Ethernet1000BaseXDecoder.cpp
@@ -78,6 +79,7 @@ set(SCOPEPROTOCOLS_SOURCES
SWDDecoder.cpp
SWDMemAPDecoder.cpp
TachometerFilter.cpp
TappedDelayLineFilter.cpp
ThresholdFilter.cpp
TIEMeasurement.cpp
TMDSDecoder.cpp
187 changes: 187 additions & 0 deletions scopeprotocols/EmphasisRemovalFilter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/***********************************************************************************************************************
* *
* 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 "EmphasisRemovalFilter.h"
#include "TappedDelayLineFilter.h"

using namespace std;

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

EmphasisRemovalFilter::EmphasisRemovalFilter(const string& color)
: Filter(OscilloscopeChannel::CHANNEL_TYPE_ANALOG, color, CAT_ANALYSIS)
, m_dataRateName("Data Rate")
, m_emphasisTypeName("Emphasis Type")
, m_emphasisAmountName("Emphasis Amount")
{
CreateInput("in");

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

m_parameters[m_dataRateName] = FilterParameter(FilterParameter::TYPE_INT, Unit(Unit::UNIT_BITRATE));
m_parameters[m_dataRateName].SetIntVal(5e9);

m_parameters[m_emphasisTypeName] = FilterParameter(FilterParameter::TYPE_ENUM, Unit(Unit::UNIT_COUNTS));
m_parameters[m_emphasisTypeName].AddEnumValue("De-emphasis", DE_EMPHASIS);
m_parameters[m_emphasisTypeName].SetIntVal(DE_EMPHASIS);

m_parameters[m_emphasisAmountName] = FilterParameter(FilterParameter::TYPE_FLOAT, Unit(Unit::UNIT_DB));
m_parameters[m_emphasisAmountName].SetFloatVal(6);
}

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

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

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

return false;
}

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

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

void EmphasisRemovalFilter::SetDefaultName()
{
char hwname[256];
snprintf(hwname, sizeof(hwname), "EmphasisRemoval(%s, %s)",
GetInputDisplayName(0).c_str(),
m_parameters[m_emphasisAmountName].ToString().c_str());
m_hwname = hwname;
m_displayname = m_hwname;
}

string EmphasisRemovalFilter::GetProtocolName()
{
return "Emphasis Removal";
}

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

bool EmphasisRemovalFilter::NeedsConfig()
{
return true;
}

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

double EmphasisRemovalFilter::GetOffset()
{
return m_offset;
}

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

void EmphasisRemovalFilter::Refresh()
{
if(!VerifyAllInputsOKAndAnalog())
{
SetData(NULL, 0);
return;
}

//Only de-emphasis is implemented for now
if(m_parameters[m_emphasisTypeName].GetIntVal() != DE_EMPHASIS)
{
SetData(NULL, 0);
return;
}

//Get the input data
auto din = GetAnalogInputWaveform(0);
size_t len = din->m_samples.size();
if(len < 8)
{
SetData(NULL, 0);
return;
}
m_xAxisUnit = m_inputs[0].m_channel->GetXAxisUnits();
m_yAxisUnit = m_inputs[0].m_channel->GetYAxisUnits();

//Set up output
auto cap = new AnalogWaveform;
cap->m_timescale = din->m_timescale;
cap->m_startTimestamp = din->m_startTimestamp;
cap->m_startFemtoseconds = din->m_startFemtoseconds;
SetData(cap, 0);

//Convert data rate to tap delay
int64_t tap_delay = round(FS_PER_SECOND / m_parameters[m_dataRateName].GetFloatVal());

//Calculate the tap values
//Reference: "Dealing with De-Emphasis in Jitter Testing", P. Pupalaikis, LeCroy technical brief, 2008
const int64_t tap_count = 8;
float db = m_parameters[m_emphasisAmountName].GetFloatVal();
float coeff = 0.5 * pow(10, -db/20);
float c = coeff + 0.5;
float p = coeff - 0.5;
float p_over_c = p / c;
float taps[tap_count] = {0};

taps[0] = 1/c;
for(int64_t i=1; i<tap_count; i++)
taps[i] = -p_over_c * taps[i-1];

//Run the actual filter
float vmin;
float vmax;
TappedDelayLineFilter::DoFilterKernel(tap_count, tap_delay, taps, din, cap, vmin, vmax);

//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 );
}
78 changes: 78 additions & 0 deletions scopeprotocols/EmphasisRemovalFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/***********************************************************************************************************************
* *
* 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 EmphasisRemovalFilter
*/
#ifndef EmphasisRemovalFilter_h
#define EmphasisRemovalFilter_h

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

virtual void Refresh();

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

virtual void ClearSweeps();

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

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

virtual bool ValidateChannel(size_t i, StreamDescriptor stream);

PROTOCOL_DECODER_INITPROC(EmphasisRemovalFilter)

enum EmphasisType
{
PRE_EMPHASIS,
DE_EMPHASIS
};

protected:

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

std::string m_dataRateName;
std::string m_emphasisTypeName;
std::string m_emphasisAmountName;
};

#endif
3 changes: 2 additions & 1 deletion scopeprotocols/JitterSpectrumFilter.cpp
Original file line number Diff line number Diff line change
@@ -185,7 +185,8 @@ void JitterSpectrumFilter::Refresh()
size_t capture_duration = din->m_offsets[inlen-1] + din->m_durations[inlen-1];
size_t num_uis = extended_samples.size();
double ui_width_final = static_cast<double>(capture_duration) / num_uis;
LogTrace("Final UI width estimate: %.1f\n", ui_width_final);
LogTrace("Capture is %zu UIs, %s\n", num_uis, Unit(Unit::UNIT_FS).PrettyPrint(capture_duration).c_str());
LogTrace("Final UI width estimate: %s\n", Unit(Unit::UNIT_FS).PrettyPrint(ui_width_final).c_str());

//Round size up to next power of two
const size_t npoints_raw = extended_samples.size();
2 changes: 2 additions & 0 deletions scopeprotocols/MovingAverageFilter.cpp
Original file line number Diff line number Diff line change
@@ -168,4 +168,6 @@ void MovingAverageFilter::Refresh()

//Copy our time scales from the input
cap->m_timescale = din->m_timescale;
cap->m_startTimestamp = din->m_startTimestamp;
cap->m_startFemtoseconds = din->m_startFemtoseconds;
}
Loading