code: def peakdet(signal, delta, x=None):
      
      
      maxtab = []
      mintab = []
  
      if x is None:
          x = np.arange(len(signal))
  
      v = np.asarray(signal)
  
      if len(v) != len(x):
          sys.exit('Input vectors v and x must have same length')
  
      if not np.isscalar(delta):
          sys.exit('Input argument delta must be a scalar')
  
      if delta <= 0:
          sys.exit('Input argument delta must be positive')
  
      mn, mx = np.inf, -np.inf
      mnpos, mxpos = np.nan, np.nan
  
      lookformax = True
  
      for i in np.arange(len(v)):
          this = v[i]
          if this > mx:
              mx = this
              mxpos = x[i]
          if this < mn:
              mn = this
              mnpos = x[i]
  
          if lookformax:
              if this < mx - delta:
                  maxtab.append((mxpos, mx))
                  mn = this
                  mnpos = x[i]
                  lookformax = False
          else:
              if this > mn + delta:
                  mintab.append((mnpos, mn))
                  mx = this
                  mxpos = x[i]
                  lookformax = True
  
      return np.array(maxtab), np.array(mintab)
docs: Find the local maxima and minima (peaks) in a 1-dimensional signal.
          Converted from MATLAB script <http://billauer.co.il/peakdet.html>
  
          :param array signal: A 1-dimensional array or list (the signal).
          :type signal: array
          :param delta: The peak threashold. 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.
          :type delta: float
          :param x: Indices in local maxima and minima are replaced with the corresponding values in x (None default).
          :type x: array
          :return maxtab: The highest peaks.
          :rtype maxtab: numpy.ndarray
          :return mintab: The lowest peaks.
          :rtype mintab: numpy.ndarray