Skip to content

Commit

Permalink
Merge pull request f4exb#2186 from srcejon/freq_scanner
Browse files Browse the repository at this point in the history
Frequency Scanner: Fix rounding error
  • Loading branch information
f4exb committed Jun 27, 2024
2 parents 2baea03 + fd1d411 commit e22688e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions plugins/channelrx/freqscanner/freqscanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ void FreqScanner::stop()
qDebug("FreqScanner::stop");
m_running = false;
m_thread->exit();
#ifndef __EMSCRIPTEN__
m_thread->wait();
#endif
}

bool FreqScanner::handleMessage(const Message& cmd)
Expand Down Expand Up @@ -343,9 +345,9 @@ void FreqScanner::processScanResults(const QDateTime& fftStartTime, const QList<
int binsPerChannel;
calcScannerSampleRate(m_settings.m_channelBandwidth, m_basebandSampleRate, m_scannerSampleRate, fftSize, binsPerChannel);

// Align first frequency so we cover as many channels as possible, while channel guard band
// Align first frequency so we cover as many channels as possible, while skipping channel guard band (12.5% either end)
// Can we adjust this to avoid DC bin?
m_stepStartFrequency = frequencies.front() + m_scannerSampleRate / 2 - m_scannerSampleRate * 0.125f;
m_stepStartFrequency = frequencies.front() + m_scannerSampleRate / 2 - (m_scannerSampleRate / 8);
m_stepStopFrequency = frequencies.back();

// If all frequencies fit within usable bandwidth, we can have the first frequency more central
Expand Down Expand Up @@ -374,7 +376,7 @@ void FreqScanner::processScanResults(const QDateTime& fftStartTime, const QList<
bool complete = false; // Have all frequencies been scanned?
bool freqInRange = false;
qint64 nextCenterFrequency = m_centerFrequency;
float usableBW = m_scannerSampleRate * 0.75f;
int usableBW = (m_scannerSampleRate * 3 / 4) & ~1;
do
{
if (nextCenterFrequency + usableBW / 2 > m_stepStopFrequency)
Expand Down
4 changes: 2 additions & 2 deletions plugins/channelrx/freqscanner/freqscannersink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ void FreqScannerSink::processOneSample(Complex &ci)
qint64 diff = frequency - startFrequency;
float binBW = m_scannerSampleRate / (float)m_fftSize;

// Ignore results in uppper and lower 12.5%, as there may be aliasing here from half-band filters
if ((diff < m_scannerSampleRate * 0.875f) && (diff >= m_scannerSampleRate * 0.125f))
// Ignore results in upper and lower 12.5%, as there may be aliasing here from half-band filters
if ((diff >= m_scannerSampleRate / 8) && (diff < m_scannerSampleRate * 7 / 8))
{
int bin = std::round(diff / binBW);
int channelBins;
Expand Down

0 comments on commit e22688e

Please sign in to comment.