1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-22 08:04:49 -05:00

Spectrum averaging: fixed average (3): scale engine fix

This commit is contained in:
f4exb 2018-07-01 04:10:36 +02:00
parent 0b496bd800
commit 9913d550e0
6 changed files with 47 additions and 31 deletions

View File

@ -95,6 +95,10 @@ public:
bool nextAverage()
{
if (m_size <= 1) {
return true;
}
if (m_avgIndex == m_size - 1)
{
m_avgIndex = 0;

View File

@ -1055,11 +1055,11 @@ void GLSpectrum::applyChanges()
if(!m_invertedWaterfall)
{
m_timeScale.setRange(Unit::Time, (waterfallHeight * m_fftSize) / scaleDiv, 0);
m_timeScale.setRange(m_timingRate > 1 ? Unit::TimeHMS : Unit::Time, (waterfallHeight * m_fftSize) / scaleDiv, 0);
}
else
{
m_timeScale.setRange(Unit::Time, 0, (waterfallHeight * m_fftSize) / scaleDiv);
m_timeScale.setRange(m_timingRate > 1 ? Unit::TimeHMS : Unit::Time, 0, (waterfallHeight * m_fftSize) / scaleDiv);
}
}
else
@ -1149,26 +1149,26 @@ 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)
{
m_timeScale.setRange(Unit::Time, (waterfallHeight * m_fftSize) / scaleDiv, 0);
m_timeScale.setRange(m_timingRate > 1 ? Unit::TimeHMS : Unit::Time, (waterfallHeight * m_fftSize) / scaleDiv, 0);
}
else
{
m_timeScale.setRange(Unit::Time, 0, (waterfallHeight * m_fftSize) / scaleDiv);
m_timeScale.setRange(m_timingRate > 1 ? Unit::TimeHMS : Unit::Time, 0, (waterfallHeight * m_fftSize) / scaleDiv);
}
}
else
{
if(!m_invertedWaterfall)
{
m_timeScale.setRange(Unit::Time, 10, 0);
m_timeScale.setRange(m_timingRate > 1 ? Unit::TimeHMS : Unit::Time, 10, 0);
}
else
{
m_timeScale.setRange(Unit::Time, 0, 10);
m_timeScale.setRange(m_timingRate > 1 ? Unit::TimeHMS : Unit::Time, 0, 10);
}
}

View File

@ -34,8 +34,10 @@ GLSpectrumGUI::GLSpectrumGUI(QWidget* parent) :
m_averagingNb(0)
{
ui->setupUi(this);
ui->refLevel->clear();
for(int ref = 0; ref >= -110; ref -= 5)
ui->refLevel->addItem(QString("%1").arg(ref));
ui->levelRange->clear();
for(int range = 100; range >= 5; range -= 5)
ui->levelRange->addItem(QString("%1").arg(range));
setAveragingCombo();

View File

@ -29,6 +29,7 @@ namespace Unit {
DecibelMicroVolt,
AngleDegrees,
Time,
TimeHMS,
Volt
};
};

View File

@ -27,43 +27,48 @@ static double trunc(double d)
}
*/
QString ScaleEngine::formatTick(double value, int decimalPlaces, bool fancyTime)
QString ScaleEngine::formatTick(double value, int decimalPlaces)
{
if((m_physicalUnit != Unit::Time) || (!fancyTime))
if (m_physicalUnit != Unit::TimeHMS)
{
return QString("%1").arg(m_makeOpposite ? -value : value, 0, 'f', decimalPlaces);
}
else
{
if (m_scale < 1.0f) { // sub second prints just as is
return QString("%1").arg(m_makeOpposite ? -value : value, 0, 'f', decimalPlaces);
}
QString str;
double orig = fabs(value);
double actual = value * m_scale; // this is the actual value in seconds
double orig = fabs(actual);
double tmp;
if(orig >= 86400.0) {
tmp = floor(value / 86400.0);
tmp = floor(actual / 86400.0);
str = QString("%1.").arg(tmp, 0, 'f', 0);
value -= tmp * 86400.0;
if(value < 0.0)
value *= -1.0;
actual -= tmp * 86400.0;
if(actual < 0.0)
actual *= -1.0;
}
if(orig >= 3600.0) {
tmp = floor(value / 3600.0);
tmp = floor(actual / 3600.0);
str += QString("%1:").arg(tmp, 2, 'f', 0, QChar('0'));
value -= tmp * 3600.0;
if(value < 0.0)
value *= -1.0;
actual -= tmp * 3600.0;
if(actual < 0.0)
actual *= -1.0;
}
if(orig >= 60.0) {
tmp = floor(value / 60.0);
tmp = floor(actual / 60.0);
str += QString("%1:").arg(tmp, 2, 'f', 0, QChar('0'));
value -= tmp * 60.0;
if(value < 0.0)
value *= -1.0;
actual -= tmp * 60.0;
if(actual < 0.0)
actual *= -1.0;
}
tmp = m_makeOpposite ? -value : value;
tmp = m_makeOpposite ? -actual : actual;
str += QString("%1").arg(tmp, 2, 'f', decimalPlaces, QChar('0'));
return str;
@ -164,14 +169,18 @@ void ScaleEngine::calcScaleFactor()
break;
case Unit::Time:
if(median < 0.001) {
case Unit::TimeHMS:
if (median < 0.001) {
m_unitStr = QString("µs");
m_scale = 0.000001;
} else if(median < 1.0) {
} else if (median < 1.0) {
m_unitStr = QString("ms");
m_scale = 0.001;
} else {
} else if (median < 1000.0) {
m_unitStr = QString("s");
} else {
m_unitStr = QString("ks");
m_scale = 1000.0;
}
break;
@ -581,15 +590,15 @@ const ScaleEngine::TickList& ScaleEngine::getTickList()
QString ScaleEngine::getRangeMinStr()
{
if(m_unitStr.length() > 0)
return QString("%1 %2").arg(formatTick(m_rangeMin / m_scale, m_decimalPlaces, false)).arg(m_unitStr);
else return QString("%1").arg(formatTick(m_rangeMin / m_scale, m_decimalPlaces, false));
return QString("%1 %2").arg(formatTick(m_rangeMin / m_scale, m_decimalPlaces)).arg(m_unitStr);
else return QString("%1").arg(formatTick(m_rangeMin / m_scale, m_decimalPlaces));
}
QString ScaleEngine::getRangeMaxStr()
{
if(m_unitStr.length() > 0)
return QString("%1 %2").arg(formatTick(m_rangeMax / m_scale, m_decimalPlaces, false)).arg(m_unitStr);
else return QString("%1").arg(formatTick(m_rangeMax / m_scale, m_decimalPlaces, false));
return QString("%1 %2").arg(formatTick(m_rangeMax / m_scale, m_decimalPlaces)).arg(m_unitStr);
else return QString("%1").arg(formatTick(m_rangeMax / m_scale, m_decimalPlaces));
}
float ScaleEngine::getScaleWidth()

View File

@ -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 = false);
QString formatTick(double value, int decimalPlaces);
void calcCharSize();
void calcScaleFactor();
double calcMajorTickUnits(double distance, int* retDecimalPlaces);