Detecting peak value on realtime IMU data stream I'm using Qt C++, 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 &gt; 0.02) // at most add point every 20 ms
    {
      // add data to lines:
        ui-&gt;customPlot-&gt;graph(0)-&gt;addData(key, x_acceleration_g); // X axis
        ui-&gt;customPlot-&gt;graph(1)-&gt;addData(key, y_acceleration_g); // Y axis
        ui-&gt;customPlot-&gt;graph(2)-&gt;addData(key, z_acceleration_g); // Z axis
        ui-&gt;customPlot-&gt;graph(3)-&gt;addData(key, z_acceleration_gnew);

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

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

I marked in the peaks by hand in the figure. I define peak as the figure that value (positive values) more than 0.25 g at high rate.

Can somebody show me a way to do this realtime?
In order to detect peaks, the simplest method will be to take the difference of adjacent samples and check for zero crossing. You may also want to smooth out the data before taking difference to prevent spurious peaks due to noise. An outline of the procedure here would be like this


Smooth out the data using Moving average filtering. It is a simple filtering where you take average of, say, 5 neighboring samples to arrive at sample value.
For the above filtered signal take the adjacent sample difference ($y[n] = x[n] - x[n-1]) and save the sample indices where difference hits zero (or near zero).
To differentiate positive peaks from negative peaks, also check for sign of sample values around these indices. Eliminate negative peaks, and remaining ones indicate positions where positive peaks occur. 
You may not get exact zero crossing, so you may want to keep a threshold. Also, the position may have offset due to filter delay. A 5-sample MA filter will delay your sample train by ceil(5)=3 samples.
There are ways to combine MA filtering and taking difference. Look for filters which do differentiation (https://www.dsprelated.com/showarticle/35.php)