private IntArrayList findPeeks(double[] x) {
    int window = 100;
    IntArrayList peeks = new IntArrayList();
    peeks.add(0);
    double threshold = 0.5;
    for (int i = 1; i < Math.min(x.length - 1, window); i++) {
      if (x[i] > x[i - 1] && x[i] > x[i + 1] && x[i] > threshold) {
        window = i;
        break;
      }
    }
    for (int i = 0; i + window <= x.length; i++) {
      double v = x[i + window / 2];
      if (v > threshold) {
        Pair<Double, Integer> p = max(x, i, i + window);
        if (p.getSecond() == i + window / 2) {
          peeks.add(p.getSecond());
        }
      }
    }
    return peeks;
  }
The function is used to compute the period of a numeric time series.
library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFPeriod.java