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

Commits on Aug 10, 2020

  1. Copy the full SHA
    9b2c636 View commit details
Showing with 29 additions and 55 deletions.
  1. +27 −52 scopeprotocols/DeEmbedDecoder.cpp
  2. +2 −3 scopeprotocols/DeEmbedDecoder.h
79 changes: 27 additions & 52 deletions scopeprotocols/DeEmbedDecoder.cpp
Original file line number Diff line number Diff line change
@@ -199,7 +199,6 @@ void DeEmbedDecoder::DoRefresh(bool invert)

//Clear out cached S-parameters
m_cachedBinSize = 0;
m_resampledSparamPhases.clear();
m_resampledSparamCosines.clear();
m_resampledSparamSines.clear();
m_resampledSparamAmplitudes.clear();
@@ -267,7 +266,8 @@ void DeEmbedDecoder::DoRefresh(bool invert)
double sample_ghz = 1000 / ps;
double bin_hz = round((0.5f * sample_ghz * 1e9f) / nouts);

//Resample S21 to our FFT bin size if needed
//Resample S21 to our FFT bin size if needed.
//Cache trig function output because there's no AVX instructions for this.
if(fabs(m_cachedBinSize - bin_hz) > FLT_EPSILON)
{
m_cachedBinSize = bin_hz;
@@ -276,54 +276,33 @@ void DeEmbedDecoder::DoRefresh(bool invert)
{
auto point = m_sparams.SamplePoint(2, 1, bin_hz * i);

m_resampledSparamPhases.push_back(point.m_phase);
m_resampledSparamSines.push_back(sin(point.m_phase));
m_resampledSparamCosines.push_back(cos(point.m_phase));
m_resampledSparamAmplitudes.push_back(point.m_amplitude);
}
}
//De-embedding
if(invert)
{
m_resampledSparamSines.push_back(sin(-point.m_phase));
m_resampledSparamCosines.push_back(cos(-point.m_phase));

//Do the actual de-embed
if(invert)
{
for(size_t i=0; i<nouts; i++)
{
float amplitude = m_resampledSparamAmplitudes[i];
float phase = m_resampledSparamPhases[i];
if(fabs(point.m_amplitude) < FLT_EPSILON)
m_resampledSparamAmplitudes.push_back(0);
else
m_resampledSparamAmplitudes.push_back(1.0f / point.m_amplitude);
}

//Zero channel response = flatten rather than dividing by zero
if(fabs(amplitude) < FLT_EPSILON)
//Channel emulation
else
{
m_forwardOutBuf[i*2 + 0] = 0;
m_forwardOutBuf[i*2 + 1] = 0;
continue;
m_resampledSparamSines.push_back(sin(point.m_phase));
m_resampledSparamCosines.push_back(cos(point.m_phase));
m_resampledSparamAmplitudes.push_back(point.m_amplitude);
}

float cosval = cos(-phase);
float sinval = sin(-phase);

//Uncorrected complex value
float real_orig = m_forwardOutBuf[i*2 + 0];
float imag_orig = m_forwardOutBuf[i*2 + 1];

//Phase correction
float real = real_orig*cosval - imag_orig*sinval;
float imag = real_orig*sinval + imag_orig*cosval;

//Amplitude correction
m_forwardOutBuf[i*2 + 0] = real / amplitude;
m_forwardOutBuf[i*2 + 1] = imag / amplitude;
}
}

//Forward channel emulation
//Do the actual filter operation
if(g_hasAvx2)
MainLoopAVX2(nouts);
else
{
if(g_hasAvx2)
ForwardMainLoopAVX2(nouts);
else
ForwardMainLoop(nouts);
}
MainLoop(nouts);

//Calculate the inverse FFT
ffts_execute(m_reversePlan, &m_forwardOutBuf[0], &m_reverseOutBuf[0]);
@@ -375,15 +354,13 @@ void DeEmbedDecoder::DoRefresh(bool invert)
SetData(cap);
}

void DeEmbedDecoder::ForwardMainLoop(size_t nouts)
void DeEmbedDecoder::MainLoop(size_t nouts)
{
for(size_t i=0; i<nouts; i++)
{
float amplitude = m_resampledSparamAmplitudes[i];
float phase = m_resampledSparamPhases[i];

float cosval = cos(phase);
float sinval = sin(phase);
float cosval = m_resampledSparamSines[i];
float sinval = m_resampledSparamCosines[i];

//Uncorrected complex value
float real_orig = m_forwardOutBuf[i*2 + 0];
@@ -400,7 +377,7 @@ void DeEmbedDecoder::ForwardMainLoop(size_t nouts)
}

__attribute__((target("avx2")))
void DeEmbedDecoder::ForwardMainLoopAVX2(size_t nouts)
void DeEmbedDecoder::MainLoopAVX2(size_t nouts)
{
unsigned int end = nouts - (nouts % 8);

@@ -468,10 +445,8 @@ void DeEmbedDecoder::ForwardMainLoopAVX2(size_t nouts)
for(size_t i=end; i<nouts; i++)
{
float amplitude = m_resampledSparamAmplitudes[i];
float phase = m_resampledSparamPhases[i];

float cosval = cos(phase);
float sinval = sin(phase);
float cosval = m_resampledSparamCosines[i];
float sinval = m_resampledSparamSines[i];

//Uncorrected complex value
float real_orig = m_forwardOutBuf[i*2 + 0];
5 changes: 2 additions & 3 deletions scopeprotocols/DeEmbedDecoder.h
Original file line number Diff line number Diff line change
@@ -74,7 +74,6 @@ class DeEmbedDecoder : public ProtocolDecoder
float m_offset;

double m_cachedBinSize;
std::vector<float, AlignedAllocator<float, 64> > m_resampledSparamPhases;
std::vector<float, AlignedAllocator<float, 64> > m_resampledSparamSines;
std::vector<float, AlignedAllocator<float, 64> > m_resampledSparamCosines;
std::vector<float, AlignedAllocator<float, 64> > m_resampledSparamAmplitudes;
@@ -90,8 +89,8 @@ class DeEmbedDecoder : public ProtocolDecoder
float* m_forwardOutBuf;
float* m_reverseOutBuf;

void ForwardMainLoop(size_t nouts);
void ForwardMainLoopAVX2(size_t nouts);
void MainLoop(size_t nouts);
void MainLoopAVX2(size_t nouts);
};

#endif