detectPeaks method
Detects peaks in the data with a debounce period.
data
- List of double values to analyze.
timestamps
- List of timestamps corresponding to the data.
threshold
- Minimum value to consider as a peak.
minPeakDistanceSec
- Minimum time between peaks in seconds.
Returns a list of indices where peaks are detected.
Implementation
List<int> detectPeaks(List<double> data, List<DateTime> timestamps, double threshold, double minPeakDistanceSec) {
List<int> peaks = [];
for (int i = 1; i < data.length - 1; i++) {
if (data[i] > threshold && data[i] > data[i - 1] && data[i] > data[i + 1]) {
if (peaks.isEmpty ||
timestamps[i].difference(timestamps[peaks.last]).inMilliseconds / 1000 > minPeakDistanceSec) {
peaks.add(i);
}
}
}
return peaks;
}