Peak Detection in Time Series

后端 未结 6 1741
栀梦
栀梦 2021-02-01 07:59

I\'m currently working on a little project in which I want to compare two time-series. The similarity measure is really vague, they are considered to be similar if the two time

6条回答
  •  悲哀的现实
    2021-02-01 08:44

    I'm not sure about correlation between time series or specific peak detection algorithms but here's a little maximum peak detection algorithm I wrote. It doesn't detect the minimum peaks but could easily be extended to do so by reversing the operations in the for loop.

    List maxPoints = ... //list to store the maximums
    XYDataItem leftPeakPoint = new XYDataItem(0, 0);
    int leftPeakPointIndex = 0;
    XYDataItem rightPeakPoint = new XYDataItem(0, 0);
    boolean first = true;
    int index = -1;
    List pointList = (List) lrpSeries.getItems();
    for (XYDataItem point : pointList) {
        index++;
        if (first) {
            //initialize the first point
            leftPeakPoint = point;
            leftPeakPointIndex = index;
            first = false;
            continue;
        }
        if (leftPeakPoint.getYValue() < point.getYValue()) {
            leftPeakPoint = point;
            leftPeakPointIndex = index;
            rightPeakPoint = point;
        } else if (leftPeakPoint.getYValue() == point.getYValue()) {
            rightPeakPoint = point;
        } else {
            //determine if we are coming down off of a peak by looking at the Y value of the point before the
            //left most point that was detected as a part of a peak
            if (leftPeakPointIndex > 0) {
                XYDataItem prev = pointList.get(leftPeakPointIndex - 1);
                //if two points back has a Y value that is less than or equal to the left peak point
                //then we have found the end of the peak and we can process as such
                if (prev.getYValue() <= leftPeakPoint.getYValue()) {
                    double peakx = rightPeakPoint.getXValue() - ((rightPeakPoint.getXValue() - leftPeakPoint.getXValue()) / 2D);
                    maxPoints.add(new XYDataItem(peakx, leftPeakPoint.getYValue()));
                }
            }
            leftPeakPoint = point;
            leftPeakPointIndex = index;
            rightPeakPoint = point;
        }
    }
    

    The result of this will center the detected peak on flat sections where the Y value of consecutive data points is the same. XYDataItem is just a class that contains an X and Y value as a double. This can easily be replaced with something equivalent.

提交回复
热议问题