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

◆ peak_positions()

MAYAFLUX_API 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 669 of file Analysis.cpp.

670{
671 if (data.size() < 3)
672 return {};
673
674 std::vector<size_t> pos;
675 pos.reserve(data.size() / 100);
676 size_t last = 0;
677
678 for (size_t i = 1; i + 1 < data.size(); ++i) {
679 const double a = std::abs(data[i]);
680 if (a > threshold
681 && a >= std::abs(data[i - 1])
682 && a >= std::abs(data[i + 1])
683 && (pos.empty() || (i - last) >= min_distance)) {
684 pos.push_back(i);
685 last = i;
686 }
687 }
688
689 pos.shrink_to_fit();
690 return pos;
691}
size_t a

References a, peak_positions(), and MayaFlux::Kinesis::threshold().

Referenced by MayaFlux::Yantra::EnergyAnalyzer< InputType, OutputType >::create_analysis_result(), MayaFlux::Yantra::extract_peaks(), peak_positions(), and MayaFlux::Nodes::Network::ModalNetwork::process_batch().

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