当前位置: 首页>>代码示例>>C++>>正文


C++ Spectrum::findPeaks方法代码示例

本文整理汇总了C++中Spectrum::findPeaks方法的典型用法代码示例。如果您正苦于以下问题:C++ Spectrum::findPeaks方法的具体用法?C++ Spectrum::findPeaks怎么用?C++ Spectrum::findPeaks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Spectrum的用法示例。


在下文中一共展示了Spectrum::findPeaks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: findHarmonics

// Algorithm: first interpolate the spectral peak corresponding to fApprox,
// then locate the (near-)integer multiples of its frequency
Spectrum Analyzer::findHarmonics(const Spectrum spectrum, qreal fApprox) const
{
    Spectrum harmonics;
    if (fApprox <= 0 || std::isinf(fApprox))
        return harmonics;
    const auto peaks = spectrum.findPeaks(0.01);
    if (peaks.isEmpty())
        return harmonics;

    harmonics.reserve(peaks.size());
    const auto iFund = std::floor(fApprox / m_binFreq) + 1;
    const auto fundamental = quadraticInterpolation(&spectrum[iFund]);
    harmonics.append(fundamental);
    for (const auto peak : peaks) {
        if (peak->frequency > fundamental.frequency) {
            const Tone t = quadraticInterpolation(peak);
            const qreal ratio = t.frequency / fundamental.frequency;
            if (qAbs(1200 * std::log2(ratio / qRound(ratio))) < 10)
                harmonics.append(t);
        }
    }
    return harmonics;
}
开发者ID:sfranzen,项目名称:ktuner,代码行数:25,代码来源:analyzer.cpp

示例2: determineSnacFundamental

Tone Analyzer::determineSnacFundamental(const Spectrum snac) const
{
    Tone result;
    const auto peaks = snac.findPeaks();
    if (peaks.isEmpty())
        return result;

    // First find the highest peak other than the first SNAC value, which
    // should be 1.0, then pick the first peak after the first zero crossing
    // that exceeds 0.8 times that value
    const auto maxPeak = *std::max_element(peaks.constBegin(), peaks.constEnd(), [](const Tone *t1, const Tone *t2) {
        return *t1 < *t2;
    });
    const auto zeros = snac.findZeros(1);
    auto pick = std::find_if(peaks.begin(), peaks.end(), [&](const Tone *t) {
        return t > zeros.first() && t->amplitude > 0.8 * maxPeak->amplitude;
    });
    if (pick != peaks.end()) {
        result = quadraticInterpolation(*pick);
        Q_ASSERT(result.frequency > 0);
    }
    return result;
}
开发者ID:sfranzen,项目名称:ktuner,代码行数:23,代码来源:analyzer.cpp


注:本文中的Spectrum::findPeaks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。