diff --git a/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.cpp b/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.cpp index feed9f3..8c0e7ae 100644 --- a/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.cpp +++ b/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.cpp @@ -215,6 +215,12 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window, QString name) connect(sbAverages, qOverload(&QSpinBox::valueChanged), this, &SpectrumAnalyzer::SetAveraging); connect(this, &SpectrumAnalyzer::averagingChanged, sbAverages, &QSpinBox::setValue); tb_acq->addWidget(sbAverages); + auto bResetAvg = new QPushButton("Reset"); + connect(bResetAvg, &QPushButton::clicked, this, [=](){ + average.reset(DeviceDriver::SApoints()); + UpdateAverageCount(); + }); + tb_acq->addWidget(bResetAvg); window->addToolBar(tb_acq); toolbars.insert(tb_acq); @@ -696,7 +702,7 @@ void SpectrumAnalyzer::SetAveraging(unsigned int averages) this->averages = averages; average.setAverages(averages); emit averagingChanged(averages); - SettingsChanged(); + UpdateAverageCount(); } void SpectrumAnalyzer::SetTGEnabled(bool enabled) diff --git a/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp b/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp index ad535bb..e46eca0 100644 --- a/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp +++ b/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp @@ -431,6 +431,12 @@ VNA::VNA(AppWindow *window, QString name) connect(sbAverages, qOverload(&QSpinBox::valueChanged), this, &VNA::SetAveraging); connect(this, &VNA::averagingChanged, sbAverages, &QSpinBox::setValue); tb_acq->addWidget(sbAverages); + auto bResetAvg = new QPushButton("Reset"); + connect(bResetAvg, &QPushButton::clicked, this, [=](){ + average.reset(settings.npoints); + UpdateAverageCount(); + }); + tb_acq->addWidget(bResetAvg); window->addToolBar(tb_acq); toolbars.insert(tb_acq); @@ -1211,7 +1217,7 @@ void VNA::SetAveraging(unsigned int averages) this->averages = averages; average.setAverages(averages); emit averagingChanged(averages); - SettingsChanged(); + UpdateAverageCount(); } void VNA::ExcitationRequired() diff --git a/Software/PC_Application/LibreVNA-GUI/averaging.cpp b/Software/PC_Application/LibreVNA-GUI/averaging.cpp index a392b4c..341f72c 100644 --- a/Software/PC_Application/LibreVNA-GUI/averaging.cpp +++ b/Software/PC_Application/LibreVNA-GUI/averaging.cpp @@ -20,7 +20,12 @@ void Averaging::reset(unsigned int points) void Averaging::setAverages(unsigned int a) { averages = a; - reset(avg.size()); + // throw away additional stored data if averaging has been reduced + for(auto &d : avg) { + while(d.size() > averages) { + d.pop_front(); + } + } } DeviceDriver::VNAMeasurement Averaging::process(DeviceDriver::VNAMeasurement d) @@ -109,7 +114,7 @@ void Averaging::process(unsigned int pointNum, std::vector> // add newest sample to queue deque->push_back(data); // remove oldest sample if required number of averages reached - if(deque->size() > averages) { + while(deque->size() > averages) { deque->pop_front(); }