code: def peakdelta(v, delta, x=None):
      maxtab = []
      mintab = [] 
      if x is None:
          x = arange(len(v))
      v = asarray(v)
      if len(v) != len(x):
          sys.exit('Input vectors v and x must have same length')
      if not isscalar(delta):
          sys.exit('Input argument delta must be a scalar')
      if delta <= 0:
          sys.exit('Input argument delta must be positive')
      mn, mx = Inf, -Inf
      mnpos, mxpos = NaN, NaN
      lookformax = True
      for i in 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 array(maxtab), array(mintab)