1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-23 00:18:37 -05:00

Moving average cleanup

This commit is contained in:
f4exb 2018-02-03 10:33:02 +01:00
parent 4cd6d5bd6e
commit b0a97510e2
47 changed files with 108 additions and 152 deletions

View File

@ -196,8 +196,8 @@ void ChannelAnalyzerGUI::channelMarkerHighlightedByCursor()
void ChannelAnalyzerGUI::tick() void ChannelAnalyzerGUI::tick()
{ {
Real powDb = CalcDb::dbPower(m_channelAnalyzer->getMagSq()); Real powDb = CalcDb::dbPower(m_channelAnalyzer->getMagSq());
m_channelPowerDbAvg.feed(powDb); m_channelPowerDbAvg(powDb);
ui->channelPower->setText(QString::number(m_channelPowerDbAvg.average(), 'f', 1)); ui->channelPower->setText(QString::number((Real) m_channelPowerDbAvg, 'f', 1));
} }
void ChannelAnalyzerGUI::on_deltaMinus_toggled(bool minus) void ChannelAnalyzerGUI::on_deltaMinus_toggled(bool minus)
@ -331,8 +331,7 @@ ChannelAnalyzerGUI::ChannelAnalyzerGUI(PluginAPI* pluginAPI, DeviceUISet *device
m_channelMarker(this), m_channelMarker(this),
m_doApplySettings(true), m_doApplySettings(true),
m_rate(6000), m_rate(6000),
m_spanLog2(3), m_spanLog2(3)
m_channelPowerDbAvg(40,0)
{ {
ui->setupUi(this); ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose, true); setAttribute(Qt::WA_DeleteOnClose, true);

View File

@ -20,7 +20,8 @@
#include <plugin/plugininstancegui.h> #include <plugin/plugininstancegui.h>
#include "gui/rollupwidget.h" #include "gui/rollupwidget.h"
#include "dsp/channelmarker.h" #include "dsp/channelmarker.h"
#include "dsp/movingaverage.h" #include "dsp/dsptypes.h"
#include "util/movingaverage.h"
#include "util/messagequeue.h" #include "util/messagequeue.h"
class PluginAPI; class PluginAPI;
@ -65,7 +66,7 @@ private:
bool m_doApplySettings; bool m_doApplySettings;
int m_rate; int m_rate;
int m_spanLog2; int m_spanLog2;
MovingAverage<Real> m_channelPowerDbAvg; MovingAverageUtil<Real, double, 40> m_channelPowerDbAvg;
ChannelAnalyzer* m_channelAnalyzer; ChannelAnalyzer* m_channelAnalyzer;
SpectrumScopeComboVis* m_spectrumScopeComboVis; SpectrumScopeComboVis* m_spectrumScopeComboVis;

View File

@ -235,8 +235,8 @@ void ChannelAnalyzerNGGUI::channelMarkerHighlightedByCursor()
void ChannelAnalyzerNGGUI::tick() void ChannelAnalyzerNGGUI::tick()
{ {
double powDb = CalcDb::dbPower(m_channelAnalyzer->getMagSq()); double powDb = CalcDb::dbPower(m_channelAnalyzer->getMagSq());
m_channelPowerDbAvg.feed(powDb); m_channelPowerDbAvg(powDb);
ui->channelPower->setText(tr("%1 dB").arg(m_channelPowerDbAvg.average(), 0, 'f', 1)); ui->channelPower->setText(tr("%1 dB").arg((Real) m_channelPowerDbAvg, 0, 'f', 1));
} }
void ChannelAnalyzerNGGUI::on_channelSampleRate_changed(quint64 value) void ChannelAnalyzerNGGUI::on_channelSampleRate_changed(quint64 value)
@ -388,8 +388,7 @@ ChannelAnalyzerNGGUI::ChannelAnalyzerNGGUI(PluginAPI* pluginAPI, DeviceUISet *de
m_channelMarker(this), m_channelMarker(this),
m_doApplySettings(true), m_doApplySettings(true),
m_rate(6000), m_rate(6000),
m_spanLog2(0), m_spanLog2(0)
m_channelPowerDbAvg(40,0)
{ {
ui->setupUi(this); ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose, true); setAttribute(Qt::WA_DeleteOnClose, true);

View File

@ -20,7 +20,8 @@
#include <plugin/plugininstancegui.h> #include <plugin/plugininstancegui.h>
#include "gui/rollupwidget.h" #include "gui/rollupwidget.h"
#include "dsp/channelmarker.h" #include "dsp/channelmarker.h"
#include "dsp/movingaverage.h" #include "dsp/dsptypes.h"
#include "util/movingaverage.h"
#include "util/messagequeue.h" #include "util/messagequeue.h"
class PluginAPI; class PluginAPI;
@ -65,7 +66,7 @@ private:
bool m_doApplySettings; bool m_doApplySettings;
int m_rate; //!< sample rate after final in-channel decimation (spanlog2) int m_rate; //!< sample rate after final in-channel decimation (spanlog2)
int m_spanLog2; int m_spanLog2;
MovingAverage<double> m_channelPowerDbAvg; MovingAverageUtil<Real, double, 40> m_channelPowerDbAvg;
ChannelAnalyzerNG* m_channelAnalyzer; ChannelAnalyzerNG* m_channelAnalyzer;
SpectrumScopeNGComboVis* m_spectrumScopeComboVis; SpectrumScopeNGComboVis* m_spectrumScopeComboVis;

View File

@ -45,7 +45,6 @@ AMDemod::AMDemod(DeviceSourceAPI *deviceAPI) :
m_magsqSum(0.0f), m_magsqSum(0.0f),
m_magsqPeak(0.0f), m_magsqPeak(0.0f),
m_magsqCount(0), m_magsqCount(0),
m_movingAverage(40, 0),
m_volumeAGC(1200, 1.0), m_volumeAGC(1200, 1.0),
m_audioFifo(48000), m_audioFifo(48000),
m_settingsMutex(QMutex::Recursive) m_settingsMutex(QMutex::Recursive)
@ -55,7 +54,6 @@ AMDemod::AMDemod(DeviceSourceAPI *deviceAPI) :
m_audioBuffer.resize(1<<14); m_audioBuffer.resize(1<<14);
m_audioBufferFill = 0; m_audioBufferFill = 0;
m_movingAverage.resize(16, 0);
m_volumeAGC.resize(4096, 0.003, 0); m_volumeAGC.resize(4096, 0.003, 0);
m_magsq = 0.0; m_magsq = 0.0;

View File

@ -24,7 +24,7 @@
#include "channel/channelsinkapi.h" #include "channel/channelsinkapi.h"
#include "dsp/nco.h" #include "dsp/nco.h"
#include "dsp/interpolator.h" #include "dsp/interpolator.h"
#include "dsp/movingaverage.h" #include "util/movingaverage.h"
#include "dsp/agc.h" #include "dsp/agc.h"
#include "dsp/bandpass.h" #include "dsp/bandpass.h"
#include "audio/audiofifo.h" #include "audio/audiofifo.h"
@ -143,7 +143,7 @@ private:
double m_magsqPeak; double m_magsqPeak;
int m_magsqCount; int m_magsqCount;
MovingAverage<double> m_movingAverage; MovingAverageUtil<Real, double, 16> m_movingAverage;
SimpleAGC m_volumeAGC; SimpleAGC m_volumeAGC;
Bandpass<Real> m_bandpass; Bandpass<Real> m_bandpass;
@ -164,8 +164,8 @@ private:
Real re = ci.real() / SDR_RX_SCALED; Real re = ci.real() / SDR_RX_SCALED;
Real im = ci.imag() / SDR_RX_SCALED; Real im = ci.imag() / SDR_RX_SCALED;
Real magsq = re*re + im*im; Real magsq = re*re + im*im;
m_movingAverage.feed(magsq); m_movingAverage(magsq);
m_magsq = m_movingAverage.average(); m_magsq = m_movingAverage.asDouble();
m_magsqSum += magsq; m_magsqSum += magsq;
if (magsq > m_magsqPeak) if (magsq > m_magsqPeak)

View File

@ -60,7 +60,6 @@ ATVDemod::ATVDemod(DeviceSourceAPI *deviceAPI) :
m_intRowIndex(0), m_intRowIndex(0),
m_intLineIndex(0), m_intLineIndex(0),
m_objAvgColIndex(3), m_objAvgColIndex(3),
m_objMagSqAverage(40, 0),
m_bfoPLL(200/1000000, 100/1000000, 0.01), m_bfoPLL(200/1000000, 100/1000000, 0.01),
m_bfoFilter(200.0, 1000000.0, 0.9), m_bfoFilter(200.0, 1000000.0, 0.9),
m_interpolatorDistance(1.0f), m_interpolatorDistance(1.0f),
@ -78,8 +77,6 @@ ATVDemod::ATVDemod(DeviceSourceAPI *deviceAPI) :
m_intNumberOfLines=0; m_intNumberOfLines=0;
m_interleaved = true; m_interleaved = true;
m_objMagSqAverage.resize(32, 1.0);
m_DSBFilter = new fftfilt((2.0f * m_rfConfig.m_fltRFBandwidth) / 1000000, 2 * m_ssbFftLen); // arbitrary 1 MS/s sample rate m_DSBFilter = new fftfilt((2.0f * m_rfConfig.m_fltRFBandwidth) / 1000000, 2 * m_ssbFftLen); // arbitrary 1 MS/s sample rate
m_DSBFilterBuffer = new Complex[m_ssbFftLen]; m_DSBFilterBuffer = new Complex[m_ssbFftLen];
memset(m_DSBFilterBuffer, 0, sizeof(Complex)*(m_ssbFftLen)); memset(m_DSBFilterBuffer, 0, sizeof(Complex)*(m_ssbFftLen));
@ -281,7 +278,7 @@ void ATVDemod::demod(Complex& c)
{ {
//Amplitude FM //Amplitude FM
magSq = fltI*fltI + fltQ*fltQ; magSq = fltI*fltI + fltQ*fltQ;
m_objMagSqAverage.feed(magSq); m_objMagSqAverage(magSq);
fltNorm = sqrt(magSq); fltNorm = sqrt(magSq);
fltNormI= fltI/fltNorm; fltNormI= fltI/fltNorm;
fltNormQ= fltQ/fltNorm; fltNormQ= fltQ/fltNorm;
@ -336,7 +333,7 @@ void ATVDemod::demod(Complex& c)
{ {
//Amplitude AM //Amplitude AM
magSq = fltI*fltI + fltQ*fltQ; magSq = fltI*fltI + fltQ*fltQ;
m_objMagSqAverage.feed(magSq); m_objMagSqAverage(magSq);
fltNorm = sqrt(magSq); fltNorm = sqrt(magSq);
fltVal = fltNorm / SDR_RX_SCALEF; fltVal = fltNorm / SDR_RX_SCALEF;
@ -359,7 +356,7 @@ void ATVDemod::demod(Complex& c)
else if ((m_rfRunning.m_enmModulation == ATV_USB) || (m_rfRunning.m_enmModulation == ATV_LSB)) else if ((m_rfRunning.m_enmModulation == ATV_USB) || (m_rfRunning.m_enmModulation == ATV_LSB))
{ {
magSq = fltI*fltI + fltQ*fltQ; magSq = fltI*fltI + fltQ*fltQ;
m_objMagSqAverage.feed(magSq); m_objMagSqAverage(magSq);
fltNorm = sqrt(magSq); fltNorm = sqrt(magSq);
Real bfoValues[2]; Real bfoValues[2];
@ -398,13 +395,13 @@ void ATVDemod::demod(Complex& c)
float rawDeviation; float rawDeviation;
fltVal = m_objPhaseDiscri.phaseDiscriminatorDelta(c, magSq, rawDeviation) + 0.5f; fltVal = m_objPhaseDiscri.phaseDiscriminatorDelta(c, magSq, rawDeviation) + 0.5f;
//fltVal = fltVal < 0.0f ? 0.0f : fltVal > 1.0f ? 1.0f : fltVal; //fltVal = fltVal < 0.0f ? 0.0f : fltVal > 1.0f ? 1.0f : fltVal;
m_objMagSqAverage.feed(magSq); m_objMagSqAverage(magSq);
fltNorm = sqrt(magSq); fltNorm = sqrt(magSq);
} }
else else
{ {
magSq = fltI*fltI + fltQ*fltQ; magSq = fltI*fltI + fltQ*fltQ;
m_objMagSqAverage.feed(magSq); m_objMagSqAverage(magSq);
fltNorm = sqrt(magSq); fltNorm = sqrt(magSq);
fltVal = 0.0f; fltVal = 0.0f;
} }

View File

@ -29,7 +29,7 @@
#include "dsp/downchannelizer.h" #include "dsp/downchannelizer.h"
#include "dsp/nco.h" #include "dsp/nco.h"
#include "dsp/interpolator.h" #include "dsp/interpolator.h"
#include "dsp/movingaverage.h" #include "util/movingaverage.h"
#include "dsp/fftfilt.h" #include "dsp/fftfilt.h"
#include "dsp/agc.h" #include "dsp/agc.h"
#include "dsp/phaselock.h" #include "dsp/phaselock.h"
@ -234,7 +234,7 @@ public:
void setATVScreen(ATVScreenInterface *objScreen); void setATVScreen(ATVScreenInterface *objScreen);
int getSampleRate(); int getSampleRate();
int getEffectiveSampleRate(); int getEffectiveSampleRate();
double getMagSq() const { return m_objMagSqAverage.average(); } //!< Beware this is scaled to 2^30 double getMagSq() const { return m_objMagSqAverage; } //!< Beware this is scaled to 2^30
bool getBFOLocked(); bool getBFOLocked();
static const QString m_channelIdURI; static const QString m_channelIdURI;
@ -457,7 +457,7 @@ private:
//*************** RF *************** //*************** RF ***************
MovingAverage<double> m_objMagSqAverage; MovingAverageUtil<double, double, 32> m_objMagSqAverage;
NCO m_nco; NCO m_nco;
SimplePhaseLock m_bfoPLL; SimplePhaseLock m_bfoPLL;

View File

@ -274,7 +274,6 @@ ATVDemodGUI::ATVDemodGUI(PluginAPI* objPluginAPI, DeviceUISet *deviceUISet, Base
m_deviceUISet(deviceUISet), m_deviceUISet(deviceUISet),
m_channelMarker(this), m_channelMarker(this),
m_blnDoApplySettings(true), m_blnDoApplySettings(true),
m_objMagSqAverage(40, 0),
m_intTickCount(0), m_intTickCount(0),
m_inputSampleRate(48000) m_inputSampleRate(48000)
{ {
@ -308,8 +307,6 @@ ATVDemodGUI::ATVDemodGUI(PluginAPI* objPluginAPI, DeviceUISet *deviceUISet, Base
m_deviceUISet->addChannelMarker(&m_channelMarker); m_deviceUISet->addChannelMarker(&m_channelMarker);
m_deviceUISet->addRollupWidget(this); m_deviceUISet->addRollupWidget(this);
m_objMagSqAverage.resize(4, 1.0);
ui->scopeGUI->setBuddies(m_scopeVis->getInputMessageQueue(), m_scopeVis, ui->glScope); ui->scopeGUI->setBuddies(m_scopeVis->getInputMessageQueue(), m_scopeVis, ui->glScope);
resetToDefaults(); // does applySettings() resetToDefaults(); // does applySettings()
@ -473,8 +470,8 @@ void ATVDemodGUI::tick()
{ {
if (m_atvDemod) if (m_atvDemod)
{ {
m_objMagSqAverage.feed(m_atvDemod->getMagSq()); m_objMagSqAverage(m_atvDemod->getMagSq());
double magSqDB = CalcDb::dbPower(m_objMagSqAverage.average() / (SDR_RX_SCALED*SDR_RX_SCALED)); double magSqDB = CalcDb::dbPower(m_objMagSqAverage / (SDR_RX_SCALED*SDR_RX_SCALED));
ui->channePowerText->setText(tr("%1 dB").arg(magSqDB, 0, 'f', 1)); ui->channePowerText->setText(tr("%1 dB").arg(magSqDB, 0, 'f', 1));
if (m_atvDemod->getBFOLocked()) { if (m_atvDemod->getBFOLocked()) {

View File

@ -21,7 +21,7 @@
#include <plugin/plugininstancegui.h> #include <plugin/plugininstancegui.h>
#include "gui/rollupwidget.h" #include "gui/rollupwidget.h"
#include "dsp/channelmarker.h" #include "dsp/channelmarker.h"
#include "dsp/movingaverage.h" #include "util/movingaverage.h"
#include "util/messagequeue.h" #include "util/messagequeue.h"
class PluginAPI; class PluginAPI;
@ -67,7 +67,7 @@ private:
bool m_blnDoApplySettings; bool m_blnDoApplySettings;
MovingAverage<double> m_objMagSqAverage; MovingAverageUtil<double, double, 4> m_objMagSqAverage;
int m_intTickCount; int m_intTickCount;
ScopeVisNG* m_scopeVis; ScopeVisNG* m_scopeVis;

View File

@ -330,7 +330,6 @@ BFMDemodGUI::BFMDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseban
m_deviceUISet(deviceUISet), m_deviceUISet(deviceUISet),
m_channelMarker(this), m_channelMarker(this),
m_rdsTimerCount(0), m_rdsTimerCount(0),
m_channelPowerDbAvg(20,0),
m_rate(625000) m_rate(625000)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -485,10 +484,6 @@ void BFMDemodGUI::tick()
ui->channelPower->setText(QString::number(powDbAvg, 'f', 1)); ui->channelPower->setText(QString::number(powDbAvg, 'f', 1));
// Real powDb = CalcDb::dbPower(m_bfmDemod->getMagSq());
// m_channelPowerDbAvg.feed(powDb);
// ui->channelPower->setText(QString::number(m_channelPowerDbAvg.average(), 'f', 1));
Real pilotPowDb = CalcDb::dbPower(m_bfmDemod->getPilotLevel()); Real pilotPowDb = CalcDb::dbPower(m_bfmDemod->getPilotLevel());
QString pilotPowDbStr; QString pilotPowDbStr;
pilotPowDbStr.sprintf("%+02.1f", pilotPowDb); pilotPowDbStr.sprintf("%+02.1f", pilotPowDb);

View File

@ -21,7 +21,6 @@
#include <plugin/plugininstancegui.h> #include <plugin/plugininstancegui.h>
#include "gui/rollupwidget.h" #include "gui/rollupwidget.h"
#include "dsp/channelmarker.h" #include "dsp/channelmarker.h"
#include "dsp/movingaverage.h"
#include "util/messagequeue.h" #include "util/messagequeue.h"
#include "bfmdemodsettings.h" #include "bfmdemodsettings.h"
@ -71,7 +70,6 @@ private:
SpectrumVis* m_spectrumVis; SpectrumVis* m_spectrumVis;
BFMDemod* m_bfmDemod; BFMDemod* m_bfmDemod;
MovingAverage<double> m_channelPowerDbAvg;
int m_rate; int m_rate;
std::vector<unsigned int> m_g14ComboIndex; std::vector<unsigned int> m_g14ComboIndex;
MessageQueue m_inputMessageQueue; MessageQueue m_inputMessageQueue;

View File

@ -17,6 +17,8 @@
#ifndef PLUGINS_CHANNELRX_DEMODBFM_BFMDEMODSETTINGS_H_ #ifndef PLUGINS_CHANNELRX_DEMODBFM_BFMDEMODSETTINGS_H_
#define PLUGINS_CHANNELRX_DEMODBFM_BFMDEMODSETTINGS_H_ #define PLUGINS_CHANNELRX_DEMODBFM_BFMDEMODSETTINGS_H_
#include "dsp/dsptypes.h"
class Serializable; class Serializable;
struct BFMDemodSettings struct BFMDemodSettings

View File

@ -51,7 +51,6 @@ DSDDemod::DSDDemod(DeviceSourceAPI *deviceAPI) :
m_squelchGate(0), m_squelchGate(0),
m_squelchLevel(1e-4), m_squelchLevel(1e-4),
m_squelchOpen(false), m_squelchOpen(false),
m_movingAverage(40, 0),
m_fmExcursion(24), m_fmExcursion(24),
m_audioFifo1(48000), m_audioFifo1(48000),
m_audioFifo2(48000), m_audioFifo2(48000),
@ -69,7 +68,6 @@ DSDDemod::DSDDemod(DeviceSourceAPI *deviceAPI) :
m_sampleBufferIndex = 0; m_sampleBufferIndex = 0;
m_scaleFromShort = SDR_RX_SAMP_SZ < sizeof(short)*8 ? 1 : 1<<(SDR_RX_SAMP_SZ - sizeof(short)*8); m_scaleFromShort = SDR_RX_SAMP_SZ < sizeof(short)*8 ? 1 : 1<<(SDR_RX_SAMP_SZ - sizeof(short)*8);
m_movingAverage.resize(16, 0);
m_magsq = 0.0f; m_magsq = 0.0f;
m_magsqSum = 0.0f; m_magsqSum = 0.0f;
m_magsqPeak = 0.0f; m_magsqPeak = 0.0f;
@ -133,7 +131,7 @@ void DSDDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
Real re = ci.real() / SDR_RX_SCALED; Real re = ci.real() / SDR_RX_SCALED;
Real im = ci.imag() / SDR_RX_SCALED; Real im = ci.imag() / SDR_RX_SCALED;
Real magsq = re*re + im*im; Real magsq = re*re + im*im;
m_movingAverage.feed(magsq); m_movingAverage(magsq);
m_magsqSum += magsq; m_magsqSum += magsq;
@ -149,7 +147,7 @@ void DSDDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
// AF processing // AF processing
if (m_movingAverage.average() > m_squelchLevel) if (m_movingAverage.asDouble() > m_squelchLevel)
{ {
if (m_squelchGate > 0) if (m_squelchGate > 0)
{ {

View File

@ -29,7 +29,7 @@
#include "dsp/lowpass.h" #include "dsp/lowpass.h"
#include "dsp/bandpass.h" #include "dsp/bandpass.h"
#include "dsp/afsquelch.h" #include "dsp/afsquelch.h"
#include "dsp/movingaverage.h" #include "util/movingaverage.h"
#include "dsp/afsquelch.h" #include "dsp/afsquelch.h"
#include "audio/audiofifo.h" #include "audio/audiofifo.h"
#include "util/message.h" #include "util/message.h"
@ -175,7 +175,7 @@ private:
double m_squelchLevel; double m_squelchLevel;
bool m_squelchOpen; bool m_squelchOpen;
MovingAverage<double> m_movingAverage; MovingAverageUtil<Real, double, 16> m_movingAverage;
double m_magsq; double m_magsq;
double m_magsqSum; double m_magsqSum;
double m_magsqPeak; double m_magsqPeak;

View File

@ -62,7 +62,6 @@ NFMDemod::NFMDemod(DeviceSourceAPI *devieAPI) :
m_magsqSum(0.0f), m_magsqSum(0.0f),
m_magsqPeak(0.0f), m_magsqPeak(0.0f),
m_magsqCount(0), m_magsqCount(0),
m_movingAverage(40, 0),
m_afSquelch(2, afSqTones), m_afSquelch(2, afSqTones),
m_fmExcursion(2400), m_fmExcursion(2400),
m_audioFifo(48000), m_audioFifo(48000),
@ -74,7 +73,6 @@ NFMDemod::NFMDemod(DeviceSourceAPI *devieAPI) :
m_audioBufferFill = 0; m_audioBufferFill = 0;
m_agcLevel = 1.0; m_agcLevel = 1.0;
m_movingAverage.resize(32, 0);
m_ctcssDetector.setCoefficients(3000, 6000.0); // 0.5s / 2 Hz resolution m_ctcssDetector.setCoefficients(3000, 6000.0); // 0.5s / 2 Hz resolution
m_afSquelch.setCoefficients(24, 600, 48000.0, 200, 0); // 0.5ms test period, 300ms average span, 48kS/s SR, 100ms attack, no decay m_afSquelch.setCoefficients(24, 600, 48000.0, 200, 0); // 0.5ms test period, 300ms average span, 48kS/s SR, 100ms attack, no decay
@ -162,7 +160,7 @@ void NFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
Real demod = m_phaseDiscri.phaseDiscriminatorDelta(ci, magsqRaw, deviation); Real demod = m_phaseDiscri.phaseDiscriminatorDelta(ci, magsqRaw, deviation);
Real magsq = magsqRaw / (SDR_RX_SCALED*SDR_RX_SCALED); Real magsq = magsqRaw / (SDR_RX_SCALED*SDR_RX_SCALED);
m_movingAverage.feed(magsq); m_movingAverage(magsq);
m_magsqSum += magsq; m_magsqSum += magsq;
if (magsq > m_magsqPeak) if (magsq > m_magsqPeak)
@ -198,7 +196,7 @@ void NFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
} }
else else
{ {
if (m_movingAverage.average() < m_squelchLevel) if ((Real) m_movingAverage < m_squelchLevel)
{ {
if (m_squelchCount > 0) if (m_squelchCount > 0)
{ {
@ -464,7 +462,7 @@ void NFMDemod::applySettings(const NFMDemodSettings& settings, bool force)
else else
{ // input is a value in centi-Bels { // input is a value in centi-Bels
m_squelchLevel = std::pow(10.0, settings.m_squelch / 100.0); m_squelchLevel = std::pow(10.0, settings.m_squelch / 100.0);
m_movingAverage.fill(0.0); m_movingAverage.reset();
} }
m_squelchCount = 0; // reset squelch open counter m_squelchCount = 0; // reset squelch open counter

View File

@ -33,6 +33,7 @@
#include "dsp/ctcssdetector.h" #include "dsp/ctcssdetector.h"
#include "audio/audiofifo.h" #include "audio/audiofifo.h"
#include "util/message.h" #include "util/message.h"
#include "util/movingaverage.h"
#include "nfmdemodsettings.h" #include "nfmdemodsettings.h"
@ -200,7 +201,7 @@ private:
Real m_lastArgument; Real m_lastArgument;
//Complex m_m1Sample; //Complex m_m1Sample;
//Complex m_m2Sample; //Complex m_m2Sample;
MovingAverage<double> m_movingAverage; MovingAverageUtil<Real, double, 32> m_movingAverage;
AFSquelch m_afSquelch; AFSquelch m_afSquelch;
Real m_agcLevel; // AGC will aim to this level Real m_agcLevel; // AGC will aim to this level
Real m_agcFloor; // AGC will not go below this level Real m_agcFloor; // AGC will not go below this level

View File

@ -47,7 +47,6 @@ WFMDemod::WFMDemod(DeviceSourceAPI* deviceAPI) :
m_magsqSum(0.0f), m_magsqSum(0.0f),
m_magsqPeak(0.0f), m_magsqPeak(0.0f),
m_magsqCount(0), m_magsqCount(0),
m_movingAverage(40, 0),
m_sampleSink(0), m_sampleSink(0),
m_audioFifo(250000), m_audioFifo(250000),
m_settingsMutex(QMutex::Recursive) m_settingsMutex(QMutex::Recursive)
@ -60,8 +59,6 @@ WFMDemod::WFMDemod(DeviceSourceAPI* deviceAPI) :
m_audioBuffer.resize(16384); m_audioBuffer.resize(16384);
m_audioBufferFill = 0; m_audioBufferFill = 0;
m_movingAverage.resize(16, 0);
DSPEngine::instance()->addAudioSink(&m_audioFifo); DSPEngine::instance()->addAudioSink(&m_audioFifo);
m_udpBufferAudio = new UDPSink<qint16>(this, m_udpBlockSize, m_settings.m_udpPort); m_udpBufferAudio = new UDPSink<qint16>(this, m_udpBlockSize, m_settings.m_udpPort);
@ -114,7 +111,7 @@ void WFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
demod = m_phaseDiscri.phaseDiscriminatorDelta(rf[i], msq, fmDev); demod = m_phaseDiscri.phaseDiscriminatorDelta(rf[i], msq, fmDev);
Real magsq = msq / (SDR_RX_SCALED*SDR_RX_SCALED); Real magsq = msq / (SDR_RX_SCALED*SDR_RX_SCALED);
m_movingAverage.feed(magsq); m_movingAverage(magsq);
m_magsqSum += magsq; m_magsqSum += magsq;
if (magsq > m_magsqPeak) if (magsq > m_magsqPeak)
@ -124,7 +121,7 @@ void WFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
m_magsqCount++; m_magsqCount++;
if(m_movingAverage.average() >= m_squelchLevel) if((Real) m_movingAverage >= m_squelchLevel)
m_squelchState = m_settings.m_rfBandwidth / 20; // decay rate m_squelchState = m_settings.m_rfBandwidth / 20; // decay rate
if (m_squelchState > 0) if (m_squelchState > 0)

View File

@ -26,7 +26,7 @@
#include "dsp/nco.h" #include "dsp/nco.h"
#include "dsp/interpolator.h" #include "dsp/interpolator.h"
#include "dsp/lowpass.h" #include "dsp/lowpass.h"
#include "dsp/movingaverage.h" #include "util/movingaverage.h"
#include "dsp/fftfilt.h" #include "dsp/fftfilt.h"
#include "dsp/phasediscri.h" #include "dsp/phasediscri.h"
#include "audio/audiofifo.h" #include "audio/audiofifo.h"
@ -105,7 +105,7 @@ public:
virtual QByteArray serialize() const; virtual QByteArray serialize() const;
virtual bool deserialize(const QByteArray& data); virtual bool deserialize(const QByteArray& data);
double getMagSq() const { return m_movingAverage.average(); } double getMagSq() const { return m_movingAverage.asDouble(); }
bool getSquelchOpen() const { return m_squelchOpen; } bool getSquelchOpen() const { return m_squelchOpen; }
void getMagSqLevels(double& avg, double& peak, int& nbSamples) void getMagSqLevels(double& avg, double& peak, int& nbSamples)
@ -151,7 +151,7 @@ private:
int m_magsqCount; int m_magsqCount;
Real m_lastArgument; Real m_lastArgument;
MovingAverage<double> m_movingAverage; MovingAverageUtil<Real, double, 16> m_movingAverage;
Real m_fmExcursion; Real m_fmExcursion;
AudioVector m_audioBuffer; AudioVector m_audioBuffer;

View File

@ -166,8 +166,7 @@ WFMDemodGUI::WFMDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseban
m_pluginAPI(pluginAPI), m_pluginAPI(pluginAPI),
m_deviceUISet(deviceUISet), m_deviceUISet(deviceUISet),
m_channelMarker(this), m_channelMarker(this),
m_basicSettingsShown(false), m_basicSettingsShown(false)
m_channelPowerDbAvg(20,0)
{ {
ui->setupUi(this); ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose, true); setAttribute(Qt::WA_DeleteOnClose, true);
@ -290,10 +289,6 @@ void WFMDemodGUI::enterEvent(QEvent*)
void WFMDemodGUI::tick() void WFMDemodGUI::tick()
{ {
// Real powDb = CalcDb::dbPower(m_wfmDemod->getMagSq());
// m_channelPowerDbAvg.feed(powDb);
// ui->channelPower->setText(QString::number(m_channelPowerDbAvg.average(), 'f', 1));
double magsqAvg, magsqPeak; double magsqAvg, magsqPeak;
int nbMagsqSamples; int nbMagsqSamples;
m_wfmDemod->getMagSqLevels(magsqAvg, magsqPeak, nbMagsqSamples); m_wfmDemod->getMagSqLevels(magsqAvg, magsqPeak, nbMagsqSamples);

View File

@ -4,7 +4,6 @@
#include <plugin/plugininstancegui.h> #include <plugin/plugininstancegui.h>
#include "gui/rollupwidget.h" #include "gui/rollupwidget.h"
#include "dsp/channelmarker.h" #include "dsp/channelmarker.h"
#include "dsp/movingaverage.h"
#include "util/messagequeue.h" #include "util/messagequeue.h"
#include "wfmdemodsettings.h" #include "wfmdemodsettings.h"
@ -52,7 +51,6 @@ private:
bool m_squelchOpen; bool m_squelchOpen;
WFMDemod* m_wfmDemod; WFMDemod* m_wfmDemod;
MovingAverage<double> m_channelPowerDbAvg;
MessageQueue m_inputMessageQueue; MessageQueue m_inputMessageQueue;
explicit WFMDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel, QWidget* parent = 0); explicit WFMDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel, QWidget* parent = 0);

View File

@ -18,6 +18,8 @@
#ifndef PLUGINS_CHANNELRX_DEMODWFM_WFMDEMODSETTINGS_H_ #ifndef PLUGINS_CHANNELRX_DEMODWFM_WFMDEMODSETTINGS_H_
#define PLUGINS_CHANNELRX_DEMODWFM_WFMDEMODSETTINGS_H_ #define PLUGINS_CHANNELRX_DEMODWFM_WFMDEMODSETTINGS_H_
#include "dsp/dsptypes.h"
class Serializable; class Serializable;
struct WFMDemodSettings struct WFMDemodSettings

View File

@ -112,8 +112,8 @@ void TCPSrcGUI::channelMarkerHighlightedByCursor()
void TCPSrcGUI::tick() void TCPSrcGUI::tick()
{ {
double powDb = CalcDb::dbPower(m_tcpSrc->getMagSq()); double powDb = CalcDb::dbPower(m_tcpSrc->getMagSq());
m_channelPowerDbAvg.feed(powDb); m_channelPowerDbAvg(powDb);
ui->channelPower->setText(QString::number(m_channelPowerDbAvg.average(), 'f', 1)); ui->channelPower->setText(QString::number(m_channelPowerDbAvg.asDouble(), 'f', 1));
} }
TCPSrcGUI::TCPSrcGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel, QWidget* parent) : TCPSrcGUI::TCPSrcGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel, QWidget* parent) :
@ -123,7 +123,6 @@ TCPSrcGUI::TCPSrcGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSam
m_deviceUISet(deviceUISet), m_deviceUISet(deviceUISet),
m_tcpSrc(0), m_tcpSrc(0),
m_channelMarker(this), m_channelMarker(this),
m_channelPowerDbAvg(40,0),
m_rfBandwidthChanged(false), m_rfBandwidthChanged(false),
m_doApplySettings(true) m_doApplySettings(true)
{ {

View File

@ -6,7 +6,7 @@
#include "gui/rollupwidget.h" #include "gui/rollupwidget.h"
#include "dsp/channelmarker.h" #include "dsp/channelmarker.h"
#include "dsp/movingaverage.h" #include "util/movingaverage.h"
#include "util/messagequeue.h" #include "util/messagequeue.h"
#include "tcpsrc.h" #include "tcpsrc.h"
@ -49,7 +49,7 @@ private:
DeviceUISet* m_deviceUISet; DeviceUISet* m_deviceUISet;
TCPSrc* m_tcpSrc; TCPSrc* m_tcpSrc;
ChannelMarker m_channelMarker; ChannelMarker m_channelMarker;
MovingAverage<double> m_channelPowerDbAvg; MovingAverageUtil<Real, double, 40> m_channelPowerDbAvg;
// settings // settings
TCPSrcSettings m_settings; TCPSrcSettings m_settings;

View File

@ -46,8 +46,6 @@ AMMod::AMMod(DeviceSinkAPI *deviceAPI) :
m_basebandSampleRate(48000), m_basebandSampleRate(48000),
m_outputSampleRate(48000), m_outputSampleRate(48000),
m_inputFrequencyOffset(0), m_inputFrequencyOffset(0),
m_movingAverage(40, 0),
m_volumeAGC(40, 0),
m_audioFifo(4800), m_audioFifo(4800),
m_settingsMutex(QMutex::Recursive), m_settingsMutex(QMutex::Recursive),
m_fileSize(0), m_fileSize(0),
@ -63,8 +61,6 @@ AMMod::AMMod(DeviceSinkAPI *deviceAPI) :
m_audioBuffer.resize(1<<14); m_audioBuffer.resize(1<<14);
m_audioBufferFill = 0; m_audioBufferFill = 0;
m_movingAverage.resize(16, 0);
m_volumeAGC.resize(4096, 0.003, 0);
m_magsq = 0.0; m_magsq = 0.0;
m_toneNco.setFreq(1000.0, m_settings.m_audioSampleRate); m_toneNco.setFreq(1000.0, m_settings.m_audioSampleRate);
@ -131,8 +127,8 @@ void AMMod::pull(Sample& sample)
double magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); double magsq = ci.real() * ci.real() + ci.imag() * ci.imag();
magsq /= (SDR_TX_SCALED*SDR_TX_SCALED); magsq /= (SDR_TX_SCALED*SDR_TX_SCALED);
m_movingAverage.feed(magsq); m_movingAverage(magsq);
m_magsq = m_movingAverage.average(); m_magsq = m_movingAverage.asDouble();
sample.m_real = (FixReal) ci.real(); sample.m_real = (FixReal) ci.real();
sample.m_imag = (FixReal) ci.imag(); sample.m_imag = (FixReal) ci.imag();

View File

@ -27,7 +27,7 @@
#include "dsp/nco.h" #include "dsp/nco.h"
#include "dsp/ncof.h" #include "dsp/ncof.h"
#include "dsp/interpolator.h" #include "dsp/interpolator.h"
#include "dsp/movingaverage.h" #include "util/movingaverage.h"
#include "dsp/agc.h" #include "dsp/agc.h"
#include "dsp/cwkeyer.h" #include "dsp/cwkeyer.h"
#include "audio/audiofifo.h" #include "audio/audiofifo.h"
@ -286,8 +286,7 @@ private:
bool m_interpolatorConsumed; bool m_interpolatorConsumed;
double m_magsq; double m_magsq;
MovingAverage<double> m_movingAverage; MovingAverageUtil<double, double, 16> m_movingAverage;
SimpleAGC m_volumeAGC;
AudioVector m_audioBuffer; AudioVector m_audioBuffer;
uint m_audioBufferFill; uint m_audioBufferFill;

View File

@ -266,7 +266,6 @@ AMModGUI::AMModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampl
m_deviceUISet(deviceUISet), m_deviceUISet(deviceUISet),
m_channelMarker(this), m_channelMarker(this),
m_doApplySettings(true), m_doApplySettings(true),
m_channelPowerDbAvg(20,0),
m_recordLength(0), m_recordLength(0),
m_recordSampleRate(48000), m_recordSampleRate(48000),
m_samplesCount(0), m_samplesCount(0),
@ -395,8 +394,8 @@ void AMModGUI::enterEvent(QEvent*)
void AMModGUI::tick() void AMModGUI::tick()
{ {
double powDb = CalcDb::dbPower(m_amMod->getMagSq()); double powDb = CalcDb::dbPower(m_amMod->getMagSq());
m_channelPowerDbAvg.feed(powDb); m_channelPowerDbAvg(powDb);
ui->channelPower->setText(tr("%1 dB").arg(m_channelPowerDbAvg.average(), 0, 'f', 1)); ui->channelPower->setText(tr("%1 dB").arg(m_channelPowerDbAvg.asDouble(), 0, 'f', 1));
if (((++m_tickCount & 0xf) == 0) && (m_modAFInput == AMMod::AMModInputFile)) if (((++m_tickCount & 0xf) == 0) && (m_modAFInput == AMMod::AMModInputFile))
{ {

View File

@ -20,7 +20,7 @@
#include <plugin/plugininstancegui.h> #include <plugin/plugininstancegui.h>
#include "gui/rollupwidget.h" #include "gui/rollupwidget.h"
#include "dsp/channelmarker.h" #include "dsp/channelmarker.h"
#include "dsp/movingaverage.h" #include "util/movingaverage.h"
#include "util/messagequeue.h" #include "util/messagequeue.h"
#include "ammod.h" #include "ammod.h"
@ -66,7 +66,7 @@ private:
bool m_doApplySettings; bool m_doApplySettings;
AMMod* m_amMod; AMMod* m_amMod;
MovingAverage<double> m_channelPowerDbAvg; MovingAverageUtil<double, double, 20> m_channelPowerDbAvg;
QString m_fileName; QString m_fileName;
quint32 m_recordLength; quint32 m_recordLength;

View File

@ -60,7 +60,6 @@ ATVMod::ATVMod(DeviceSinkAPI *deviceAPI) :
m_settingsMutex(QMutex::Recursive), m_settingsMutex(QMutex::Recursive),
m_horizontalCount(0), m_horizontalCount(0),
m_lineCount(0), m_lineCount(0),
m_movingAverage(40, 0),
m_imageOK(false), m_imageOK(false),
m_videoFPSq(1.0f), m_videoFPSq(1.0f),
m_videoFPSCount(0.0f), m_videoFPSCount(0.0f),
@ -90,8 +89,6 @@ ATVMod::ATVMod(DeviceSinkAPI *deviceAPI) :
m_interpolatorDistanceRemain = 0.0f; m_interpolatorDistanceRemain = 0.0f;
m_interpolatorDistance = 1.0f; m_interpolatorDistance = 1.0f;
m_movingAverage.resize(16, 0);
m_channelizer = new UpChannelizer(this); m_channelizer = new UpChannelizer(this);
m_threadedChannelizer = new ThreadedBasebandSampleSource(m_channelizer, this); m_threadedChannelizer = new ThreadedBasebandSampleSource(m_channelizer, this);
m_deviceAPI->addThreadedSource(m_threadedChannelizer); m_deviceAPI->addThreadedSource(m_threadedChannelizer);
@ -165,7 +162,7 @@ void ATVMod::pullFinalize(Complex& ci, Sample& sample)
double magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); double magsq = ci.real() * ci.real() + ci.imag() * ci.imag();
magsq /= (SDR_TX_SCALED*SDR_TX_SCALED); magsq /= (SDR_TX_SCALED*SDR_TX_SCALED);
m_movingAverage.feed(magsq); m_movingAverage(magsq);
sample.m_real = (FixReal) ci.real(); sample.m_real = (FixReal) ci.real();
sample.m_imag = (FixReal) ci.imag(); sample.m_imag = (FixReal) ci.imag();

View File

@ -31,7 +31,7 @@
#include "channel/channelsourceapi.h" #include "channel/channelsourceapi.h"
#include "dsp/nco.h" #include "dsp/nco.h"
#include "dsp/interpolator.h" #include "dsp/interpolator.h"
#include "dsp/movingaverage.h" #include "util/movingaverage.h"
#include "dsp/fftfilt.h" #include "dsp/fftfilt.h"
#include "util/message.h" #include "util/message.h"
@ -412,7 +412,7 @@ public:
virtual bool deserialize(const QByteArray& data); virtual bool deserialize(const QByteArray& data);
int getEffectiveSampleRate() const { return m_tvSampleRate; }; int getEffectiveSampleRate() const { return m_tvSampleRate; };
double getMagSq() const { return m_movingAverage.average(); } double getMagSq() const { return m_movingAverage.asDouble(); }
void getCameraNumbers(std::vector<int>& numbers); void getCameraNumbers(std::vector<int>& numbers);
static void getBaseValues(int outputSampleRate, int linesPerSecond, int& sampleRateUnits, uint32_t& nbPointsPerRateUnit); static void getBaseValues(int outputSampleRate, int linesPerSecond, int& sampleRateUnits, uint32_t& nbPointsPerRateUnit);
@ -512,7 +512,7 @@ private:
int m_lineCount; //!< current line index in frame int m_lineCount; //!< current line index in frame
float m_fps; //!< resulting frames per second float m_fps; //!< resulting frames per second
MovingAverage<double> m_movingAverage; MovingAverageUtil<double, double, 16> m_movingAverage;
quint32 m_levelCalcCount; quint32 m_levelCalcCount;
Real m_peakLevel; Real m_peakLevel;
Real m_levelSum; Real m_levelSum;

View File

@ -586,7 +586,6 @@ ATVModGUI::ATVModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSam
m_deviceUISet(deviceUISet), m_deviceUISet(deviceUISet),
m_channelMarker(this), m_channelMarker(this),
m_doApplySettings(true), m_doApplySettings(true),
m_channelPowerDbAvg(20,0),
m_videoLength(0), m_videoLength(0),
m_videoFrameRate(48000), m_videoFrameRate(48000),
m_frameCount(0), m_frameCount(0),
@ -741,8 +740,8 @@ void ATVModGUI::enterEvent(QEvent*)
void ATVModGUI::tick() void ATVModGUI::tick()
{ {
double powDb = CalcDb::dbPower(m_atvMod->getMagSq()); double powDb = CalcDb::dbPower(m_atvMod->getMagSq());
m_channelPowerDbAvg.feed(powDb); m_channelPowerDbAvg(powDb);
ui->channelPower->setText(tr("%1 dB").arg(m_channelPowerDbAvg.average(), 0, 'f', 1)); ui->channelPower->setText(tr("%1 dB").arg(m_channelPowerDbAvg.asDouble(), 0, 'f', 1));
if (((++m_tickCount & 0xf) == 0) && (ui->inputSelect->currentIndex() == (int) ATVModSettings::ATVModInputVideo)) if (((++m_tickCount & 0xf) == 0) && (ui->inputSelect->currentIndex() == (int) ATVModSettings::ATVModInputVideo))
{ {

View File

@ -20,7 +20,7 @@
#include <plugin/plugininstancegui.h> #include <plugin/plugininstancegui.h>
#include "gui/rollupwidget.h" #include "gui/rollupwidget.h"
#include "dsp/channelmarker.h" #include "dsp/channelmarker.h"
#include "dsp/movingaverage.h" #include "util/movingaverage.h"
#include "util/messagequeue.h" #include "util/messagequeue.h"
#include "atvmod.h" #include "atvmod.h"
@ -65,7 +65,7 @@ private:
bool m_doApplySettings; bool m_doApplySettings;
ATVMod* m_atvMod; ATVMod* m_atvMod;
MovingAverage<double> m_channelPowerDbAvg; MovingAverageUtil<double, double, 20> m_channelPowerDbAvg;
QString m_imageFileName; QString m_imageFileName;
QString m_videoFileName; QString m_videoFileName;

View File

@ -52,8 +52,6 @@ NFMMod::NFMMod(DeviceSinkAPI *deviceAPI) :
m_outputSampleRate(48000), m_outputSampleRate(48000),
m_inputFrequencyOffset(0), m_inputFrequencyOffset(0),
m_modPhasor(0.0f), m_modPhasor(0.0f),
m_movingAverage(40, 0),
m_volumeAGC(40, 0),
m_audioFifo(4800), m_audioFifo(4800),
m_settingsMutex(QMutex::Recursive), m_settingsMutex(QMutex::Recursive),
m_fileSize(0), m_fileSize(0),
@ -68,8 +66,6 @@ NFMMod::NFMMod(DeviceSinkAPI *deviceAPI) :
m_audioBuffer.resize(1<<14); m_audioBuffer.resize(1<<14);
m_audioBufferFill = 0; m_audioBufferFill = 0;
m_movingAverage.resize(16, 0);
m_volumeAGC.resize(4096, 0.003, 0);
m_magsq = 0.0; m_magsq = 0.0;
m_toneNco.setFreq(1000.0, m_settings.m_audioSampleRate); m_toneNco.setFreq(1000.0, m_settings.m_audioSampleRate);
@ -137,8 +133,8 @@ void NFMMod::pull(Sample& sample)
double magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); double magsq = ci.real() * ci.real() + ci.imag() * ci.imag();
magsq /= (SDR_TX_SCALED*SDR_TX_SCALED); magsq /= (SDR_TX_SCALED*SDR_TX_SCALED);
m_movingAverage.feed(magsq); m_movingAverage(magsq);
m_magsq = m_movingAverage.average(); m_magsq = m_movingAverage.asDouble();
sample.m_real = (FixReal) ci.real(); sample.m_real = (FixReal) ci.real();
sample.m_imag = (FixReal) ci.imag(); sample.m_imag = (FixReal) ci.imag();

View File

@ -29,7 +29,7 @@
#include "dsp/interpolator.h" #include "dsp/interpolator.h"
#include "dsp/lowpass.h" #include "dsp/lowpass.h"
#include "dsp/bandpass.h" #include "dsp/bandpass.h"
#include "dsp/movingaverage.h" #include "util/movingaverage.h"
#include "dsp/agc.h" #include "dsp/agc.h"
#include "dsp/cwkeyer.h" #include "dsp/cwkeyer.h"
#include "audio/audiofifo.h" #include "audio/audiofifo.h"
@ -281,8 +281,7 @@ private:
Bandpass<Real> m_bandpass; Bandpass<Real> m_bandpass;
double m_magsq; double m_magsq;
MovingAverage<double> m_movingAverage; MovingAverageUtil<double, double, 16> m_movingAverage;
SimpleAGC m_volumeAGC;
AudioVector m_audioBuffer; AudioVector m_audioBuffer;
uint m_audioBufferFill; uint m_audioBufferFill;

View File

@ -294,7 +294,6 @@ NFMModGUI::NFMModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSam
m_deviceUISet(deviceUISet), m_deviceUISet(deviceUISet),
m_channelMarker(this), m_channelMarker(this),
m_doApplySettings(true), m_doApplySettings(true),
m_channelPowerDbAvg(20,0),
m_recordLength(0), m_recordLength(0),
m_recordSampleRate(48000), m_recordSampleRate(48000),
m_samplesCount(0), m_samplesCount(0),
@ -450,8 +449,8 @@ void NFMModGUI::enterEvent(QEvent*)
void NFMModGUI::tick() void NFMModGUI::tick()
{ {
double powDb = CalcDb::dbPower(m_nfmMod->getMagSq()); double powDb = CalcDb::dbPower(m_nfmMod->getMagSq());
m_channelPowerDbAvg.feed(powDb); m_channelPowerDbAvg(powDb);
ui->channelPower->setText(tr("%1 dB").arg(m_channelPowerDbAvg.average(), 0, 'f', 1)); ui->channelPower->setText(tr("%1 dB").arg(m_channelPowerDbAvg.asDouble(), 0, 'f', 1));
if (((++m_tickCount & 0xf) == 0) && (m_settings.m_modAFInput == NFMModSettings::NFMModInputFile)) if (((++m_tickCount & 0xf) == 0) && (m_settings.m_modAFInput == NFMModSettings::NFMModInputFile))
{ {

View File

@ -20,7 +20,7 @@
#include <plugin/plugininstancegui.h> #include <plugin/plugininstancegui.h>
#include "gui/rollupwidget.h" #include "gui/rollupwidget.h"
#include "dsp/channelmarker.h" #include "dsp/channelmarker.h"
#include "dsp/movingaverage.h" #include "util/movingaverage.h"
#include "util/messagequeue.h" #include "util/messagequeue.h"
#include "nfmmod.h" #include "nfmmod.h"
@ -64,7 +64,7 @@ private:
bool m_doApplySettings; bool m_doApplySettings;
NFMMod* m_nfmMod; NFMMod* m_nfmMod;
MovingAverage<double> m_channelPowerDbAvg; MovingAverageUtil<double, double, 20> m_channelPowerDbAvg;
QString m_fileName; QString m_fileName;
quint32 m_recordLength; quint32 m_recordLength;

View File

@ -55,7 +55,6 @@ SSBMod::SSBMod(DeviceSinkAPI *deviceAPI) :
m_SSBFilterBufferIndex(0), m_SSBFilterBufferIndex(0),
m_DSBFilterBufferIndex(0), m_DSBFilterBufferIndex(0),
m_sampleSink(0), m_sampleSink(0),
m_movingAverage(40, 0),
m_audioFifo(4800), m_audioFifo(4800),
m_settingsMutex(QMutex::Recursive), m_settingsMutex(QMutex::Recursive),
m_fileSize(0), m_fileSize(0),
@ -84,7 +83,6 @@ SSBMod::SSBMod(DeviceSinkAPI *deviceAPI) :
m_undersampleCount = 0; m_undersampleCount = 0;
m_sumCount = 0; m_sumCount = 0;
m_movingAverage.resize(16, 0);
m_magsq = 0.0; m_magsq = 0.0;
m_toneNco.setFreq(1000.0, m_settings.m_audioSampleRate); m_toneNco.setFreq(1000.0, m_settings.m_audioSampleRate);
@ -166,8 +164,8 @@ void SSBMod::pull(Sample& sample)
double magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); double magsq = ci.real() * ci.real() + ci.imag() * ci.imag();
magsq /= (SDR_TX_SCALED*SDR_TX_SCALED); magsq /= (SDR_TX_SCALED*SDR_TX_SCALED);
m_movingAverage.feed(magsq); m_movingAverage(magsq);
m_magsq = m_movingAverage.average(); m_magsq = m_movingAverage.asDouble();
sample.m_real = (FixReal) ci.real(); sample.m_real = (FixReal) ci.real();
sample.m_imag = (FixReal) ci.imag(); sample.m_imag = (FixReal) ci.imag();

View File

@ -27,7 +27,7 @@
#include "dsp/basebandsamplesink.h" #include "dsp/basebandsamplesink.h"
#include "dsp/ncof.h" #include "dsp/ncof.h"
#include "dsp/interpolator.h" #include "dsp/interpolator.h"
#include "dsp/movingaverage.h" #include "util/movingaverage.h"
#include "dsp/agc.h" #include "dsp/agc.h"
#include "dsp/fftfilt.h" #include "dsp/fftfilt.h"
#include "dsp/cwkeyer.h" #include "dsp/cwkeyer.h"
@ -303,7 +303,7 @@ private:
int m_sumCount; int m_sumCount;
double m_magsq; double m_magsq;
MovingAverage<double> m_movingAverage; MovingAverageUtil<double, double, 16> m_movingAverage;
AudioVector m_audioBuffer; AudioVector m_audioBuffer;
uint m_audioBufferFill; uint m_audioBufferFill;

View File

@ -352,7 +352,6 @@ SSBModGUI::SSBModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSam
m_channelMarker(this), m_channelMarker(this),
m_doApplySettings(true), m_doApplySettings(true),
m_spectrumRate(6000), m_spectrumRate(6000),
m_channelPowerDbAvg(20,0),
m_recordLength(0), m_recordLength(0),
m_recordSampleRate(48000), m_recordSampleRate(48000),
m_samplesCount(0), m_samplesCount(0),
@ -672,8 +671,8 @@ void SSBModGUI::enterEvent(QEvent*)
void SSBModGUI::tick() void SSBModGUI::tick()
{ {
double powDb = CalcDb::dbPower(m_ssbMod->getMagSq()); double powDb = CalcDb::dbPower(m_ssbMod->getMagSq());
m_channelPowerDbAvg.feed(powDb); m_channelPowerDbAvg(powDb);
ui->channelPower->setText(tr("%1 dB").arg(m_channelPowerDbAvg.average(), 0, 'f', 1)); ui->channelPower->setText(tr("%1 dB").arg(m_channelPowerDbAvg.asDouble(), 0, 'f', 1));
if (((++m_tickCount & 0xf) == 0) && (m_modAFInput == SSBMod::SSBModInputFile)) if (((++m_tickCount & 0xf) == 0) && (m_modAFInput == SSBMod::SSBModInputFile))
{ {

View File

@ -22,7 +22,7 @@
#include <plugin/plugininstancegui.h> #include <plugin/plugininstancegui.h>
#include "gui/rollupwidget.h" #include "gui/rollupwidget.h"
#include "dsp/channelmarker.h" #include "dsp/channelmarker.h"
#include "dsp/movingaverage.h" #include "util/movingaverage.h"
#include "util/messagequeue.h" #include "util/messagequeue.h"
#include "ssbmod.h" #include "ssbmod.h"
@ -69,7 +69,7 @@ private:
SpectrumVis* m_spectrumVis; SpectrumVis* m_spectrumVis;
SSBMod* m_ssbMod; SSBMod* m_ssbMod;
MovingAverage<double> m_channelPowerDbAvg; MovingAverageUtil<double, double, 20> m_channelPowerDbAvg;
QString m_fileName; QString m_fileName;
quint32 m_recordLength; quint32 m_recordLength;

View File

@ -51,8 +51,6 @@ WFMMod::WFMMod(DeviceSinkAPI *deviceAPI) :
m_outputSampleRate(384000), m_outputSampleRate(384000),
m_inputFrequencyOffset(0), m_inputFrequencyOffset(0),
m_modPhasor(0.0f), m_modPhasor(0.0f),
m_movingAverage(40, 0),
m_volumeAGC(40, 0),
m_audioFifo(4800), m_audioFifo(4800),
m_settingsMutex(QMutex::Recursive), m_settingsMutex(QMutex::Recursive),
m_fileSize(0), m_fileSize(0),
@ -73,8 +71,6 @@ WFMMod::WFMMod(DeviceSinkAPI *deviceAPI) :
m_audioBuffer.resize(1<<14); m_audioBuffer.resize(1<<14);
m_audioBufferFill = 0; m_audioBufferFill = 0;
m_movingAverage.resize(16, 0);
m_volumeAGC.resize(4096, 0.003, 0);
m_magsq = 0.0; m_magsq = 0.0;
m_toneNco.setFreq(1000.0, m_settings.m_audioSampleRate); m_toneNco.setFreq(1000.0, m_settings.m_audioSampleRate);
@ -159,8 +155,8 @@ void WFMMod::pull(Sample& sample)
double magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); double magsq = ci.real() * ci.real() + ci.imag() * ci.imag();
magsq /= (SDR_TX_SCALED*SDR_TX_SCALED); magsq /= (SDR_TX_SCALED*SDR_TX_SCALED);
m_movingAverage.feed(magsq); m_movingAverage(magsq);
m_magsq = m_movingAverage.average(); m_magsq = m_movingAverage.asDouble();
sample.m_real = (FixReal) ci.real(); sample.m_real = (FixReal) ci.real();
sample.m_imag = (FixReal) ci.imag(); sample.m_imag = (FixReal) ci.imag();

View File

@ -28,7 +28,7 @@
#include "dsp/ncof.h" #include "dsp/ncof.h"
#include "dsp/interpolator.h" #include "dsp/interpolator.h"
#include "dsp/fftfilt.h" #include "dsp/fftfilt.h"
#include "dsp/movingaverage.h" #include "util/movingaverage.h"
#include "dsp/agc.h" #include "dsp/agc.h"
#include "dsp/cwkeyer.h" #include "dsp/cwkeyer.h"
#include "audio/audiofifo.h" #include "audio/audiofifo.h"
@ -294,8 +294,7 @@ private:
int m_rfFilterBufferIndex; int m_rfFilterBufferIndex;
double m_magsq; double m_magsq;
MovingAverage<double> m_movingAverage; MovingAverageUtil<double, double, 16> m_movingAverage;
SimpleAGC m_volumeAGC;
AudioVector m_audioBuffer; AudioVector m_audioBuffer;
uint m_audioBufferFill; uint m_audioBufferFill;

View File

@ -272,7 +272,6 @@ WFMModGUI::WFMModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSam
m_deviceUISet(deviceUISet), m_deviceUISet(deviceUISet),
m_channelMarker(this), m_channelMarker(this),
m_doApplySettings(true), m_doApplySettings(true),
m_channelPowerDbAvg(20,0),
m_recordLength(0), m_recordLength(0),
m_recordSampleRate(48000), m_recordSampleRate(48000),
m_samplesCount(0), m_samplesCount(0),
@ -415,8 +414,8 @@ void WFMModGUI::enterEvent(QEvent*)
void WFMModGUI::tick() void WFMModGUI::tick()
{ {
double powDb = CalcDb::dbPower(m_wfmMod->getMagSq()); double powDb = CalcDb::dbPower(m_wfmMod->getMagSq());
m_channelPowerDbAvg.feed(powDb); m_channelPowerDbAvg(powDb);
ui->channelPower->setText(tr("%1 dB").arg(m_channelPowerDbAvg.average(), 0, 'f', 1)); ui->channelPower->setText(tr("%1 dB").arg(m_channelPowerDbAvg.asDouble(), 0, 'f', 1));
if (((++m_tickCount & 0xf) == 0) && (m_modAFInput == WFMMod::WFMModInputFile)) if (((++m_tickCount & 0xf) == 0) && (m_modAFInput == WFMMod::WFMModInputFile))
{ {

View File

@ -20,7 +20,7 @@
#include <plugin/plugininstancegui.h> #include <plugin/plugininstancegui.h>
#include "gui/rollupwidget.h" #include "gui/rollupwidget.h"
#include "dsp/channelmarker.h" #include "dsp/channelmarker.h"
#include "dsp/movingaverage.h" #include "util/movingaverage.h"
#include "util/messagequeue.h" #include "util/messagequeue.h"
#include "wfmmod.h" #include "wfmmod.h"
@ -68,7 +68,7 @@ private:
// ThreadedBasebandSampleSource* m_threadedChannelizer; // ThreadedBasebandSampleSource* m_threadedChannelizer;
// UpChannelizer* m_channelizer; // UpChannelizer* m_channelizer;
WFMMod* m_wfmMod; WFMMod* m_wfmMod;
MovingAverage<double> m_channelPowerDbAvg; MovingAverageUtil<double, double, 20> m_channelPowerDbAvg;
QString m_fileName; QString m_fileName;
quint32 m_recordLength; quint32 m_recordLength;

View File

@ -107,8 +107,6 @@ UDPSinkGUI::UDPSinkGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandS
ui(new Ui::UDPSinkGUI), ui(new Ui::UDPSinkGUI),
m_pluginAPI(pluginAPI), m_pluginAPI(pluginAPI),
m_deviceUISet(deviceUISet), m_deviceUISet(deviceUISet),
m_channelPowerAvg(4, 1e-10),
m_inPowerAvg(4, 1e-10),
m_tickCount(0), m_tickCount(0),
m_channelMarker(this), m_channelMarker(this),
m_rfBandwidthChanged(false), m_rfBandwidthChanged(false),
@ -454,14 +452,14 @@ void UDPSinkGUI::enterEvent(QEvent*)
void UDPSinkGUI::tick() void UDPSinkGUI::tick()
{ {
m_channelPowerAvg.feed(m_udpSink->getMagSq()); m_channelPowerAvg(m_udpSink->getMagSq());
m_inPowerAvg.feed(m_udpSink->getInMagSq()); m_inPowerAvg(m_udpSink->getInMagSq());
if (m_tickCount % 4 == 0) if (m_tickCount % 4 == 0)
{ {
double powDb = CalcDb::dbPower(m_channelPowerAvg.average()); double powDb = CalcDb::dbPower(m_channelPowerAvg.asDouble());
ui->channelPower->setText(tr("%1 dB").arg(powDb, 0, 'f', 1)); ui->channelPower->setText(tr("%1 dB").arg(powDb, 0, 'f', 1));
double inPowDb = CalcDb::dbPower(m_inPowerAvg.average()); double inPowDb = CalcDb::dbPower(m_inPowerAvg.asDouble());
ui->inputPower->setText(tr("%1").arg(inPowDb, 0, 'f', 1)); ui->inputPower->setText(tr("%1").arg(inPowDb, 0, 'f', 1));
} }

View File

@ -23,6 +23,7 @@
#include "gui/rollupwidget.h" #include "gui/rollupwidget.h"
#include "dsp/channelmarker.h" #include "dsp/channelmarker.h"
#include "util/messagequeue.h" #include "util/messagequeue.h"
#include "util/movingaverage.h"
#include "udpsink.h" #include "udpsink.h"
#include "udpsinksettings.h" #include "udpsinksettings.h"
@ -62,8 +63,8 @@ private:
DeviceUISet* m_deviceUISet; DeviceUISet* m_deviceUISet;
SpectrumVis* m_spectrumVis; SpectrumVis* m_spectrumVis;
UDPSink* m_udpSink; UDPSink* m_udpSink;
MovingAverage<double> m_channelPowerAvg; MovingAverageUtil<double, double, 4> m_channelPowerAvg;
MovingAverage<double> m_inPowerAvg; MovingAverageUtil<double, double, 4> m_inPowerAvg;
uint32_t m_tickCount; uint32_t m_tickCount;
ChannelMarker m_channelMarker; ChannelMarker m_channelMarker;

View File

@ -32,6 +32,13 @@ class MovingAverageUtil
: m_num_samples(0), m_index(0), m_total(0) : m_num_samples(0), m_index(0), m_total(0)
{ } { }
void reset()
{
m_num_samples = 0;
m_index = 0;
m_total = 0;
}
void operator()(T sample) void operator()(T sample)
{ {
if (m_num_samples < N) // fill up if (m_num_samples < N) // fill up
@ -42,14 +49,14 @@ class MovingAverageUtil
else // roll else // roll
{ {
T& oldest = m_samples[m_index]; T& oldest = m_samples[m_index];
m_index = (m_index + 1) % N;
m_total += sample - oldest; m_total += sample - oldest;
oldest = sample; oldest = sample;
m_index = (m_index + 1) % N;
} }
} }
operator double() const { return m_num_samples > 0 ? m_total / std::min(m_num_samples, N) : 0.0d; } double asDouble() const { return m_total / N; }
operator float() const { return m_num_samples > 0 ? m_total / std::min(m_num_samples, N) : 0.0f; } float asFloat() const { return m_total / N; }
operator T() const { return m_total / N; } operator T() const { return m_total / N; }
private: private: