code: def PSD_continuous(t, h, axis=-1, method=1):
      r"""Approximate a continuous 1D Power Spectral Density of sampled data.
  
      This function uses the Fast Fourier Transform to approximate
      the continuous fourier transform of a sampled function, using
      the convention
  
      .. math::
  
          H(f) = \int h(t) \exp(-2 \pi i f t) dt
  
      It returns f and PSD, which approximate PSD(f) where
  
      .. math::
  
          PSD(f) = |H(f)|^2 + |H(-f)|^2
  
      Parameters
      ----------
      t : array_like
          regularly sampled array of times
          t is assumed to be regularly spaced, i.e.
          t = t0 + Dt * np.arange(N)
      h : array_like
          real or complex signal at each time
      axis : int
          axis along which to perform fourier transform.
          This axis must be the same length as t.
  
      Returns
      -------
      f : ndarray
          frequencies of result.  Units are the same as 1/t
      PSD : ndarray
          Fourier coefficients at each frequency.
      """
      assert t.ndim == 1
      assert h.shape[axis] == t.shape[0]
      N = len(t)
      if N % 2 != 0:
          raise ValueError("number of samples must be even")
  
      ax = axis % h.ndim
  
      if method == 1:
          # use FT_continuous
          f, Hf = FT_continuous(t, h, axis)
          Hf = np.rollaxis(Hf, ax)
          f = -f[N // 2 :: -1]
          PSD = abs(Hf[N // 2 :: -1]) ** 2
          PSD[:-1] += abs(Hf[N // 2 :]) ** 2
          PSD = np.rollaxis(PSD, 0, ax + 1)
      else:
          # A faster way to do it is with fftshift
          # take advantage of the fact that phases go away
          Dt = t[1] - t[0]
          Df = 1.0 / (N * Dt)
          f = Df * np.arange(N // 2 + 1)
          Hf = fft(h, axis=axis)
          Hf = np.rollaxis(Hf, ax)
          PSD = abs(Hf[: N // 2 + 1]) ** 2
          PSD[-1] = 0
          PSD[1:] += abs(Hf[N // 2 :][::-1]) ** 2
          PSD[0] *= 2
          PSD = Dt**2 * np.rollaxis(PSD, 0, ax + 1)
  
      return f, PSD
  
file_path: astroML/astroML/fourier.py
imports: import numpy
label_desc: Use image node_id 3 for calling a global function with example usage: PSD_continuous(t, h, axis, method) and returns: f,  PSD