From 0b496bd80041d7ccc1c9a2fdfb441c2ee3cbc651 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 1 Jul 2018 03:11:36 +0200 Subject: [PATCH] Spectrum averaging: fixed average (2) --- sdrgui/gui/glspectrum.cpp | 10 +++++++++- sdrgui/gui/glspectrum.h | 2 ++ sdrgui/gui/glspectrumgui.cpp | 18 ++++++++++++++++++ sdrgui/gui/scaleengine.cpp | 2 +- sdrgui/gui/scaleengine.h | 2 +- 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/sdrgui/gui/glspectrum.cpp b/sdrgui/gui/glspectrum.cpp index 9a511628f..75c55b5f4 100644 --- a/sdrgui/gui/glspectrum.cpp +++ b/sdrgui/gui/glspectrum.cpp @@ -38,6 +38,7 @@ GLSpectrum::GLSpectrum(QWidget* parent) : m_powerRange(100), m_decay(0), m_sampleRate(500000), + m_timingRate(1), m_fftSize(512), m_displayGrid(true), m_displayGridIntensity(5), @@ -196,6 +197,13 @@ void GLSpectrum::setSampleRate(qint32 sampleRate) update(); } +void GLSpectrum::setTimingRate(qint32 timingRate) +{ + m_timingRate = timingRate; + m_changesPending = true; + update(); +} + void GLSpectrum::setDisplayWaterfall(bool display) { m_displayWaterfall = display; @@ -1043,7 +1051,7 @@ void GLSpectrum::applyChanges() if(m_sampleRate > 0) { - float scaleDiv = (float)m_sampleRate * (m_ssbSpectrum ? 2 : 1); + float scaleDiv = ((float)m_sampleRate / (float)m_timingRate) * (m_ssbSpectrum ? 2 : 1); if(!m_invertedWaterfall) { diff --git a/sdrgui/gui/glspectrum.h b/sdrgui/gui/glspectrum.h index 3b2ef97ac..a5e3dce20 100644 --- a/sdrgui/gui/glspectrum.h +++ b/sdrgui/gui/glspectrum.h @@ -46,6 +46,7 @@ public: void setCenterFrequency(qint64 frequency); void setSampleRate(qint32 sampleRate); + void setTimingRate(qint32 timingRate); void setReferenceLevel(Real referenceLevel); void setPowerRange(Real powerRange); void setDecay(int decay); @@ -110,6 +111,7 @@ private: Real m_powerRange; int m_decay; quint32 m_sampleRate; + quint32 m_timingRate; int m_fftSize; diff --git a/sdrgui/gui/glspectrumgui.cpp b/sdrgui/gui/glspectrumgui.cpp index 6933fcf75..36fed96f0 100644 --- a/sdrgui/gui/glspectrumgui.cpp +++ b/sdrgui/gui/glspectrumgui.cpp @@ -229,6 +229,7 @@ void GLSpectrumGUI::on_fftSize_currentIndexChanged(int index) void GLSpectrumGUI::on_averagingMode_currentIndexChanged(int index) { m_averagingMode = index < 0 ? AvgModeMoving : index > 1 ? AvgModeFixed : (AveragingMode) index; + if(m_spectrumVis != 0) { m_spectrumVis->configure(m_messageQueue, m_fftSize, @@ -237,12 +238,22 @@ void GLSpectrumGUI::on_averagingMode_currentIndexChanged(int index) m_averagingMode, (FFTWindow::Function)m_fftWindow); } + + if (m_glSpectrum != 0) + { + if (m_averagingMode == AvgModeFixed) { + m_glSpectrum->setTimingRate(m_averagingNb == 0 ? 1 : m_averagingNb); + } else { + m_glSpectrum->setTimingRate(1); + } + } } void GLSpectrumGUI::on_averaging_currentIndexChanged(int index) { m_averagingIndex = index; m_averagingNb = getAveragingValue(index); + if(m_spectrumVis != 0) { m_spectrumVis->configure(m_messageQueue, m_fftSize, @@ -251,6 +262,13 @@ void GLSpectrumGUI::on_averaging_currentIndexChanged(int index) m_averagingMode, (FFTWindow::Function)m_fftWindow); } + + if (m_glSpectrum != 0) + { + if (m_averagingMode == AvgModeFixed) { + m_glSpectrum->setTimingRate(m_averagingNb == 0 ? 1 : m_averagingNb); + } + } } void GLSpectrumGUI::on_refLevel_currentIndexChanged(int index) diff --git a/sdrgui/gui/scaleengine.cpp b/sdrgui/gui/scaleengine.cpp index 2e921ead7..1ad5c436d 100644 --- a/sdrgui/gui/scaleengine.cpp +++ b/sdrgui/gui/scaleengine.cpp @@ -29,7 +29,7 @@ static double trunc(double d) QString ScaleEngine::formatTick(double value, int decimalPlaces, bool fancyTime) { - if((m_physicalUnit != Unit::Time) || (!fancyTime) || 1) + if((m_physicalUnit != Unit::Time) || (!fancyTime)) { return QString("%1").arg(m_makeOpposite ? -value : value, 0, 'f', decimalPlaces); } diff --git a/sdrgui/gui/scaleengine.h b/sdrgui/gui/scaleengine.h index a66f6b093..0f4e20083 100644 --- a/sdrgui/gui/scaleengine.h +++ b/sdrgui/gui/scaleengine.h @@ -58,7 +58,7 @@ private: int m_decimalPlaces; bool m_makeOpposite; // will show -value instead of value - QString formatTick(double value, int decimalPlaces, bool fancyTime = true); + QString formatTick(double value, int decimalPlaces, bool fancyTime = false); void calcCharSize(); void calcScaleFactor(); double calcMajorTickUnits(double distance, int* retDecimalPlaces);