我正在使用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
高值(正值)更多的数字。最佳答案
如何针对y轴执行此操作:
窗口的大小为您提供了峰数。
对最小值也执行相同的操作以找到负峰。
在图表的开头和结尾要多加注意。
关于c++ - 在实时数据流上检测峰值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60543683/