Added IQ correction

This commit is contained in:
Ryzerth 2021-07-27 23:50:48 +02:00
parent 5f29350dd1
commit 679fb49743
4 changed files with 30 additions and 3 deletions

View File

@ -206,6 +206,7 @@ int sdrpp_main(int argc, char *argv[]) {
defConfig["showWaterfall"] = true; defConfig["showWaterfall"] = true;
defConfig["source"] = ""; defConfig["source"] = "";
defConfig["decimationPower"] = 0; defConfig["decimationPower"] = 0;
defConfig["iqCorrection"] = false;
defConfig["streams"]["Radio"]["muted"] = false; defConfig["streams"]["Radio"]["muted"] = false;
defConfig["streams"]["Radio"]["sink"] = "Audio"; defConfig["streams"]["Radio"]["sink"] = "Audio";

View File

@ -12,6 +12,7 @@ namespace sourecmenu {
double customOffset = 0.0; double customOffset = 0.0;
double effectiveOffset = 0.0; double effectiveOffset = 0.0;
int decimationPower = 0; int decimationPower = 0;
bool iqCorrection = false;
EventHandler<std::string> sourceRegisteredHandler; EventHandler<std::string> sourceRegisteredHandler;
EventHandler<std::string> sourceUnregisterHandler; EventHandler<std::string> sourceUnregisterHandler;
@ -124,6 +125,8 @@ namespace sourecmenu {
customOffset = core::configManager.conf["offset"]; customOffset = core::configManager.conf["offset"];
offsetMode = core::configManager.conf["offsetMode"]; offsetMode = core::configManager.conf["offsetMode"];
decimationPower = core::configManager.conf["decimationPower"]; decimationPower = core::configManager.conf["decimationPower"];
iqCorrection = core::configManager.conf["iqCorrection"];
sigpath::signalPath.setIQCorrection(iqCorrection);
updateOffset(); updateOffset();
refreshSources(); refreshSources();
@ -158,6 +161,13 @@ namespace sourecmenu {
sigpath::sourceManager.showSelectedMenu(); 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::Text("Offset mode");
ImGui::SameLine(); ImGui::SameLine();
ImGui::SetNextItemWidth(itemWidth - ImGui::GetCursorPosX()); ImGui::SetNextItemWidth(itemWidth - ImGui::GetCursorPosX());

View File

@ -16,7 +16,8 @@ void SignalPath::init(uint64_t sampleRate, int fftRate, int fftSize, dsp::stream
// split.init(input); // split.init(input);
inputBuffer.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); reshape.init(&fftStream, fftSize, (sampleRate / fftRate) - fftSize);
split.bindStream(&fftStream); split.bindStream(&fftStream);
@ -43,6 +44,8 @@ void SignalPath::setSampleRate(double sampleRate) {
vfo.vfo->start(); vfo.vfo->start();
} }
corrector.setCorrectionRate(100.0f / sampleRate);
split.start(); split.start();
} }
@ -55,6 +58,7 @@ void SignalPath::start() {
decimator->start(); decimator->start();
} }
inputBuffer.start(); inputBuffer.start();
corrector.start();
split.start(); split.start();
reshape.start(); reshape.start();
fftHandlerSink.start(); fftHandlerSink.start();
@ -66,6 +70,7 @@ void SignalPath::stop() {
decimator->stop(); decimator->stop();
} }
inputBuffer.stop(); inputBuffer.stop();
corrector.stop();
split.stop(); split.stop();
reshape.stop(); reshape.stop();
fftHandlerSink.stop(); fftHandlerSink.stop();
@ -159,7 +164,7 @@ void SignalPath::setDecimation(int dec) {
// If no decimation, reconnect // If no decimation, reconnect
if (!dec) { if (!dec) {
split.setInput(&inputBuffer.out); split.setInput(&corrector.out);
if (running) { split.start(); } if (running) { split.start(); }
core::setInputSampleRate(sourceSampleRate); core::setInputSampleRate(sourceSampleRate);
return; return;
@ -167,7 +172,7 @@ void SignalPath::setDecimation(int dec) {
// Create new decimators // Create new decimators
for (int i = 0; i < dec; i++) { for (int i = 0; i < dec; i++) {
dsp::HalfDecimator<dsp::complex_t>* decimator = new dsp::HalfDecimator<dsp::complex_t>((i == 0) ? &inputBuffer.out : &decimators[i-1]->out, &halfBandWindow); dsp::HalfDecimator<dsp::complex_t>* decimator = new dsp::HalfDecimator<dsp::complex_t>((i == 0) ? &corrector.out : &decimators[i-1]->out, &halfBandWindow);
if (running) { decimator->start(); } if (running) { decimator->start(); }
decimators.push_back(decimator); decimators.push_back(decimator);
} }
@ -177,3 +182,11 @@ void SignalPath::setDecimation(int dec) {
// Update the DSP sample rate // Update the DSP sample rate
core::setInputSampleRate(sourceSampleRate); core::setInputSampleRate(sourceSampleRate);
} }
void SignalPath::setIQCorrection(bool enabled) {
corrector.bypass = !enabled;
if (!enabled) {
corrector.offset.re = 0;
corrector.offset.im = 0;
}
}

View File

@ -4,6 +4,7 @@
#include <map> #include <map>
#include <dsp/sink.h> #include <dsp/sink.h>
#include <dsp/decimation.h> #include <dsp/decimation.h>
#include <dsp/correction.h>
class SignalPath { class SignalPath {
public: public:
@ -24,6 +25,7 @@ public:
void stopFFT(); void stopFFT();
void setBuffering(bool enabled); void setBuffering(bool enabled);
void setDecimation(int dec); void setDecimation(int dec);
void setIQCorrection(bool enabled);
dsp::SampleFrameBuffer<dsp::complex_t> inputBuffer; dsp::SampleFrameBuffer<dsp::complex_t> inputBuffer;
double sourceSampleRate = 0; double sourceSampleRate = 0;
@ -36,6 +38,7 @@ private:
}; };
dsp::Splitter<dsp::complex_t> split; dsp::Splitter<dsp::complex_t> split;
dsp::IQCorrector corrector;
// FFT // FFT
dsp::stream<dsp::complex_t> fftStream; dsp::stream<dsp::complex_t> fftStream;