code: def complexity_fd_petrosian(signal):
      
      diff = np.diff(signal)
      # x[i] * x[i-1] for i in t0 -> tmax
      prod = diff[1:-1] * diff[0:-2]
  
      # Number of sign changes in derivative of the signal
      N_delta = np.sum(prod < 0)
      n = len(signal)
      fd_petrosian = np.log(n)/(np.log(n)+np.log(n/(n+0.4*N_delta)))
      return(fd_petrosian)
docs: Computes the Petrosian Fractal Dimension of a signal. Based on the `pyrem <https://github.com/gilestrolab/pyrem>`_ repo by Quentin Geissmann.
  
      Parameters
      ----------
      signal : list or array
          List or array of values.
  
      Returns
      ----------
      fd_petrosian : float
          The Petrosian FD as float value.
  
  
      Example
      ----------
      >>> import neurokit as nk
      >>>
      >>> signal = np.sin(np.log(np.random.sample(666)))
      >>> fd_petrosian = nk.complexity_fd_petrosian(signal, 1, 2)
  
      Notes
      ----------
      *Details*
  
      - **Petrosian Fractal Dimension**: Provide a fast computation of the FD of a signal by translating the series into a binary sequence.
  
      *Authors*
  
      - Quentin Geissmann (https://github.com/qgeissmann)
  
      *Dependencies*
  
      - numpy
  
      *See Also*
  
      - pyrem package: https://github.com/gilestrolab/pyrem