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

Merge pull request #1856 from das-Iro/fix-fft-overlap

Fix fft overlap
This commit is contained in:
Edouard Griffiths 2023-10-23 21:30:23 +02:00 committed by GitHub
commit c9a4d541af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 16 deletions

View File

@ -327,7 +327,7 @@ void SpectrumVis::feed(const ComplexVector::const_iterator& cbegin, const Comple
while (begin < end)
{
std::size_t todo = end - begin;
std::size_t samplesNeeded = m_refillSize - m_fftBufferFill;
std::size_t samplesNeeded = m_settings.m_fftSize - m_fftBufferFill;
if (todo >= samplesNeeded)
{
@ -338,6 +338,7 @@ void SpectrumVis::feed(const ComplexVector::const_iterator& cbegin, const Comple
processFFT(positiveOnly);
// advance buffer respecting the fft overlap factor
// undefined bahavior if the memory regions overlap, valid code for 50% overlap
std::copy(m_fftBuffer.begin() + m_refillSize, m_fftBuffer.end(), m_fftBuffer.begin());
// start over
@ -377,7 +378,7 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV
while (begin < end)
{
std::size_t todo = end - begin;
std::size_t samplesNeeded = m_refillSize - m_fftBufferFill;
std::size_t samplesNeeded = m_settings.m_fftSize - m_fftBufferFill;
if (todo >= samplesNeeded)
{
@ -391,6 +392,7 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV
processFFT(positiveOnly);
// advance buffer respecting the fft overlap factor
// undefined bahavior if the memory regions overlap, valid code for 50% overlap
std::copy(m_fftBuffer.begin() + m_refillSize, m_fftBuffer.end(), m_fftBuffer.begin());
// start over
@ -890,8 +892,8 @@ void SpectrumVis::applySettings(const SpectrumSettings& settings, bool force)
if ((fftSize != m_settings.m_fftSize)
|| (settings.m_fftOverlap != m_settings.m_fftOverlap) || force)
{
m_overlapSize = settings.m_fftOverlap < 0 ? 0 :
settings.m_fftOverlap < fftSize/2 ? settings.m_fftOverlap : (fftSize/2) - 1;
m_overlapSize = settings.m_fftOverlap < 0 ? 0 :
settings.m_fftOverlap < fftSize ? settings.m_fftOverlap : (fftSize - 1);
m_refillSize = fftSize - m_overlapSize;
m_fftBufferFill = m_overlapSize;
}

View File

@ -864,8 +864,7 @@ void GLSpectrumGUI::setAveragingToolitp()
{
QString s;
int averagingIndex = m_settings.m_averagingMode == SpectrumSettings::AvgModeNone ? 0 : m_settings.m_averagingIndex;
float halfSize = m_settings.m_fftSize / 2;
float overlapFactor = (halfSize - m_settings.m_fftOverlap) / halfSize;
float overlapFactor = (m_settings.m_fftSize - m_settings.m_fftOverlap) / m_settings.m_fftSize;
float averagingTime = (m_settings.m_fftSize * (SpectrumSettings::getAveragingValue(averagingIndex, m_settings.m_averagingMode) == 0 ?
1 :
SpectrumSettings::getAveragingValue(averagingIndex, m_settings.m_averagingMode))) / (float) m_glSpectrum->getSampleRate();
@ -905,11 +904,10 @@ void GLSpectrumGUI::setFFTSize(int log2FFTSize)
void GLSpectrumGUI::setMaximumOverlap()
{
int halfSize = m_settings.m_fftSize/2;
ui->fftOverlap->setMaximum((halfSize)-1);
ui->fftOverlap->setMaximum(m_settings.m_fftSize -1);
int value = ui->fftOverlap->value();
ui->fftOverlap->setValue(value);
ui->fftOverlap->setToolTip(tr("FFT overlap %1 %").arg((value/(float)halfSize)*100.0f));
ui->fftOverlap->setToolTip(tr("FFT overlap %1 %").arg((value/(float)m_settings.m_fftSize)*100.0f));
if (m_glSpectrum) {
m_glSpectrum->setFFTOverlap(value);

View File

@ -2733,10 +2733,9 @@ void GLSpectrumView::applyChanges()
if (m_sampleRate > 0)
{
float timeScaleDiv = ((float)m_sampleRate / (float)m_timingRate);
float halfFFTSize = m_fftSize / 2;
if (halfFFTSize > m_fftOverlap) {
timeScaleDiv *= halfFFTSize / (halfFFTSize - m_fftOverlap);
if (m_fftSize > m_fftOverlap) {
timeScaleDiv *= m_fftSize / (m_fftSize - m_fftOverlap);
}
if (!m_invertedWaterfall) {
@ -2827,10 +2826,9 @@ void GLSpectrumView::applyChanges()
if (m_sampleRate > 0)
{
float timeScaleDiv = ((float)m_sampleRate / (float)m_timingRate);
float halfFFTSize = m_fftSize / 2;
if (halfFFTSize > m_fftOverlap) {
timeScaleDiv *= halfFFTSize / (halfFFTSize - m_fftOverlap);
if (m_fftSize > m_fftOverlap) {
timeScaleDiv *= m_fftSize / (m_fftSize - m_fftOverlap);
}
if (!m_invertedWaterfall) {
@ -4454,7 +4452,7 @@ void GLSpectrumView::timeZoom(bool zoomInElseOut)
return;
}
if (zoomInElseOut && (m_fftOverlap == m_fftSize/2 - 1)) {
if (zoomInElseOut && (m_fftOverlap == m_fftSize - 1)) {
return;
}