Skip to content

RF: refactor DCT-II into more visible function #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
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