Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
RF: refactor cosine basis to use dct-ii function
Use dedicated function for _cosine basis.

This refactoring will require continuous times, otherwise it will raise
an error.  In any case, I believe that the values returned when times
are not continuous are not valid:

a) The current function assumes that all differences in volume times are
equal to the difference in the first two volume times, and;
b) The DCT values should (I believe) reflect the number of `dt`
intervals, not the index into the time vector, as currently.
  • Loading branch information
matthew-brett committed Feb 6, 2017
commit f3be3eeef8eccd32eced8e8469cb74f77359637c
33 changes: 2 additions & 31 deletions nipy/modalities/fmri/design_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from ...utils.compat3 import open4csv

from .hemodynamic_models import compute_regressor, _orthogonalize
from .realfuncs import dct_ii_cut_basis


######################################################################
Expand Down Expand Up @@ -63,37 +64,7 @@ def _poly_drift(order, frametimes):


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./ 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 + .5)*k)

cdrift[:,order-1] = 1. # or 1./sqrt(len_tim) to normalize
return cdrift

return dct_ii_cut_basis(frametimes, period_cut)


def _blank_drift(frametimes):
Expand Down