mirror of
https://github.com/jankae/LibreVNA.git
synced 2025-12-06 07:12:10 +01:00
continuous updates for TDR/DFT with optional rate limit
This commit is contained in:
parent
5ae57bfa9a
commit
792a6a4974
|
|
@ -7,6 +7,9 @@
|
|||
#include "ui_dftexplanationwidget.h"
|
||||
#include "appwindow.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
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<double>(1.0 / p.Acquisition.maxDFTrate));
|
||||
lastCalc = system_clock::now();
|
||||
}
|
||||
// qDebug() << "DFT thread calculating";
|
||||
double DC = dft.DCfreq;
|
||||
TDR *tdr = nullptr;
|
||||
if(dft.automaticDC) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@
|
|||
#include "Util/util.h"
|
||||
#include "appwindow.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QDebug>
|
||||
|
|
@ -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<double>(1.0 / p.Acquisition.maxDFTrate));
|
||||
lastCalc = system_clock::now();
|
||||
}
|
||||
// qDebug() << "TDR thread calculating";
|
||||
// perform calculation
|
||||
vector<complex<double>> frequencyDomain;
|
||||
auto stepSize = (tdr.input->rData().back().x - tdr.input->rData().front().x) / (tdr.input->rData().size() - 1);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -104,6 +104,10 @@ public:
|
|||
double fullSpanStart;
|
||||
double fullSpanStop;
|
||||
bool fullSpanCalibratedRange;
|
||||
|
||||
// Math settings
|
||||
bool limitDFT;
|
||||
double maxDFTrate;
|
||||
} Acquisition;
|
||||
struct {
|
||||
bool showUnits;
|
||||
|
|
@ -208,6 +212,8 @@ private:
|
|||
{&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)},
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@
|
|||
</size>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>2</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="Startup">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
|
|
@ -824,6 +824,55 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_15">
|
||||
<property name="title">
|
||||
<string>Math operations</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="AcquisitionLimitTDRCheckbox">
|
||||
<property name="text">
|
||||
<string>Limit TDR/DFT to </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="AcquisitionDFTLimitValue">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>100.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_30">
|
||||
<property name="text">
|
||||
<string>updates per second</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_8">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
|
|
@ -1688,8 +1737,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>168</width>
|
||||
<height>127</height>
|
||||
<width>697</width>
|
||||
<height>563</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_12">
|
||||
|
|
@ -1778,8 +1827,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>215</width>
|
||||
<height>168</height>
|
||||
<width>697</width>
|
||||
<height>563</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_19">
|
||||
|
|
|
|||
Loading…
Reference in a new issue