code: def _summaries_welch_rect(X, centroid, X_fft):
      new_length = int(len(X_fft) / 2) + 1
      p = np.zeros(new_length)
      pi2 = 2 * math.pi
      p[0] = (np.power(_complex_magnitude(X_fft[0]), 2) / len(X)) / pi2
      for i in range(1, new_length - 1):
          p[i] = (
              (np.power(_complex_magnitude(X_fft[i]), 2) / len(X)) * 2
          ) / pi2
      p[new_length - 1] = (
          np.power(_complex_magnitude(X_fft[new_length - 1]), 2)
          / len(X)
      ) / pi2
  
      w = np.zeros(new_length)
      a = 1.0 / len(X_fft)
      for i in range(0, new_length):
          w[i] = i * a * math.pi * 2
  
      if centroid:
          cs = np.zeros(new_length)
          cs[0] = p[0]
          for i in range(1, new_length):
              cs[i] = cs[i - 1] + p[i]
  
          threshold = cs[new_length - 1] / 2
          for i in range(1, new_length):
              if cs[i] > threshold:
                  return w[i]
          return np.nan
      else:
          tau = int(np.floor(new_length / 5))
          nsum = 0
          for i in range(tau):
              nsum += p[i]
  
          return nsum * (w[1] - w[0])
  
imports: import math
  import numpy
  from sktime.utils.numba.njit import njit
label_desc: Use image node_id 7 for calling a global function with example usage: _summaries_welch_rect(X, centroid, X_fft) and returns: np, unknown, w