From 673a145490afc386c7ad848cac4b53b7cdaed8e2 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 16 Oct 2018 23:56:09 +0200 Subject: [PATCH] Spectrum: limit averaging depth to 1000 when in moving average mode to avoid memory exhaustion --- debian/changelog | 1 + sdrgui/dsp/spectrumvis.cpp | 2 +- sdrgui/gui/glspectrumgui.cpp | 15 +++++++++++++++ sdrgui/readme.md | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 899edc393..35ee4c187 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,7 @@ sdrangel (4.2.3-1) unstable; urgency=medium * Scope: fixed channel rate affecting scope in memory mode. Issue #227 + * Spectrum: limit depth to 1000 when in moving average mode to avoid RAM exhaustion -- Edouard Griffiths, F4EXB Sun, 21 Oct 2018 21:14:18 +0200 diff --git a/sdrgui/dsp/spectrumvis.cpp b/sdrgui/dsp/spectrumvis.cpp index 0389cdc91..0fbeb0384 100644 --- a/sdrgui/dsp/spectrumvis.cpp +++ b/sdrgui/dsp/spectrumvis.cpp @@ -364,7 +364,7 @@ void SpectrumVis::handleConfigure(int fftSize, m_overlapSize = (m_fftSize * m_overlapPercent) / 100; m_refillSize = m_fftSize - m_overlapSize; m_fftBufferFill = m_overlapSize; - m_movingAverage.resize(fftSize, averageNb); + m_movingAverage.resize(fftSize, averageNb > 1000 ? 1000 : averageNb); // Capping to avoid out of memory condition m_fixedAverage.resize(fftSize, averageNb); m_max.resize(fftSize, averageNb); m_averageNb = averageNb; diff --git a/sdrgui/gui/glspectrumgui.cpp b/sdrgui/gui/glspectrumgui.cpp index 25eefc448..0d2dc6814 100644 --- a/sdrgui/gui/glspectrumgui.cpp +++ b/sdrgui/gui/glspectrumgui.cpp @@ -246,6 +246,18 @@ void GLSpectrumGUI::on_averagingMode_currentIndexChanged(int index) { m_averagingMode = index < 0 ? AvgModeNone : index > 3 ? AvgModeMax : (AveragingMode) index; + if (m_averagingMode == AvgModeMoving) + { + m_averagingMaxScale = 2; + setAveragingCombo(); + m_averagingNb = m_averagingNb > 1000 ? 1000 : m_averagingNb; + } + else + { + m_averagingMaxScale = 5; + setAveragingCombo(); + } + if(m_spectrumVis != 0) { m_spectrumVis->configure(m_messageQueueToVis, m_fftSize, @@ -507,6 +519,7 @@ int GLSpectrumGUI::getAveragingValue(int averagingIndex) const void GLSpectrumGUI::setAveragingCombo() { + int index = ui->averaging->currentIndex(); ui->averaging->clear(); ui->averaging->addItem(QString("1")); @@ -524,6 +537,8 @@ void GLSpectrumGUI::setAveragingCombo() setNumberStr(x, s); ui->averaging->addItem(s); } + + ui->averaging->setCurrentIndex(index >= ui->averaging->count() ? ui->averaging->count() - 1 : index); } void GLSpectrumGUI::setNumberStr(int n, QString& s) diff --git a/sdrgui/readme.md b/sdrgui/readme.md index 1f6ee8f87..8130633f3 100644 --- a/sdrgui/readme.md +++ b/sdrgui/readme.md @@ -273,7 +273,7 @@ Use this combo to select which averaging mode is applied:

4.6. Number of averaged samples

-Each FFT bin (squared magnitude) is averaged or max'ed over a number of samples. This combo allows selecting the number of samples between these values: 1 (no averaging), 2, 5, 10, 20, 50, 100, 200, 500, 1k (1000), 2k, 5k, 10k, 20k, 50k, 1e5 (100000), 2e5, 5e5, 1M (1000000). The tooltip mentions the resulting averaging period considering the baseband sample rate and FFT size. +Each FFT bin (squared magnitude) is averaged or max'ed over a number of samples. This combo allows selecting the number of samples between these values: 1 (no averaging), 2, 5, 10, 20, 50, 100, 200, 500, 1k (1000) for all modes and in addition 2k, 5k, 10k, 20k, 50k, 1e5 (100000), 2e5, 5e5, 1M (1000000) for "fixed" and "max" modes. The tooltip mentions the resulting averaging period considering the baseband sample rate and FFT size. Averaging reduces the noise variance and can be used to better detect weak continuous signals. The fixed averaging mode allows long time monitoring on the waterfall. The max mode helps showing short bursts that may appear during the "averaging" period. ☞ Note: The spectrum display is refreshed every 50ms (20 FPS). Setting an averaging time above this value will make sure that a short burst is not missed particularly when using the max mode.