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

Commits on Jul 23, 2020

  1. Copy the full SHA
    041f512 View commit details
  2. DeEmbedDecoder: initial support for amplitude correction (see #183). …

    …Does not support phase correction yet.
    azonenberg committed Jul 23, 2020
    Copy the full SHA
    0b35104 View commit details
Showing with 41 additions and 19 deletions.
  1. +27 −18 scopehal/TouchstoneParser.cpp
  2. +14 −1 scopeprotocols/DeEmbedDecoder.cpp
45 changes: 27 additions & 18 deletions scopehal/TouchstoneParser.cpp
Original file line number Diff line number Diff line change
@@ -46,28 +46,37 @@ SParameterPoint SParameterVector::InterpolatePoint(float frequency)
size_t pos = len/2;
size_t last_lo = 0;
size_t last_hi = len - 1;
while(true)

//If out of range, clip
if(frequency < m_points[0].m_frequency)
return m_points[0];
else if(frequency > m_points[len-1].m_frequency)
return m_points[len-1];
else
{
SParameterPoint pivot = m_points[pos];
while(true)
{
SParameterPoint pivot = m_points[pos];

//Dead on? Stop
if( (last_hi - last_lo) <= 1)
break;
//Dead on? Stop
if( (last_hi - last_lo) <= 1)
break;

//Too high, move down
if(pivot.m_frequency > frequency)
{
size_t delta = (pos - last_lo);
pos = last_lo + delta/2;
last_hi = pos;
}
//Too high, move down
if(pivot.m_frequency > frequency)
{
size_t delta = (pos - last_lo);
last_hi = pos;
pos = last_lo + delta/2;
}

//Too low, move up
else
{
size_t delta = last_hi - pos;
pos = last_hi - delta/2;
last_lo = pos;
//Too low, move up
else
{
size_t delta = last_hi - pos;
last_lo = pos;
pos = last_hi - delta/2;
}
}
}

15 changes: 14 additions & 1 deletion scopeprotocols/DeEmbedDecoder.cpp
Original file line number Diff line number Diff line change
@@ -176,7 +176,20 @@ void DeEmbedDecoder::Refresh()
double sample_ghz = 1000 / ps;
double bin_hz = round((0.5f * sample_ghz * 1e9f) / nouts);

//TODO: Do the de-embed on the "rdout" buffer
//Do the actual de-embed
for(size_t i=0; i<nouts; i++)
{
//Calculate frequency of this bin and look up the resampled S21 parameter for it
float freq = bin_hz * i;
auto point = m_sparams.SamplePoint(2, 1, freq);

//TODO: Phase correction

//Amplitude correction
//We need to scale both real and imaginary parts
rdout[i*2 + 0] /= point.m_amplitude;
rdout[i*2 + 1] /= point.m_amplitude;
}

//Set up the inverse FFT
float* ddout;