Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

One of the great new function in V10 is PeakDetect.

It can detect peaks according to desired sharpness as shown in this example:

data = Table[{x, (Sin[10 x] + 2) Exp[-x^2]}, {x, -4, 4, .01}];
peaks = Pick[data, PeakDetect[data[[;; , 2]], .01, .0005], 1];
ListPlot[{data, peaks}, 
 PlotStyle -> {Automatic, Directive[Red, PointSize[0.02]]}]

enter image description here

The question is how to find valleys of the such data using this new function?

share|improve this question
4  
Apply it to $-f$? –  Mark McClure Jul 14 at 1:04
    
@MarkMcClure Just saw your comment after I posted it. Yes, that is the first thing I though about also. –  Nasser Jul 14 at 1:08
    
@MarkMcClure great trick. thanks to you and to Nasser. –  Algohi Jul 14 at 1:09

2 Answers 2

up vote 9 down vote accepted

As has been observed

enter image description here

data = Table[{x, (Sin[10 x] + 2) Exp[-x^2]}, {x, -4, 4, .01}];
peaks = Pick[data, PeakDetect[data[[;; , 2]], .01, .0005], 1];
troughs = Pick[data, PeakDetect[-data[[;; , 2]], .01, .0005], 1];
ListPlot[{data, peaks, troughs}, 
 PlotStyle -> {Automatic, Directive[Red, PointSize[0.02]], 
   Directive[Green, PointSize[0.02]]}]
share|improve this answer
data = Table[{x, -(Sin[10 x] + 2) Exp[-x^2]}, {x, -4, 4, .01}];
peaks = Pick[data, PeakDetect[data[[;; , 2]], .01, .0005], 1];
ListPlot[{data, peaks}, PlotStyle -> {Automatic, Directive[Red, PointSize[0.02]]}];
Rotate[%, 180 Degree]

Mathematica graphics

Or as Pickett mentioned below, just add - to data as in

data = Table[{x, (Sin[10 x] + 2) Exp[-x^2]}, {x, -4, 4, .01}];
peaks = Pick[data, PeakDetect[-data[[;; , 2]], .01, .0005], 1];
ListPlot[{data, peaks}, PlotStyle -> {Automatic, Directive[Red, PointSize[0.02]]}]
share|improve this answer
2  
It's easier to just add - in front of data[[;;,2]]. This way you don't have to rotate the graph. –  Pickett Jul 14 at 1:12
    
@Nasser, it would better if you ListPlot[{-data,-peaks},....] –  Algohi Jul 14 at 1:13
    
@Pickett, sure that is better so no rotation is needed. Thanks. –  Nasser Jul 14 at 1:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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