# Name of peak finding algorithm

I've been using this implementation of a peak finding algorithm and it works pretty well. I'm wondering if this particular algorithm has a name?

Python code:

def indexes(y, thres=0.3, min_dist=1):
if isinstance(y, np.ndarray) and np.issubdtype(y.dtype, np.unsignedinteger):
raise ValueError("y must be signed")

thres = thres * (np.max(y) - np.min(y)) + np.min(y)
min_dist = int(min_dist)

# compute first order difference
dy = np.diff(y)

# propagate left and right values successively to fill all plateau pixels (0-value)
zeros,=np.where(dy == 0)

# check if the singal is totally flat
if len(zeros) == len(y) - 1:
return np.array([])

while len(zeros):
# add pixels 2 by 2 to propagate left and right value onto the zero-value pixel
zerosr = np.hstack([dy[1:], 0.])
zerosl = np.hstack([0., dy[:-1]])

# replace 0 with right value if non zero
dy[zeros]=zerosr[zeros]
zeros,=np.where(dy == 0)

# replace 0 with left value if non zero
dy[zeros]=zerosl[zeros]
zeros,=np.where(dy == 0)

# find the peaks by using the first order difference
peaks = np.where((np.hstack([dy, 0.]) < 0.)
& (np.hstack([0., dy]) > 0.)
& (y > thres))[0]

# handle multiple peaks, respecting the minimum distance
if peaks.size > 1 and min_dist > 1:
highest = peaks[np.argsort(y[peaks])][::-1]
rem = np.ones(y.size, dtype=bool)
rem[peaks] = False

for peak in highest:
if not rem[peak]:
sl = slice(max(0, peak - min_dist), peak + min_dist + 1)
rem[sl] = True
rem[peak] = False

peaks = np.arange(y.size)[~rem]

return peaks


The full python package can be found here

• I don't think this peak finder has any special name, because the core of it is just an elementary fact from calculus - a peak is where the first derivative has a zero crossing. I guess you could call it that - zero crossing peak detector. – Atul Ingle Jul 21 '17 at 14:56
• and the first derivative has to cross zero from the positive to the negative values. otherwise, it's a valley. – robert bristow-johnson Jul 25 '17 at 4:13