def simple_peakfinder(x, y, delta):
    """Detect local maxima and minima in a vector

    A point is considered a maximum peak if it has the maximal value, and was
    preceded (to the left) by a value lower by `delta`.

    Args
    ----
    y: ndarray
        array of values to find local maxima and minima in
    delta: float
        minimum change in `y` since previous peak to be considered new peak.
        It should be positive and it's absolute value taken to ensure this.
    x: ndarray
        corresponding x-axis positions to y array

    Returns
    -------
    max_ind: ndarray
        Indices of local maxima
    min_ind: ndarray
        Indices of local minima

    Example
    -------
    max_ind, min_ind = simple_peakfinder(x, y, delta)

    # get values of `y` at local maxima
    local_max = y[max_ind]

    Notes
    -----
    Matlab Author:      Eli Billauer   http://billauer.co.il/peakdet.html
    Python translation: Chris Muktar   https://gist.github.com/endolith/250860
    Python cleanup:     Ryan J. Dillon
    """
    import numpy
    y = numpy.asarray(y)
    max_ind = list()
    min_ind = list()
    local_min = numpy.inf
    local_max = -numpy.inf
    local_min_pos = numpy.nan
    local_max_pos = numpy.nan
    lookformax = True
    for i in range(len(y)):
        if y[i] > local_max:
            local_max = y[i]
            local_max_pos = x[i]
        if y[i] < local_min:
            local_min = y[i]
            local_min_pos = x[i]
        if lookformax:
            if y[i] < local_max - abs(delta):
                max_ind.append(local_max_pos)
                local_min = y[i]
                local_min_pos = x[i]
                lookformax = False
        elif y[i] > local_min + abs(delta):
            min_ind.append(local_min_pos)
            local_max = y[i]
            local_max_pos = x[i]
            lookformax = True
    return numpy.array(max_ind), numpy.array(min_ind)
