Git Product home page Git Product logo

Comments (2)

argilo avatar argilo commented on May 23, 2024

If you'd like to experiment with the peak detection algorithm, you can find the code in plotter.cpp:

gqrx/src/qtgui/plotter.cpp

Lines 1638 to 1738 in 848acef

// Peak detection
if (m_PeakDetectActive)
{
const int pw = PEAK_WINDOW_HALF_WIDTH;
// Use data source appropriate for current display mode
float *_detectSource;
if (m_MaxHoldActive)
_detectSource = m_fftMaxHoldBuf;
else if (m_PlotMode == PLOT_MODE_AVG)
_detectSource = m_fftAvgBuf;
else
_detectSource = m_fftMaxBuf;
const float *detectSource = _detectSource;
// Run peak detection periodically. If overlay will be redrawn, run
// peak detection since zoom/pan may have changed.
if (tnow_ms > tlast_peaks_ms + PEAK_UPDATE_PERIOD || m_DrawOverlay) {
tlast_peaks_ms = tnow_ms;
m_Peaks.clear();
// Narrow peaks
for (i = pw; i < npts - pw; ++i) {
const int ix = i + xmin;
const float vi = detectSource[ix];
float sumV = 0;
float minV = vi;
float maxV = 0;
for (j = -pw; j <= pw; ++j) {
const float vj = detectSource[ix + j];
minV = std::min(minV, vj);
maxV = std::max(maxV, vj);
sumV += vj;
}
const float avgV = sumV / (float)(pw * 2 + 1);
m_peakSmoothBuf[ix] = avgV;
if (vi == maxV && (vi > 2.0f * avgV) && (vi > 4.0f * minV))
{
const qreal y = (qreal)std::max(std::min(
panddBGainFactor * (m_PandMaxdB - 10.0f * log10f(vi)),
(float)plotHeight - 0.0f), 0.0f);
m_Peaks[ix] = y;
}
}
// Use the smoothed curve to find wider peaks
const int pw2 = pw * 5;
for (i = pw2; i < npts - pw2; ++i) {
const int ix = i + xmin;
const float vi = m_peakSmoothBuf[ix];
float sumV = 0;
float minV = vi;
float maxV = 0;
for (j = -pw2; j <= pw2; ++j) {
const float vj = m_peakSmoothBuf[ix + j];
minV = std::min(minV, vj);
maxV = std::max(maxV, vj);
sumV += vj;
}
const float avgV = sumV / (float)(pw2 * 2);
if (vi == maxV && (vi > 2.0f * avgV) && (vi > 4.0f * minV))
{
const qreal y = (qreal)std::max(std::min(
panddBGainFactor * (m_PandMaxdB - 10.0f * log10f(vi)),
(float)plotHeight - 0.0f), 0.0f);
// Show the wider peak only if there is no very close narrow peak
bool found = false;
for (j = -pw; j <= pw; ++j) {
auto it = m_Peaks.find(ix + j);
if (it != m_Peaks.end()) {
found = true;
break;
}
}
if (!found) {
m_Peaks[ix] = y;
}
}
}
}
// Paint peaks with shadow
QPen peakPen(m_maxFftColor, m_DPR);
QPen peakShadowPen(Qt::black, m_DPR);
peakPen.setWidthF(m_DPR);
for(auto peakx : m_Peaks.keys()) {
const qreal peakxPlot = (qreal)peakx;
const qreal peakv = m_Peaks.value(peakx);
painter2.setPen(peakShadowPen);
painter2.drawEllipse(
QRectF(peakxPlot - 5.0 * m_DPR + shadowOffset,
peakv - 5.0 * m_DPR + shadowOffset,
10.0 * m_DPR, 10.0 * m_DPR));
painter2.setPen(peakPen);
painter2.drawEllipse(
QRectF(peakxPlot - 5.0 * m_DPR,
peakv - 5.0 * m_DPR,
10.0 * m_DPR, 10.0 * m_DPR));
}
}

from gqrx.

alphapats avatar alphapats commented on May 23, 2024

Thanks, will try that

from gqrx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.