I'm using QCustomPlot to read and display realtime value from an IMU. This is how I set the 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;
}
}
which shows me as follows:
As a next step, I need to detect the peaks in any axis, say for example in the above figure in the Y
axis there are peak values which I need to detect and count. Can somebody show me a way to do this?
Thanks in advance
EDIT
I marked in the peaks following figure:
I define peak as the figure that value (positive values) more than 0.25 g
at high rate.