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

Commits on May 12, 2020

  1. Copy the full SHA
    1fff87e View commit details
Showing with 54 additions and 17 deletions.
  1. +9 −1 scopehal/Unit.cpp
  2. +2 −1 scopehal/Unit.h
  3. +43 −12 scopeprotocols/HorizontalBathtubDecoder.cpp
  4. +0 −3 scopeprotocols/HorizontalBathtubDecoder.h
10 changes: 9 additions & 1 deletion scopehal/Unit.cpp
Original file line number Diff line number Diff line change
@@ -139,12 +139,20 @@ string Unit::PrettyPrint(double value)
scale = "";
value_rescaled = value; //TODO: scientific notation flag?
break;
case UNIT_LOG_BER:
unit = "";
scale = "";
value_rescaled = value;
break;

default:
return "Invalid unit";
}

char tmp[128];
snprintf(tmp, sizeof(tmp), "%.3f %s%s", value_rescaled, scale, unit);
if(m_type == UNIT_LOG_BER) //special formatting for BER since it's already logarithmic
snprintf(tmp, sizeof(tmp), "1e%.0f", value);
else
snprintf(tmp, sizeof(tmp), "%.3f %s%s", value_rescaled, scale, unit);
return string(tmp);
}
3 changes: 2 additions & 1 deletion scopehal/Unit.h
Original file line number Diff line number Diff line change
@@ -54,7 +54,8 @@ class Unit
UNIT_BITRATE, //Bits per second
UNIT_PERCENT, //Dimensionless ratio
UNIT_DB, //Dimensionless ratio
UNIT_COUNTS //Dimensionless ratio (histogram)
UNIT_COUNTS, //Dimensionless ratio (histogram)
UNIT_LOG_BER //Dimensionless ratio (log scale)

//TODO: more here
};
55 changes: 43 additions & 12 deletions scopeprotocols/HorizontalBathtubDecoder.cpp
Original file line number Diff line number Diff line change
@@ -38,15 +38,12 @@ using namespace std;
HorizontalBathtubDecoder::HorizontalBathtubDecoder(string color)
: ProtocolDecoder(OscilloscopeChannel::CHANNEL_TYPE_ANALOG, color, CAT_ANALYSIS)
{
m_yAxisUnit = Unit(Unit::UNIT_COUNTS);
m_yAxisUnit = Unit(Unit::UNIT_LOG_BER);

//Set up channels
m_signalNames.push_back("din");
m_channels.push_back(NULL);

m_midpoint = 0.5;
m_range = 1;

m_voltageName = "Voltage";
m_parameters[m_voltageName] = ProtocolDecoderParameter(ProtocolDecoderParameter::TYPE_FLOAT);
m_parameters[m_voltageName].SetFloatVal(0);
@@ -94,12 +91,14 @@ bool HorizontalBathtubDecoder::NeedsConfig()

double HorizontalBathtubDecoder::GetVoltageRange()
{
return m_range;
//1e12 total height
return 12;
}

double HorizontalBathtubDecoder::GetOffset()
{
return -m_midpoint;
//1e-6 is the midpoint
return 6;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -140,20 +139,52 @@ void HorizontalBathtubDecoder::Refresh()
AnalogCapture* cap = new AnalogCapture;

//Extract the single scanline we're interested in
//TODO: support a range of voltages
int64_t* row = din->GetAccumData() + ybin*din->GetWidth();
m_range = 0;
float nmax = 0;
for(size_t i=0; i<din->GetWidth(); i++)
{
int64_t sample = row[i];
if(sample > m_range)
m_range = sample;
if(sample > nmax)
nmax = sample;

cap->m_samples.push_back(AnalogSample(i*ps_per_pixel - din->m_uiWidth, ps_per_pixel, sample));
}

//Scale so we don't quite touch the edges of the plot
m_range *= 1.05;
m_midpoint = m_range/2;
//Normalize to max amplitude
for(size_t i=0; i<cap->m_samples.size(); i++)
cap->m_samples[i].m_sample /= nmax;

//Move from the center out and persist the max BER
float maxleft = 0;
float maxright = 0;
ssize_t mid = cap->m_samples.size()/2;
for(ssize_t i=mid; i>=0; i--)
{
float& samp = cap->m_samples[i].m_sample;
if(samp > maxleft)
maxleft = samp;
else
samp = maxleft;
}
for(size_t i=mid; i<cap->m_samples.size(); i++)
{
float& samp = cap->m_samples[i].m_sample;
if(samp > maxright)
maxright = samp;
else
samp = maxright;
}

//Log post-scaling
for(size_t i=0; i<cap->m_samples.size(); i++)
{
float& samp = cap->m_samples[i].m_sample;
if(samp < 1e-12)
samp = -14; //cap ber if we don't have enough data
else
samp = log10(samp);
}

SetData(cap);

3 changes: 0 additions & 3 deletions scopeprotocols/HorizontalBathtubDecoder.h
Original file line number Diff line number Diff line change
@@ -59,9 +59,6 @@ class HorizontalBathtubDecoder : public ProtocolDecoder

protected:
std::string m_voltageName;

double m_midpoint;
double m_range;
};

#endif