From 792a6a49747afde4be81e781f9ecb9c038bb1710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=A4berich?= Date: Wed, 8 May 2024 20:00:15 +0200 Subject: [PATCH] continuous updates for TDR/DFT with optional rate limit --- .../LibreVNA-GUI/Traces/Math/dft.cpp | 18 ++++-- .../LibreVNA-GUI/Traces/Math/tdr.cpp | 18 ++++-- .../LibreVNA-GUI/preferences.cpp | 7 +++ .../PC_Application/LibreVNA-GUI/preferences.h | 6 ++ .../LibreVNA-GUI/preferencesdialog.ui | 59 +++++++++++++++++-- 5 files changed, 91 insertions(+), 17 deletions(-) diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/Math/dft.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/Math/dft.cpp index 576aa848..22d838ef 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/Math/dft.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/Math/dft.cpp @@ -7,6 +7,9 @@ #include "ui_dftexplanationwidget.h" #include "appwindow.h" +#include +#include + #include using namespace std; @@ -133,11 +136,6 @@ void Math::DFT::inputSamplesChanged(unsigned int begin, unsigned int end) warning("Not enough input samples"); return; } - // DFT is computationally expensive, only update at the end of sweep -> check if this is the first changed data in the next sweep - if(begin != 0) { - // not the end, do nothing - return; - } // trigger calculation in thread semphr.release(); success(); @@ -159,6 +157,8 @@ Math::DFTThread::DFTThread(Math::DFT &dft) void Math::DFTThread::run() { qDebug() << "DFT thread starting"; + using namespace std::chrono; + auto lastCalc = system_clock::now(); while(1) { dft.semphr.acquire(); // clear possible additional semaphores @@ -168,7 +168,13 @@ void Math::DFTThread::run() qDebug() << "DFT thread exiting"; return; } - qDebug() << "DFT thread calculating"; + // limit update rate if configured in preferences + auto &p = Preferences::getInstance(); + if(p.Acquisition.limitDFT) { + std::this_thread::sleep_until(lastCalc + duration(1.0 / p.Acquisition.maxDFTrate)); + lastCalc = system_clock::now(); + } +// qDebug() << "DFT thread calculating"; double DC = dft.DCfreq; TDR *tdr = nullptr; if(dft.automaticDC) { diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/Math/tdr.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/Math/tdr.cpp index e2d95d55..697f11c2 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/Math/tdr.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/Math/tdr.cpp @@ -6,6 +6,9 @@ #include "Util/util.h" #include "appwindow.h" +#include +#include + #include #include #include @@ -201,11 +204,6 @@ void TDR::inputSamplesChanged(unsigned int begin, unsigned int end) { Q_UNUSED(end); if(input->rData().size() >= 2) { - // TDR is computationally expensive, only update at the end of sweep -> check if this is the first changed data in the next sweep - if(begin != 0) { - // not the end, do nothing - return; - } // trigger calculation in thread semphr.release(); success(); @@ -244,6 +242,8 @@ TDRThread::TDRThread(TDR &tdr) void TDRThread::run() { qDebug() << "TDR thread starting"; + using namespace std::chrono; + auto lastCalc = system_clock::now(); while(1) { tdr.semphr.acquire(); // clear possible additional semaphores @@ -253,7 +253,13 @@ void TDRThread::run() qDebug() << "TDR thread exiting"; return; } - qDebug() << "TDR thread calculating"; + // limit update rate if configured in preferences + auto &p = Preferences::getInstance(); + if(p.Acquisition.limitDFT) { + std::this_thread::sleep_until(lastCalc + duration(1.0 / p.Acquisition.maxDFTrate)); + lastCalc = system_clock::now(); + } +// qDebug() << "TDR thread calculating"; // perform calculation vector> frequencyDomain; auto stepSize = (tdr.input->rData().back().x - tdr.input->rData().front().x) / (tdr.input->rData().size() - 1); diff --git a/Software/PC_Application/LibreVNA-GUI/preferences.cpp b/Software/PC_Application/LibreVNA-GUI/preferences.cpp index 2b231c15..8a4c7909 100644 --- a/Software/PC_Application/LibreVNA-GUI/preferences.cpp +++ b/Software/PC_Application/LibreVNA-GUI/preferences.cpp @@ -210,6 +210,9 @@ PreferencesDialog::PreferencesDialog(Preferences *pref, QWidget *parent) : setInitialGUIState(); } }); + connect(ui->AcquisitionLimitTDRCheckbox, &QCheckBox::toggled, [=](bool enabled){ + ui->AcquisitionDFTLimitValue->setEnabled(enabled); + }); setInitialGUIState(); } @@ -257,6 +260,8 @@ void PreferencesDialog::setInitialGUIState() ui->AcquisitionFullSpanStart->setValue(p->Acquisition.fullSpanStart); ui->AcquisitionFullSpanStop->setValue(p->Acquisition.fullSpanStop); ui->AcquisitionFullSpanCalibrated->setChecked(p->Acquisition.fullSpanCalibratedRange); + ui->AcquisitionLimitTDRCheckbox->setChecked(p->Acquisition.limitDFT); + ui->AcquisitionDFTLimitValue->setValue(p->Acquisition.maxDFTrate); ui->GraphsDefaultTransmission->setCurrentText(p->Graphs.defaultGraphs.transmission); ui->GraphsDefaultReflection->setCurrentText(p->Graphs.defaultGraphs.reflection); @@ -354,6 +359,8 @@ void PreferencesDialog::updateFromGUI() p->Acquisition.fullSpanStart = ui->AcquisitionFullSpanStart->value(); p->Acquisition.fullSpanStop = ui->AcquisitionFullSpanStop->value(); p->Acquisition.fullSpanCalibratedRange = ui->AcquisitionFullSpanCalibrated->isChecked(); + p->Acquisition.limitDFT = ui->AcquisitionLimitTDRCheckbox->isChecked(); + p->Acquisition.maxDFTrate = ui->AcquisitionDFTLimitValue->value(); p->Graphs.defaultGraphs.transmission = ui->GraphsDefaultTransmission->currentText(); p->Graphs.defaultGraphs.reflection = ui->GraphsDefaultReflection->currentText(); diff --git a/Software/PC_Application/LibreVNA-GUI/preferences.h b/Software/PC_Application/LibreVNA-GUI/preferences.h index d6d26600..ce3b3d37 100644 --- a/Software/PC_Application/LibreVNA-GUI/preferences.h +++ b/Software/PC_Application/LibreVNA-GUI/preferences.h @@ -104,6 +104,10 @@ class Preferences : public Savable { double fullSpanStart; double fullSpanStop; bool fullSpanCalibratedRange; + + // Math settings + bool limitDFT; + double maxDFTrate; } Acquisition; struct { bool showUnits; @@ -208,6 +212,8 @@ class Preferences : public Savable { {&Acquisition.fullSpanStart, "Acquisition.fullSpanStart", 0.0}, {&Acquisition.fullSpanStop, "Acquisition.fullSpanStop", 6000000000.0}, {&Acquisition.fullSpanCalibratedRange, "Acquisition.fullSpanCalibratedRange", false}, + {&Acquisition.limitDFT, "Acquisition.limitDFT", true}, + {&Acquisition.maxDFTrate, "Acquisition.maxDFTrate", 1.0}, {&Graphs.showUnits, "Graphs.showUnits", true}, {&Graphs.Color.background, "Graphs.Color.background", QColor(Qt::black)}, {&Graphs.Color.axis, "Graphs.Color.axis", QColor(Qt::white)}, diff --git a/Software/PC_Application/LibreVNA-GUI/preferencesdialog.ui b/Software/PC_Application/LibreVNA-GUI/preferencesdialog.ui index ff9c8051..5f6977e3 100644 --- a/Software/PC_Application/LibreVNA-GUI/preferencesdialog.ui +++ b/Software/PC_Application/LibreVNA-GUI/preferencesdialog.ui @@ -93,7 +93,7 @@ - 2 + 1 @@ -824,6 +824,55 @@ + + + + Math operations + + + + + + Limit TDR/DFT to + + + + + + + false + + + 0.100000000000000 + + + 100.000000000000000 + + + + + + + updates per second + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + @@ -1688,8 +1737,8 @@ 0 0 - 168 - 127 + 697 + 563 @@ -1778,8 +1827,8 @@ 0 0 - 215 - 168 + 697 + 563