MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ peak_positions()

std::vector< size_t > MayaFlux::Kinesis::Discrete::peak_positions ( std::span< const double >  data,
double  threshold = 0.0,
size_t  min_distance = 1 
)

Sample indices of local peak maxima in the full span.

A peak at index i satisfies: |data[i]| > threshold, |data[i]| >= |data[i-1]|, |data[i]| >= |data[i+1]|, and i - last_peak >= min_distance.

Note
Produces sparse output; not vectorisable or suitable for compute kernels.
Parameters
dataInput span
thresholdMinimum absolute value to qualify as a peak
min_distanceMinimum sample gap between accepted peaks
Returns
Sorted sample indices of detected peaks

Definition at line 646 of file Analysis.cpp.

647{
648 if (data.size() < 3)
649 return {};
650
651 std::vector<size_t> pos;
652 pos.reserve(data.size() / 100);
653 size_t last = 0;
654
655 for (size_t i = 1; i + 1 < data.size(); ++i) {
656 const double a = std::abs(data[i]);
657 if (a > threshold
658 && a >= std::abs(data[i - 1])
659 && a >= std::abs(data[i + 1])
660 && (pos.empty() || (i - last) >= min_distance)) {
661 pos.push_back(i);
662 last = i;
663 }
664 }
665
666 pos.shrink_to_fit();
667 return pos;
668}
size_t a

References a, and peak_positions().

Referenced by MayaFlux::Yantra::extract_peaks(), and peak_positions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: