code: def _cosine_drift(period_cut, frametimes):
      """Create a cosine drift matrix with periods greater or equals to period_cut
  
      Parameters
      ----------
      period_cut: float
           Cut period of the low-pass filter (in sec)
      frametimes: array of shape(nscans)
           The sampling times (in sec)
  
      Returns
      -------
      cdrift:  array of shape(n_scans, n_drifts)
               cosin drifts plus a constant regressor at cdrift[:,0]
  
      Ref: http://en.wikipedia.org/wiki/Discrete_cosine_transform DCT-II
      """
      len_tim = len(frametimes)
      n_times = np.arange(len_tim)
      hfcut = 1.0 / period_cut  # input parameter is the period
  
      dt = (
          frametimes[1] - frametimes[0]
      )  # frametimes.max() should be (len_tim-1)*dt
      order = int(
          np.floor(2 * len_tim * hfcut * dt)
      )  # s.t. hfcut = 1/(2*dt) yields len_tim
      cdrift = np.zeros((len_tim, order))
      nfct = np.sqrt(2.0 / len_tim)
  
      for k in range(1, order):
          cdrift[:, k - 1] = nfct * np.cos(
              (np.pi / len_tim) * (n_times + 0.5) * k
          )
  
      cdrift[:, order - 1] = 1.0  # or 1./sqrt(len_tim) to normalize
      return cdrift
  
file_path: nipy/nipy/modalities/fmri/design_matrix.py
imports: from warnings import warn
  import numpy
  from .hemodynamic_models import _orthogonalize, compute_regressor
label_desc: Use image node_id 2 for calling a global function with example usage: _cosine_drift(period_cut, frametimes) and returns: cdrift