0

I have the following program to detect all the peaks on a line graph. It succesfully detects the peaks but I only want for it to detect the ones which are conspicous(large enough to be seen). Any suggestions?
Line Graph

import numpy as np

b = (X[1:]-X[:-1])[:-1]
c = (X[:-1]-X[1:])[1:]
minima = np.where(np.bitwise_and(b<0, c<0))[0]+1
maxima = np.where(np.bitwise_and(b>0, c>0))[0]+1
all_peaks = np.where((b*c)>0)[0]+1
del b,c

print(minima)
print(maxima)
print(all_peaks)
If_You_Say_So
  • 1,195
  • 1
  • 10
  • 25
  • 2
    "large enough to be seen" - with or without glasses? :) – If_You_Say_So Jul 22 '20 at 23:10
  • Either is fine. :) – User285 Jul 23 '20 at 00:03
  • 3
    I'd recommend to replace "to be seen" by some quantitative criteria for filtering your peaks in terms of absolute or relative height of the pek. – Yuri Ginsburg Jul 23 '20 at 00:40
  • 1
    Compare to left and right neighbors, if larger than both mark as local maximum. Alternatively, if largest value within 2n+1 neighborhood for any n, mark as local maximum. Can also apply a threshold on ratio of current value to second largest value within neighborhood (to filter out spurious peaks) – ldog Jul 23 '20 at 05:21
  • Typically you find extremes when the derivation crosses 0. – Thomas Weller Jul 23 '20 at 06:37
  • What is the output of your code? Why does it not match your expectations? The code is not plotting anything. How would one determine the scale of the plot then? What is `X`? Can you provide a [mcve]? – Thomas Weller Jul 23 '20 at 06:43
  • Something like this? https://stackoverflow.com/questions/20618804/how-to-smooth-a-curve-in-the-right-way – tripleee Jul 23 '20 at 06:44
  • You can pick your favourite peak detection algorithm here: https://github.com/MonsieurV/py-findpeaks – Niko Föhr Jul 23 '20 at 07:12

0 Answers0