Skip to content

Commit

Permalink
added define PRINT_INPUT_RANGE to enable debug output of ADC overstee…
Browse files Browse the repository at this point in the history
…ring

with Drok JDS6600 Signal Generator, generating Sine with 0.3V Amplitude,
having RX888 at +0dB ATT (Attenuators deactivated)
=> 14.6 (+1 sign) Bits are used .. value range ~ 78%

Signed-off-by: hayati ayguen <[email protected]>
  • Loading branch information
hayguen committed Jan 8, 2021
1 parent dfd50e6 commit 9fa7463
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ enum rf_mode { NOMODE = 0, HFMODE = 0x1, VHFMODE = 0x2 };
extern bool saveADCsamplesflag;

const int transferSize = 131072;
const int transferSamples = 131072 / sizeof(int16_t);

const uint32_t DEFAULT_ADC_FREQ = 64000000; // ADC sampling frequency

const uint32_t DEFAULT_TRANSFERS_PER_SEC = DEFAULT_ADC_FREQ / transferSamples;

#endif // _CONFIG_H_

62 changes: 58 additions & 4 deletions Core/fft_mt_r2iq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,32 @@ The name r2iq as Real 2 I+Q stream

#include <string.h>
#include <algorithm>
#include <utility>

// assure, that ADC is not oversteered?
#define PRINT_INPUT_RANGE 0


struct r2iqThreadArg {

r2iqThreadArg()
{
#if PRINT_INPUT_RANGE
MinMaxBlockCount = 0;
MinValue = 0;
MaxValue = 0;
#endif
}

float *ADCinTime; // point to each threads input buffers [nftt][n]
fftwf_complex *ADCinFreq; // buffers in frequency
fftwf_complex *inFreqTmp; // tmp decimation output buffers (after tune shift)
fftwf_complex *outTimeTmp; // tmp decimation output buffers baseband time cplx
#if PRINT_INPUT_RANGE
int MinMaxBlockCount;
int16_t MinValue;
int16_t MaxValue;
#endif
};

r2iqControlClass::r2iqControlClass()
Expand Down Expand Up @@ -289,26 +309,60 @@ void * fft_mt_r2iq::r2iqThreadf(r2iqThreadArg *th) {
*inloop++ = *endloop++; // duplicate form last frame halfFft samples
}

#if PRINT_INPUT_RANGE
std::pair<int16_t, int16_t> blockMinMax = std::make_pair<int16_t, int16_t>(0, 0);
#endif
if (!this->getRand()) // plain samples no ADC rand set
{
for (int m = 0; m < transferSize / sizeof(int16_t); m++) {
#if PRINT_INPUT_RANGE
auto minmax = std::minmax_element(dataADC, dataADC + transferSamples);
blockMinMax.first = *minmax.first;
blockMinMax.second = *minmax.second;
#endif
for (int m = 0; m < transferSamples; m++)
{
*inloop++ = *dataADC++;
}
}
else
{
for (int m = 0; m < transferSize / sizeof(int16_t); m++) {
for (int m = 0; m < transferSamples; m++)
{
#if PRINT_INPUT_RANGE
int16_t smp = RandTable[(uint16_t)*dataADC++];
blockMinMax.first = std::min(blockMinMax.first, smp);
blockMinMax.second = std::max(blockMinMax.second, smp);
*inloop++ = smp;
#else
*inloop++ = (RandTable[(uint16_t)*dataADC++]);
#endif
}
}

#if PRINT_INPUT_RANGE
th->MinValue = std::min(blockMinMax.first, th->MinValue);
th->MaxValue = std::max(blockMinMax.second, th->MaxValue);
++th->MinMaxBlockCount;
if (th->MinMaxBlockCount * processor_count / 3 >= DEFAULT_TRANSFERS_PER_SEC )
{
float minBits = (th->MinValue < 0) ? (log10f((float)(-th->MinValue)) / log10f(2.0f)) : -1.0f;
float maxBits = (th->MaxValue > 0) ? (log10f((float)(th->MaxValue)) / log10f(2.0f)) : -1.0f;
printf("r2iq: min = %d (%.1f bits) %.2f%%, max = %d (%.1f bits) %.2f%%\n",
(int)th->MinValue, minBits, th->MinValue *-100.0f / 32768.0f,
(int)th->MaxValue, maxBits, th->MaxValue * 100.0f / 32768.0f);
th->MinValue = 0;
th->MaxValue = 0;
th->MinMaxBlockCount = 0;
}
#endif

// decimate in frequency plus tuning

// Caculate the parameters for the first half
// Calculate the parameters for the first half
auto count = std::min(mfft/2, halfFft - _mtunebin);
auto source = &th->ADCinFreq[_mtunebin];

// Caculate the parameters for the second half
// Calculate the parameters for the second half
auto start = std::max(0, mfft / 2 - _mtunebin);
auto source2 = &th->ADCinFreq[_mtunebin - mfft / 2];
auto filter2 = &filter[halfFft - mfft / 2];
Expand Down

0 comments on commit 9fa7463

Please sign in to comment.