Suppose I plot two columns of data from an ASCII file using the ListPlot function. Now, how can I obtain the coordinates of local maxima of the curve such that the maxima are greater than some lower bound?

Thank you

  • 1
    $\begingroup$ Look at FindPeaks in the documentation. Or look at mathematica.stackexchange.com/questions/19829/… Or try listy={12,11,4,7,5,5}; lowerbound=3; len=Length[listy]; i=Range[2,len-1]; Join[ If[listy[[1]]>listy[[2]]&&listy[[1]]>lowerbound,{1},{}], Select[i,listy[[#]]> listy[[#-1]]&&listy[[#]]>listy[[#+1]]&&listy[[#]]>lowerbound&], If[listy[[len]]> listy[[len-1]]&&listy[[len]]>lowerbound,{len},{}]] That assumes your lists are sorted on your x coordinates. Test that on every possible input to try to convince yourself that it is correct. $\endgroup$
    – Bill
    Apr 6, 2021 at 20:34
  • $\begingroup$ Thank you. I'm trying to use FindPeaks but I do not really know how to use it. Since I have to specify sigma, s, and t but I think I just need to specify t which I think specifies the lower bound. I get errors unless I pass values to sigma and s. As you can tell, I know next to nothing in mathematica. I am not sure what Gaussian blurring "sigma" even means. Do you know if there is a more comprehensive documentation out there? I'm not sure if the documentation on the Wolfram website is friendly to a beginner. $\endgroup$ Apr 6, 2021 at 20:40
  • 1
    $\begingroup$ Google wiki gaussian filter returns en.wikipedia.org/wiki/Gaussian_filter and the second item is en.wikipedia.org/wiki/Gaussian_blur Perhaps those and the explanations and pictures will be a more beginner friendly introduction for you $\endgroup$
    – Bill
    Apr 7, 2021 at 2:53

1 Answer 1


data = RandomReal[{0, 10}, {20, 2}] // Sort;

 peaks = data[[FindPeaks[data[[All, 2]],
      sigma, sh, th][[All, 1]]]];
 ListPlot[data, Joined -> True,
  Epilog -> {Red, AbsolutePointSize[4], Point[peaks]}],
 {{sigma, 0}, 0, 4, 0.1, Appearance -> "Labeled"},
 {{sh, 0, "sharpness"}, 0, 4, 0.1, Appearance -> "Labeled"},
 {{th, 0, "threshold"}, Sequence @@ Flatten[
    {Floor[MinMax[data[[All, 2]]], 0.1], 0.1}],
  Appearance -> "Labeled"}]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.