From 1efc50929607f74950caf4c478f747970ab039b9 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 4 Feb 2018 18:20:16 +0100 Subject: [PATCH] DC and IQ correction: added a defiend out integer version (no advantage over floating point) --- sdrbase/dsp/dspdevicesourceengine.cpp | 39 +++++++++++++++++++++++++++ sdrbase/dsp/dspdevicesourceengine.h | 19 ++++++++++--- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/sdrbase/dsp/dspdevicesourceengine.cpp b/sdrbase/dsp/dspdevicesourceengine.cpp index fe12e69e3..ad3d60908 100644 --- a/sdrbase/dsp/dspdevicesourceengine.cpp +++ b/sdrbase/dsp/dspdevicesourceengine.cpp @@ -183,6 +183,44 @@ void DSPDeviceSourceEngine::iqCorrections(SampleVector::iterator begin, SampleVe if (imbalanceCorrection) { +#if IMBALANCE_INT + // acquisition + int64_t xi = (it->m_real - (int32_t) m_iBeta) << 5; + int64_t xq = (it->m_imag - (int32_t) m_qBeta) << 5; + + // phase imbalance + m_avgII((xi*xi)>>28); // + m_avgIQ((xi*xq)>>28); // + + if ((int64_t) m_avgII != 0) + { + int64_t phi = (((int64_t) m_avgIQ)<<28) / (int64_t) m_avgII; + m_avgPhi(phi); + } + + int64_t corrPhi = (((int64_t) m_avgPhi) * xq) >> 28; //(m_avgPhi.asDouble()/16777216.0) * ((double) xq); + + int64_t yi = xi - corrPhi; + int64_t yq = xq; + + // amplitude I/Q imbalance + m_avgII2((yi*yi)>>28); // + m_avgQQ2((yq*yq)>>28); // + + if ((int64_t) m_avgQQ2 != 0) + { + int64_t a = (((int64_t) m_avgII2)<<28) / (int64_t) m_avgQQ2; + Fixed fA(Fixed::internal(), a); + Fixed sqrtA = sqrt((Fixed) fA); + m_avgAmp(sqrtA.as_internal()); + } + + int64_t zq = (((int64_t) m_avgAmp) * yq) >> 28; + + it->m_real = yi >> 5; + it->m_imag = zq >> 5; + +#else // DC correction and conversion float xi = (it->m_real - (int32_t) m_iBeta) / SDR_RX_SCALEF; float xq = (it->m_imag - (int32_t) m_qBeta) / SDR_RX_SCALEF; @@ -214,6 +252,7 @@ void DSPDeviceSourceEngine::iqCorrections(SampleVector::iterator begin, SampleVe // convert and store it->m_real = zi * SDR_RX_SCALEF; it->m_imag = zq * SDR_RX_SCALEF; +#endif } else { diff --git a/sdrbase/dsp/dspdevicesourceengine.h b/sdrbase/dsp/dspdevicesourceengine.h index aca574b91..923c0715e 100644 --- a/sdrbase/dsp/dspdevicesourceengine.h +++ b/sdrbase/dsp/dspdevicesourceengine.h @@ -102,17 +102,30 @@ private: bool m_dcOffsetCorrection; bool m_iqImbalanceCorrection; double m_iOffset, m_qOffset; + MovingAverageUtil m_iBeta; MovingAverageUtil m_qBeta; + +#if IMBALANCE_INT + // Fixed point DC + IQ corrections + MovingAverageUtil m_avgII; + MovingAverageUtil m_avgIQ; + MovingAverageUtil m_avgPhi; + MovingAverageUtil m_avgII2; + MovingAverageUtil m_avgQQ2; + MovingAverageUtil m_avgAmp; + +#else + // Floating point DC + IQ corrections MovingAverageUtil m_avgII; MovingAverageUtil m_avgIQ; MovingAverageUtil m_avgII2; MovingAverageUtil m_avgQQ2; MovingAverageUtil m_avgPhi; MovingAverageUtil m_avgAmp; -// MovingAverageUtil m_avgII; -// MovingAverageUtil m_avgIQ; - qint32 m_iRange; +#endif + + qint32 m_iRange; qint32 m_qRange; qint32 m_imbalance;