c++ - 在实时数据流上检测峰值

标签 c++ qt qcustomplot

我正在使用QCustomPlot从IMU读取和显示实时值。这就是我设置realtimeDataSlot的方法:

void Settings::realtimeDataSlot(double x_acceleration_g, double y_acceleration_g, double z_acceleration_g, double z_acceleration_gnew)
{
    static QTime time(QTime::currentTime());
    // calculate two new data points:
    double key = time.elapsed()/1000.0; // time elapsed since start of demo, in seconds
    static double lastPointKey = 0;
    if (key-lastPointKey > 0.02) // at most add point every 20 ms
    {
      // add data to lines:
        ui->customPlot->graph(0)->addData(key, x_acceleration_g); // X axis
        ui->customPlot->graph(1)->addData(key, y_acceleration_g); // Y axis
        ui->customPlot->graph(2)->addData(key, z_acceleration_g); // Z axis
        ui->customPlot->graph(3)->addData(key, z_acceleration_gnew);

      lastPointKey = key;
    }
    // make key axis range scroll with the data (at a constant range size of 8):
    ui->customPlot->xAxis->setRange(key, 8, Qt::AlignRight);
    ui->customPlot->replot();

    // calculate frames per second:
    static double lastFpsKey;
    static int frameCount;
    ++frameCount;
    if (key-lastFpsKey >2) // average fps over 2 seconds
    {
      ui->statusbar->showMessage(
            QString("%1 FPS, Total Data points: %2")
            .arg(frameCount/(key-lastFpsKey), 0, 'f', 0)
            .arg(ui->customPlot->graph(0)->data()->size()+ui->customPlot->graph(1)->data()->size())
            , 0);
      lastFpsKey = key;
      frameCount = 0;
    }
}

显示如下:

enter image description here

下一步,我需要检测任何轴上的峰值,例如,在上图中的Y轴上,有一些峰值需要检测和计数。有人可以告诉我一种方法吗?

提前致谢

编辑

我在下图中标记了峰值:

我定义峰值为比0.25 g高值(正值)更多的数字。

enter image description here

最佳答案

如何针对y轴执行此操作:

  • 您定义x轴上的窗口大小,例如5个x值,即100
  • 让该窗口从x轴的起点移动到终点,这意味着:对于第一个度量,请查看x值数字0、1、2、3、4,对于第二个度量,请查看x-值数字1,2,3,4,5等等
  • 每个窗口量度的
  • :确定该窗口中的最大y值,并为适当的x值增加一个得分计数器。
  • 从窗口的开始到结束完全移动之后,您需要查找分数计数器最高的x值。
    窗口的大小为您提供了峰数。

    对最小值也执行相同的操作以找到负峰。

    在图表的开头和结尾要多加注意。

    关于c++ - 在实时数据流上检测峰值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60543683/

    相关文章:

    c++ - 将此类传递给引用的正确语法是什么?

    c++ - cocos2d-x JSON文件解析

    c++ - 在 Qt C++ 中将简单文件夹转换为共享文件夹

    c++ - 黑莓 10 : GNU STL

    c++ - 在 QSplitter 中设置最小固定大小 QCustomPlot 条形图

    c++ - QcustomPlot 不想绘制图形

    php - PHP 中的按位和无符号整数运算

    c++ - 在 Qt 中更改 show() 上的窗口位置

    c++ - QCustomPlot 重新绘制 QCPLayer

    c++ - 教 child C++ 时使用 "include stdafx.h"?