/* MCL Copyright (c) 2012-18, Enzo De Sena All rights reserved. Authors: Enzo De Sena, enzodesena@gmail.com */ #include "basicop.h" #include "mcltypes.h" #include "pointwiseop.h" #include namespace mcl { std::vector FindPeaks(const std::vector& vector, const Real min_peak_height) { std::vector indexes = FindPeaksIndexes(vector, min_peak_height); std::vector output(indexes.size()); for (Int i=0; i<(Int)indexes.size(); ++i) { output[i] = vector[indexes[i]]; } return output; } std::vector FindPeaksIndexes(const std::vector& vector, const Real min_peak_height) { // Allocate new vectors for the indexes of the local maxima std::vector indexes; for (Int i=1; i<(Int)(vector.size()-1); ++i) { if ((vector[i] > min_peak_height) & (vector[i] > vector[i-1]) & (vector[i] > vector[i+1])) { indexes.push_back(i); } } return indexes; } template<> Int MaxIndex(const std::vector& input) noexcept { return MinIndex(Opposite(ConvertToInt(input))); } } // namespace mcl