0

I'm using Matlab's findpeaks function for finding local maxima's in a 1d array. My aim is to count the number of maximas, and that's where I encounter problems.

findpeaks() is just too sensitive. For instance, try this

v=[3.6107,3.6109, 3.6110,3.6110, 3.6108, 3.6107,3.6105, 3.6105, 3.6105,3.6106,3.6108,3.6109,3.6109, 3.6108,3.6105,3.6100,3.6094,3.6087,3.6080,   3.6073, 3.6067, 3.6062,3.6058,3.6053,3.6048,3.6041,3.6032,3.6021,3.6008,3.5993,3.5977, 3.5960,3.5942,3.5925,3.5907,3.5889,3.5869,3.5846,3.5820,3.5789,3.5753];
[maxvals, maxind] = findpeaks(v)

And you'll get a number of maximas, while this is obviously just a numerical artifact, and not the actual number of maximas.

How would you suggest to relax the parameters so I'll get a better result?

In Matlab 2014 there is a MinPeakProminence parameter that should solve the issue, but it doesn't seem to work in 2013a. Any ideas?

Amir Sagiv
  • 376
  • 5
  • 23
  • 2
    define 'too sensitive'. How many peaks were you expecting? On my machine, your input data yields just 2 detected peaks, which looks quite reasonable to me? – Wouter Kuijsters Feb 13 '15 at 13:54
  • 2
    This depends on the prior knowledge you have. You could e.g. specify the `threshold` option to set a minimum threshold for a peak, or the `minpeakheight`. – hbaderts Feb 13 '15 at 13:55
  • @WouterKuijsters , seems to me my array has one significant maxima, and minor (= 2 orders of magnitude smaller) "bumps". – Amir Sagiv Feb 13 '15 at 15:43
  • @hbaderts , `threshold` won't limit the number here, since it looks at every maxima seperately, and it either "kills" both or changes nothing, same with `minpeakheight`. – Amir Sagiv Feb 13 '15 at 15:54
  • a quite brutal option is to smooth your data beforehand: [maxvals, maxind] = findpeaks(smooth(v,10)) – yoh.lej Feb 13 '15 at 15:55
  • There is a parameter `MINPEAKDISTANCE` you can use, but it's too coarse. I can run the same simulation with slightly different setting and encounter different relevant values. – Amir Sagiv Feb 13 '15 at 16:01
  • @user42864: you might want to run the command `findpeaks(v)` without output arguments. That will give you a plot with arrows indicating the location of the maxima it found. Judging from that, getting 2 maxima seems quite likely to me (or to state it in another way: which of these maxima would you consider to be 'the' maximum?). Alternatively, you can set the parameter 'npeaks' if you know how many peaks to expect. – Wouter Kuijsters Feb 13 '15 at 16:15
  • It seems I read your question wrong (or you edited it afterwards). I think your best bet would be to upgrade to the newer matlab version, or implement the prominence by hand (the algorithm is explained here: http://nl.mathworks.com/help/signal/ref/findpeaks.html?searchHighlight=findpeaks#buff2uu and does not seem to be too complicated). Other alternatives I can think of: use a combination of the `minpeakdistance` and `sortstr` arguments to get an ordered list of peaks. Run it through a loop for various `minpeakdistance` values and see if you can distill something useful from those results. – Wouter Kuijsters Feb 13 '15 at 17:33

0 Answers0