From 679fb49743ae50aec28d947f84200a9133941114 Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Tue, 27 Jul 2021 23:50:48 +0200 Subject: [PATCH] Added IQ correction --- core/src/core.cpp | 1 + core/src/gui/menus/source.cpp | 10 ++++++++++ core/src/signal_path/dsp.cpp | 19 ++++++++++++++++--- core/src/signal_path/dsp.h | 3 +++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/core/src/core.cpp b/core/src/core.cpp index 8d60165..8c21dbb 100644 --- a/core/src/core.cpp +++ b/core/src/core.cpp @@ -206,6 +206,7 @@ int sdrpp_main(int argc, char *argv[]) { defConfig["showWaterfall"] = true; defConfig["source"] = ""; defConfig["decimationPower"] = 0; + defConfig["iqCorrection"] = false; defConfig["streams"]["Radio"]["muted"] = false; defConfig["streams"]["Radio"]["sink"] = "Audio"; diff --git a/core/src/gui/menus/source.cpp b/core/src/gui/menus/source.cpp index 1afe0e0..43c8b95 100644 --- a/core/src/gui/menus/source.cpp +++ b/core/src/gui/menus/source.cpp @@ -12,6 +12,7 @@ namespace sourecmenu { double customOffset = 0.0; double effectiveOffset = 0.0; int decimationPower = 0; + bool iqCorrection = false; EventHandler sourceRegisteredHandler; EventHandler sourceUnregisterHandler; @@ -124,6 +125,8 @@ namespace sourecmenu { customOffset = core::configManager.conf["offset"]; offsetMode = core::configManager.conf["offsetMode"]; decimationPower = core::configManager.conf["decimationPower"]; + iqCorrection = core::configManager.conf["iqCorrection"]; + sigpath::signalPath.setIQCorrection(iqCorrection); updateOffset(); refreshSources(); @@ -158,6 +161,13 @@ namespace sourecmenu { sigpath::sourceManager.showSelectedMenu(); + if (ImGui::Checkbox("IQ Correction##_sdrpp_iq_corr", &iqCorrection)) { + sigpath::signalPath.setIQCorrection(iqCorrection); + core::configManager.acquire(); + core::configManager.conf["iqCorrection"] = iqCorrection; + core::configManager.release(true); + } + ImGui::Text("Offset mode"); ImGui::SameLine(); ImGui::SetNextItemWidth(itemWidth - ImGui::GetCursorPosX()); diff --git a/core/src/signal_path/dsp.cpp b/core/src/signal_path/dsp.cpp index 37f385e..15a3078 100644 --- a/core/src/signal_path/dsp.cpp +++ b/core/src/signal_path/dsp.cpp @@ -16,7 +16,8 @@ void SignalPath::init(uint64_t sampleRate, int fftRate, int fftSize, dsp::stream // split.init(input); inputBuffer.init(input); - split.init(&inputBuffer.out); + corrector.init(&inputBuffer.out, 100.0f / sampleRate); + split.init(&corrector.out); reshape.init(&fftStream, fftSize, (sampleRate / fftRate) - fftSize); split.bindStream(&fftStream); @@ -43,6 +44,8 @@ void SignalPath::setSampleRate(double sampleRate) { vfo.vfo->start(); } + corrector.setCorrectionRate(100.0f / sampleRate); + split.start(); } @@ -55,6 +58,7 @@ void SignalPath::start() { decimator->start(); } inputBuffer.start(); + corrector.start(); split.start(); reshape.start(); fftHandlerSink.start(); @@ -66,6 +70,7 @@ void SignalPath::stop() { decimator->stop(); } inputBuffer.stop(); + corrector.stop(); split.stop(); reshape.stop(); fftHandlerSink.stop(); @@ -159,7 +164,7 @@ void SignalPath::setDecimation(int dec) { // If no decimation, reconnect if (!dec) { - split.setInput(&inputBuffer.out); + split.setInput(&corrector.out); if (running) { split.start(); } core::setInputSampleRate(sourceSampleRate); return; @@ -167,7 +172,7 @@ void SignalPath::setDecimation(int dec) { // Create new decimators for (int i = 0; i < dec; i++) { - dsp::HalfDecimator* decimator = new dsp::HalfDecimator((i == 0) ? &inputBuffer.out : &decimators[i-1]->out, &halfBandWindow); + dsp::HalfDecimator* decimator = new dsp::HalfDecimator((i == 0) ? &corrector.out : &decimators[i-1]->out, &halfBandWindow); if (running) { decimator->start(); } decimators.push_back(decimator); } @@ -176,4 +181,12 @@ void SignalPath::setDecimation(int dec) { // Update the DSP sample rate core::setInputSampleRate(sourceSampleRate); +} + +void SignalPath::setIQCorrection(bool enabled) { + corrector.bypass = !enabled; + if (!enabled) { + corrector.offset.re = 0; + corrector.offset.im = 0; + } } \ No newline at end of file diff --git a/core/src/signal_path/dsp.h b/core/src/signal_path/dsp.h index a644850..cf6f2af 100644 --- a/core/src/signal_path/dsp.h +++ b/core/src/signal_path/dsp.h @@ -4,6 +4,7 @@ #include #include #include +#include class SignalPath { public: @@ -24,6 +25,7 @@ public: void stopFFT(); void setBuffering(bool enabled); void setDecimation(int dec); + void setIQCorrection(bool enabled); dsp::SampleFrameBuffer inputBuffer; double sourceSampleRate = 0; @@ -36,6 +38,7 @@ private: }; dsp::Splitter split; + dsp::IQCorrector corrector; // FFT dsp::stream fftStream;