code: def _color_noise(x, s_freq, coef=0):
      
      # convert to freq domain
      y = fft(x)
      ph = angle(y)
      m = abs(y)
  
      # frequencies for each fft value
      freq = linspace(0, s_freq / 2, int(len(m) / 2) + 1)
      freq = freq[1:-1]
  
      # create new power spectrum
      m1 = zeros(len(m))
      # leave zero alone, and multiply the rest by the function
      m1[1:int(len(m) / 2)] = m[1:int(len(m) / 2)] * f(freq, coef)
      # simmetric around nyquist freq
      m1[int(len(m1) / 2 + 1):] = m1[1:int(len(m1) / 2)][::-1]
  
      # reconstruct the signal
      y1 = m1 * exp(1j * ph)
      return real(ifft(y1))
docs: Add some color to the noise by changing the power spectrum.
  
      Parameters
      ----------
      x : ndarray
          one vector of the original signal
      s_freq : int
          sampling frequency
      coef : float
          coefficient to apply (0 -> white noise, 1 -> pink, 2 -> brown,
                                -1 -> blue)
  
      Returns
      -------
      ndarray
          one vector of the colored noise.