Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fft overlap #1856

Merged
merged 4 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions sdrbase/dsp/spectrumvis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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
Expand Down Expand Up @@ -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)
{
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 3 additions & 5 deletions sdrgui/gui/glspectrumgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 5 additions & 7 deletions sdrgui/gui/glspectrumview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down
Loading