【发布时间】:2020-03-05 10:50:58
【问题描述】:
我正在使用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;
}
}
显示如下:
下一步,我需要检测任何轴上的峰值,例如上图中Y 轴上的峰值,我需要检测和计数。有人可以告诉我一个方法吗?
提前致谢
编辑
我在山峰上标注了下图:
我将峰值定义为值(正值)高于0.25 g 的数字。
【问题讨论】:
-
请定义“峰值”。局部最大值?全局最大值?您是否需要因输入抖动而进行衰减(否则“平坦”信号很容易在那里出现“峰值”)?
-
也许您可以在图片中添加一些小标记,确定您认为“峰值”的值。
-
负值可能是峰值吗?
-
@Yunnosch 谢谢。我刚刚根据您的反馈编辑了问题
-
" if (key-lastPointKey > 0.02) // 最多每 2 毫秒添加一个点"。这是什么单位...听起来很像 20 毫秒(不是 2 毫秒)!
标签: c++ qt qcustomplot