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

◆ find_peak_positions()

std::vector< size_t > MayaFlux::Yantra::find_peak_positions ( std::span< const double >  data,
double  threshold = 0.0,
size_t  min_distance = 1 
)

Find actual peak positions in the signal.

Returns sample indices where local maxima occur above a threshold.

Parameters
dataInput data span
thresholdMinimum absolute value to be considered a peak
min_distanceMinimum samples between peaks (prevents clustering)
Returns
Vector of sample positions where peaks occur

Definition at line 237 of file AnalysisHelper.cpp.

241{
242 if (data.size() < 3) {
243 return {};
244 }
245
246 std::vector<size_t> positions;
247 positions.reserve(data.size() / 100);
248
249 size_t last_peak = 0;
250
251 for (size_t i = 1; i < data.size() - 1; ++i) {
252 double abs_val = std::abs(data[i]);
253
254 if (abs_val > threshold && abs_val >= std::abs(data[i - 1]) && abs_val >= std::abs(data[i + 1])) {
255
256 if (positions.empty() || (i - last_peak) >= min_distance) {
257 positions.push_back(i);
258 last_peak = i;
259 }
260 }
261 }
262
263 positions.shrink_to_fit();
264 return positions;
265}

References find_peak_positions().

Referenced by MayaFlux::Yantra::EnergyAnalyzer< InputType, OutputType >::create_analysis_result(), and find_peak_positions().

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