diff --git a/sdrgui/dsp/spectrumvis.cpp b/sdrgui/dsp/spectrumvis.cpp index f3d30aef7..2c1542ec8 100644 --- a/sdrgui/dsp/spectrumvis.cpp +++ b/sdrgui/dsp/spectrumvis.cpp @@ -26,12 +26,12 @@ SpectrumVis::SpectrumVis(Real scalef, GLSpectrum* glSpectrum) : m_scalef(scalef), m_glSpectrum(glSpectrum), m_averageNb(0), - m_averagingMode(AvgModeMoving), + m_averagingMode(AvgModeNone), m_ofs(0), m_mutex(QMutex::Recursive) { setObjectName("SpectrumVis"); - handleConfigure(1024, 0, 0, AvgModeMoving, FFTWindow::BlackmanHarris); + handleConfigure(1024, 0, 0, AvgModeNone, FFTWindow::BlackmanHarris); } SpectrumVis::~SpectrumVis() @@ -111,7 +111,39 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV Real v; std::size_t halfSize = m_fftSize / 2; - if (m_averagingMode == AvgModeMoving) + if (m_averagingMode == AvgModeNone) + { + if ( positiveOnly ) + { + for (std::size_t i = 0; i < halfSize; i++) + { + c = fftOut[i]; + v = c.real() * c.real() + c.imag() * c.imag(); + v = m_mult * log2f(v) + m_ofs; + m_logPowerSpectrum[i * 2] = v; + m_logPowerSpectrum[i * 2 + 1] = v; + } + } + else + { + for (std::size_t i = 0; i < halfSize; i++) + { + c = fftOut[i + halfSize]; + v = c.real() * c.real() + c.imag() * c.imag(); + v = m_mult * log2f(v) + m_ofs; + m_logPowerSpectrum[i] = v; + + c = fftOut[i]; + v = c.real() * c.real() + c.imag() * c.imag(); + v = m_mult * log2f(v) + m_ofs; + m_logPowerSpectrum[i + halfSize] = v; + } + } + + // send new data to visualisation + m_glSpectrum->newSpectrum(m_logPowerSpectrum, m_fftSize); + } + else if (m_averagingMode == AvgModeMoving) { if ( positiveOnly ) { diff --git a/sdrgui/dsp/spectrumvis.h b/sdrgui/dsp/spectrumvis.h index e2b81c2ca..e6832627a 100644 --- a/sdrgui/dsp/spectrumvis.h +++ b/sdrgui/dsp/spectrumvis.h @@ -18,6 +18,7 @@ class SDRGUI_API SpectrumVis : public BasebandSampleSink { public: enum AveragingMode { + AvgModeNone, AvgModeMoving, AvgModeFixed }; @@ -33,7 +34,7 @@ public: m_averageNb(averageNb), m_window(window) { - m_averagingMode = averagingMode < 0 ? AvgModeMoving : averagingMode > 1 ? AvgModeFixed : (SpectrumVis::AveragingMode) averagingMode; + m_averagingMode = averagingMode < 0 ? AvgModeNone : averagingMode > 2 ? AvgModeFixed : (SpectrumVis::AveragingMode) averagingMode; } int getFFTSize() const { return m_fftSize; } diff --git a/sdrgui/gui/glspectrumgui.cpp b/sdrgui/gui/glspectrumgui.cpp index 1567093be..a22343e42 100644 --- a/sdrgui/gui/glspectrumgui.cpp +++ b/sdrgui/gui/glspectrumgui.cpp @@ -28,7 +28,7 @@ GLSpectrumGUI::GLSpectrumGUI(QWidget* parent) : m_displayHistogram(false), m_displayGrid(false), m_invert(true), - m_averagingMode(AvgModeMoving), + m_averagingMode(AvgModeNone), m_averagingIndex(0), m_averagingMaxScale(2), m_averagingNb(0) @@ -75,7 +75,7 @@ void GLSpectrumGUI::resetToDefaults() m_displayHistogram = false; m_displayGrid = false; m_invert = true; - m_averagingMode = AvgModeMoving; + m_averagingMode = AvgModeNone; m_averagingIndex = 0; applySettings(); } @@ -138,7 +138,7 @@ bool GLSpectrumGUI::deserialize(const QByteArray& data) Real waterfallShare; d.readReal(18, &waterfallShare, 0.66); d.readS32(19, &tmp, 0); - m_averagingMode = tmp < 0 ? AvgModeMoving : tmp > 1 ? AvgModeFixed : (AveragingMode) tmp; + m_averagingMode = tmp < 0 ? AvgModeNone : tmp > 2 ? AvgModeFixed : (AveragingMode) tmp; d.readS32(20, &tmp, 0); m_averagingIndex = getAveragingIndex(tmp); m_averagingNb = getAveragingValue(m_averagingIndex); @@ -235,7 +235,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; + m_averagingMode = index < 0 ? AvgModeNone : index > 2 ? AvgModeFixed : (AveragingMode) index; if(m_spectrumVis != 0) { m_spectrumVis->configure(m_messageQueueToVis, diff --git a/sdrgui/gui/glspectrumgui.h b/sdrgui/gui/glspectrumgui.h index 2028bda91..773274595 100644 --- a/sdrgui/gui/glspectrumgui.h +++ b/sdrgui/gui/glspectrumgui.h @@ -20,6 +20,7 @@ class SDRGUI_API GLSpectrumGUI : public QWidget, public Serializable { public: enum AveragingMode { + AvgModeNone, AvgModeMoving, AvgModeFixed }; diff --git a/sdrgui/gui/glspectrumgui.ui b/sdrgui/gui/glspectrumgui.ui index d563cb4a6..ed90ebf08 100644 --- a/sdrgui/gui/glspectrumgui.ui +++ b/sdrgui/gui/glspectrumgui.ui @@ -547,6 +547,11 @@ Averaging type + + + No + + Mov