Skip to content

Commit 4d0b9cc

Browse files
author
MSenden
committed
corrected inverse Fourier transform; mistake in using ifft caused aberrant convolution
1 parent b9c2ed0 commit 4d0b9cc

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

code/python/cni_tlbx/HGR.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def __convolution__(self, x):
435435
kernel = np.append(self.hrf, np.zeros(n_samples))
436436
x = np.vstack((x, np.zeros((np.ceil(self.l_hrf / self.p_sampling).astype(int),
437437
self.n_features))))
438-
x_conv = np.abs(
438+
x_conv = np.real(
439439
ifft(fft(x, axis=0) *
440440
np.expand_dims(fft(kernel),
441441
axis=1), axis=0))

code/python/cni_tlbx/IRM.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def get_hrf(self):
110110
else:
111111
hrf = ifft(self.hrf_fft, axis = 0)[0:self.l_hrf]
112112

113-
return np.abs(hrf)
113+
return np.real(hrf)
114114

115115
def get_stimulus(self):
116116
'''
@@ -130,7 +130,7 @@ def get_timecourses(self):
130130
predicted timecourses
131131
'''
132132

133-
return np.abs(ifft(self.tc_fft, axis = 0)[0:self.n_samples, :])
133+
return np.real(ifft(self.tc_fft, axis = 0)[0:self.n_samples, :])
134134

135135
def set_hrf(self, hrf):
136136
'''
@@ -256,7 +256,7 @@ def mapping(self, data, threshold = 100, mask = []):
256256
if self.hrf_fft.ndim==1:
257257
tc = np.transpose(
258258
zscore(
259-
np.abs(
259+
np.real(
260260
ifft(self.tc_fft *
261261
np.expand_dims(self.hrf_fft,
262262
axis = 1), axis = 0)), axis = 0))
@@ -287,7 +287,7 @@ def mapping(self, data, threshold = 100, mask = []):
287287

288288
tc = np.transpose(
289289
zscore(
290-
np.abs(
290+
np.real(
291291
ifft(self.tc_fft *
292292
np.expand_dims(self.hrf_fft[:, v],
293293
axis = 1), axis = 0)), axis = 0))

code/python/cni_tlbx/gadgets.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ def two_gamma(timepoints):
6666
hemodynamic response function
6767
'''
6868

69-
hrf = (6 * timepoints**5 * np.exp(-timepoints)) / gamma(6) \
70-
- 1 / 6 * (16 * timepoints ** 15 * np.exp(-timepoints)) \
69+
hrf = (6 * (timepoints**5) * np.exp(-timepoints)) / gamma(6) \
70+
- 1 / 6 * (16 * (timepoints ** 15) * np.exp(-timepoints)) \
7171
/ gamma(16)
7272
return hrf
7373

74+
7475
def size(x,length):
7576
'''
7677
Parameters
@@ -246,7 +247,7 @@ def convolve(self, x):
246247

247248
x_fft = fft(np.vstack((x.reshape(1,-1), np.zeros((self.l_subsampled - 1, self.n_channels)))), axis=0)
248249
self.x_conv = np.vstack((self.x_conv, np.zeros((1, self.n_channels))))
249-
self.x_conv[self.step:self.step + self.l_subsampled, :] += np.abs(ifft(
250+
self.x_conv[self.step:self.step + self.l_subsampled, :] += np.real(ifft(
250251
x_fft * np.expand_dims(self.hrf_fft , axis=1), axis=0))
251252

252253
return self.x_conv[self.step, :]

code/python/cni_tlbx/pRF.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def get_hrf(self):
116116
else:
117117
hrf = ifft(self.hrf_fft, axis=0)[0:self.l_hrf]
118118

119-
return np.abs(hrf)
119+
return np.real(hrf)
120120

121121
def get_stimulus(self):
122122
'''
@@ -141,7 +141,7 @@ def get_timecourses(self):
141141
predicted timecourses
142142
'''
143143

144-
return np.abs(ifft(self.tc_fft, axis=0)[0:self.n_samples, :])
144+
return np.real(ifft(self.tc_fft, axis=0)[0:self.n_samples, :])
145145

146146
def set_hrf(self, hrf):
147147
'''
@@ -287,7 +287,7 @@ def get_timecourses(self):
287287
predicted timecourses
288288
'''
289289

290-
return np.abs(ifft(self.tc_fft, axis=0)[0:self.n_samples, :])
290+
return np.real(ifft(self.tc_fft, axis=0)[0:self.n_samples, :])
291291

292292
def set_hrf(self, hrf):
293293
'''
@@ -511,7 +511,7 @@ def _mapping_slope(self, data, threshold, mask):
511511
if self.hrf_fft.ndim == 1:
512512
tc = np.transpose(
513513
zscore(
514-
np.abs(
514+
np.real(
515515
ifft(self.tc_fft *
516516
np.expand_dims(self.hrf_fft,
517517
axis=1), axis=0)), axis=0))
@@ -545,7 +545,7 @@ def _mapping_slope(self, data, threshold, mask):
545545

546546
tc = np.transpose(
547547
zscore(
548-
np.abs(
548+
np.real(
549549
ifft(self.tc_fft *
550550
np.expand_dims(self.hrf_fft[:, v],
551551
axis=1), axis=0)), axis=0))
@@ -620,7 +620,7 @@ def _mapping_sigma(self, data, threshold, mask):
620620
if self.hrf_fft.ndim == 1:
621621
tc = np.transpose(
622622
zscore(
623-
np.abs(
623+
np.real(
624624
ifft(self.tc_fft *
625625
np.expand_dims(self.hrf_fft,
626626
axis=1), axis=0)), axis=0))
@@ -653,7 +653,7 @@ def _mapping_sigma(self, data, threshold, mask):
653653

654654
tc = np.transpose(
655655
zscore(
656-
np.abs(
656+
np.real(
657657
ifft(self.tc_fft *
658658
np.expand_dims(self.hrf_fft[:, v],
659659
axis=1), axis=0)), axis=0))

0 commit comments

Comments
 (0)