0
$\begingroup$

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

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – Atul Ingle Jul 21 '17 at 14:56
  • $\begingroup$ and the first derivative has to cross zero from the positive to the negative values. otherwise, it's a valley. $\endgroup$ – robert bristow-johnson Jul 25 '17 at 4:13
1
$\begingroup$

The earliest use of the word "peak" in the IEEE library is from 1937

H. Roder, "Effects of Tuned Circuits upon a Frequency Modulated Signal," in Proceedings of the Institute of Radio Engineers, vol. 25, no. 12, pp. 1617-1647, Dec. 1937. doi: 10.1109/JRPROC.1937.228819 Abstract: Prior investigations indicated that the frequency modulated receiver would always respond to the signal having the largest amplitude. Thus, selective circuits would be required to pick out a desired signal existing simultaneously with a number of other signals. The first item considered in this paper is that the signal carrier is tuned to the steep side of the resonance curve. It is found that in this case conversion from frequency modulation into amplitude modulation can be effected. It is required that the amplitude and phase characteristic of the circuit be linear with respect to frequency over the whole frequency interval occupied by the modulated signal. In order to derive a faithful audio signal reproduction from the complete detection process, a phase modulated signal must be transformed into frequency modulation first. Next, the case is considered in which the signal carrier is tuned to the peak of the resonance curve. The single tuned circuit is taken up first and two methods of solution are presented. It is found that with certain values of the modulation index, the tuned circuit may cause very serious nonlinear distortion of the output. For large values of the modulation index the resulting variation in amplitude and frequency can be determined statically, while for very small values of the modulation index the effect of the tuned circuit is exactly analogous to that encountered with amplitude modulation. keywords: {Amplitude modulation;Chirp modulation;Frequency modulation;Nonlinear distortion;Phase detection;Phase frequency detector;Phase modulation;RLC circuits;Resonance;Signal processing}, URL: http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=1686321&isnumber=35536

As one of the commentators stated, it's a very basic operation but also one that is not trivial. The definition that I've used for myself is that a peak is a cell or bin that is higher than it's adjacent neighbors. It sometimes is the maximum likelihood estimate of discrete valued signal parameter. This really ages me, but on a 300 pound, Numerix, Mars 432 array processor, searching through an array and testing if the left and right values of an element of a vector for "peakness" was a slow operation and it was faster to do two off set vector subtractions, clip and do a vector "and".

$\endgroup$

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.