mirror of https://github.com/f4exb/sdrangel.git
Spectrum averaging (1)
This commit is contained in:
parent
833412dcc2
commit
9fee7b49b5
|
@ -14,6 +14,8 @@ inline double log2f(double n)
|
||||||
|
|
||||||
MESSAGE_CLASS_DEFINITION(SpectrumVis::MsgConfigureSpectrumVis, Message)
|
MESSAGE_CLASS_DEFINITION(SpectrumVis::MsgConfigureSpectrumVis, Message)
|
||||||
|
|
||||||
|
const Real SpectrumVis::m_mult = (10.0f / log2f(10.0f));
|
||||||
|
|
||||||
SpectrumVis::SpectrumVis(Real scalef, GLSpectrum* glSpectrum) :
|
SpectrumVis::SpectrumVis(Real scalef, GLSpectrum* glSpectrum) :
|
||||||
BasebandSampleSink(),
|
BasebandSampleSink(),
|
||||||
m_fft(FFTEngine::create()),
|
m_fft(FFTEngine::create()),
|
||||||
|
@ -96,8 +98,6 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV
|
||||||
m_fft->transform();
|
m_fft->transform();
|
||||||
|
|
||||||
// extract power spectrum and reorder buckets
|
// extract power spectrum and reorder buckets
|
||||||
Real ofs = 20.0f * log10f(1.0f / m_fftSize);
|
|
||||||
Real mult = (10.0f / log2f(10.0f));
|
|
||||||
const Complex* fftOut = m_fft->out();
|
const Complex* fftOut = m_fft->out();
|
||||||
Complex c;
|
Complex c;
|
||||||
Real v;
|
Real v;
|
||||||
|
@ -109,7 +109,8 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV
|
||||||
{
|
{
|
||||||
c = fftOut[i];
|
c = fftOut[i];
|
||||||
v = c.real() * c.real() + c.imag() * c.imag();
|
v = c.real() * c.real() + c.imag() * c.imag();
|
||||||
v = mult * log2f(v) + ofs;
|
v = m_average.storeAndGetAvg(v, i);
|
||||||
|
v = m_mult * log2f(v) + m_ofs;
|
||||||
m_logPowerSpectrum[i * 2] = v;
|
m_logPowerSpectrum[i * 2] = v;
|
||||||
m_logPowerSpectrum[i * 2 + 1] = v;
|
m_logPowerSpectrum[i * 2 + 1] = v;
|
||||||
}
|
}
|
||||||
|
@ -120,18 +121,21 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV
|
||||||
{
|
{
|
||||||
c = fftOut[i + halfSize];
|
c = fftOut[i + halfSize];
|
||||||
v = c.real() * c.real() + c.imag() * c.imag();
|
v = c.real() * c.real() + c.imag() * c.imag();
|
||||||
v = mult * log2f(v) + ofs;
|
v = m_average.storeAndGetAvg(v, i+halfSize);
|
||||||
|
v = m_mult * log2f(v) + m_ofs;
|
||||||
m_logPowerSpectrum[i] = v;
|
m_logPowerSpectrum[i] = v;
|
||||||
|
|
||||||
c = fftOut[i];
|
c = fftOut[i];
|
||||||
v = c.real() * c.real() + c.imag() * c.imag();
|
v = c.real() * c.real() + c.imag() * c.imag();
|
||||||
v = mult * log2f(v) + ofs;
|
v = m_average.storeAndGetAvg(v, i);
|
||||||
|
v = m_mult * log2f(v) + m_ofs;
|
||||||
m_logPowerSpectrum[i + halfSize] = v;
|
m_logPowerSpectrum[i + halfSize] = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// send new data to visualisation
|
// send new data to visualisation
|
||||||
m_glSpectrum->newSpectrum(m_logPowerSpectrum, m_fftSize);
|
m_glSpectrum->newSpectrum(m_logPowerSpectrum, m_fftSize);
|
||||||
|
m_average.nextAverage();
|
||||||
|
|
||||||
// advance buffer respecting the fft overlap factor
|
// advance buffer respecting the fft overlap factor
|
||||||
std::copy(m_fftBuffer.begin() + m_refillSize, m_fftBuffer.end(), m_fftBuffer.begin());
|
std::copy(m_fftBuffer.begin() + m_refillSize, m_fftBuffer.end(), m_fftBuffer.begin());
|
||||||
|
@ -208,4 +212,7 @@ void SpectrumVis::handleConfigure(int fftSize, int overlapPercent, FFTWindow::Fu
|
||||||
m_overlapSize = (m_fftSize * m_overlapPercent) / 100;
|
m_overlapSize = (m_fftSize * m_overlapPercent) / 100;
|
||||||
m_refillSize = m_fftSize - m_overlapSize;
|
m_refillSize = m_fftSize - m_overlapSize;
|
||||||
m_fftBufferFill = m_overlapSize;
|
m_fftBufferFill = m_overlapSize;
|
||||||
|
m_average.resize(fftSize, 10);
|
||||||
|
m_averageNb = 100;
|
||||||
|
m_ofs = 20.0f * log10f(1.0f / m_fftSize);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "dsp/fftwindow.h"
|
#include "dsp/fftwindow.h"
|
||||||
#include "export.h"
|
#include "export.h"
|
||||||
#include "util/message.h"
|
#include "util/message.h"
|
||||||
|
#include "util/movingaverage2d.h"
|
||||||
|
|
||||||
class GLSpectrum;
|
class GLSpectrum;
|
||||||
class MessageQueue;
|
class MessageQueue;
|
||||||
|
@ -62,6 +63,11 @@ private:
|
||||||
|
|
||||||
Real m_scalef;
|
Real m_scalef;
|
||||||
GLSpectrum* m_glSpectrum;
|
GLSpectrum* m_glSpectrum;
|
||||||
|
MovingAverage2D<double> m_average;
|
||||||
|
unsigned int m_averageNb;
|
||||||
|
|
||||||
|
Real m_ofs;
|
||||||
|
static const Real m_mult;
|
||||||
|
|
||||||
QMutex m_mutex;
|
QMutex m_mutex;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue