Skip to content

Commit

Permalink
corrected inverse Fourier transform; mistake in using ifft caused abe…
Browse files Browse the repository at this point in the history
…rrant convolution
  • Loading branch information
MSenden committed Jan 17, 2022
1 parent b9c2ed0 commit 4d0b9cc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion code/python/cni_tlbx/HGR.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def __convolution__(self, x):
kernel = np.append(self.hrf, np.zeros(n_samples))
x = np.vstack((x, np.zeros((np.ceil(self.l_hrf / self.p_sampling).astype(int),
self.n_features))))
x_conv = np.abs(
x_conv = np.real(
ifft(fft(x, axis=0) *
np.expand_dims(fft(kernel),
axis=1), axis=0))
Expand Down
8 changes: 4 additions & 4 deletions code/python/cni_tlbx/IRM.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get_hrf(self):
else:
hrf = ifft(self.hrf_fft, axis = 0)[0:self.l_hrf]

return np.abs(hrf)
return np.real(hrf)

def get_stimulus(self):
'''
Expand All @@ -130,7 +130,7 @@ def get_timecourses(self):
predicted timecourses
'''

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

def set_hrf(self, hrf):
'''
Expand Down Expand Up @@ -256,7 +256,7 @@ def mapping(self, data, threshold = 100, mask = []):
if self.hrf_fft.ndim==1:
tc = np.transpose(
zscore(
np.abs(
np.real(
ifft(self.tc_fft *
np.expand_dims(self.hrf_fft,
axis = 1), axis = 0)), axis = 0))
Expand Down Expand Up @@ -287,7 +287,7 @@ def mapping(self, data, threshold = 100, mask = []):

tc = np.transpose(
zscore(
np.abs(
np.real(
ifft(self.tc_fft *
np.expand_dims(self.hrf_fft[:, v],
axis = 1), axis = 0)), axis = 0))
Expand Down
7 changes: 4 additions & 3 deletions code/python/cni_tlbx/gadgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ def two_gamma(timepoints):
hemodynamic response function
'''

hrf = (6 * timepoints**5 * np.exp(-timepoints)) / gamma(6) \
- 1 / 6 * (16 * timepoints ** 15 * np.exp(-timepoints)) \
hrf = (6 * (timepoints**5) * np.exp(-timepoints)) / gamma(6) \
- 1 / 6 * (16 * (timepoints ** 15) * np.exp(-timepoints)) \
/ gamma(16)
return hrf


def size(x,length):
'''
Parameters
Expand Down Expand Up @@ -246,7 +247,7 @@ def convolve(self, x):

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

return self.x_conv[self.step, :]
Expand Down
14 changes: 7 additions & 7 deletions code/python/cni_tlbx/pRF.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def get_hrf(self):
else:
hrf = ifft(self.hrf_fft, axis=0)[0:self.l_hrf]

return np.abs(hrf)
return np.real(hrf)

def get_stimulus(self):
'''
Expand All @@ -141,7 +141,7 @@ def get_timecourses(self):
predicted timecourses
'''

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

def set_hrf(self, hrf):
'''
Expand Down Expand Up @@ -287,7 +287,7 @@ def get_timecourses(self):
predicted timecourses
'''

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

def set_hrf(self, hrf):
'''
Expand Down Expand Up @@ -511,7 +511,7 @@ def _mapping_slope(self, data, threshold, mask):
if self.hrf_fft.ndim == 1:
tc = np.transpose(
zscore(
np.abs(
np.real(
ifft(self.tc_fft *
np.expand_dims(self.hrf_fft,
axis=1), axis=0)), axis=0))
Expand Down Expand Up @@ -545,7 +545,7 @@ def _mapping_slope(self, data, threshold, mask):

tc = np.transpose(
zscore(
np.abs(
np.real(
ifft(self.tc_fft *
np.expand_dims(self.hrf_fft[:, v],
axis=1), axis=0)), axis=0))
Expand Down Expand Up @@ -620,7 +620,7 @@ def _mapping_sigma(self, data, threshold, mask):
if self.hrf_fft.ndim == 1:
tc = np.transpose(
zscore(
np.abs(
np.real(
ifft(self.tc_fft *
np.expand_dims(self.hrf_fft,
axis=1), axis=0)), axis=0))
Expand Down Expand Up @@ -653,7 +653,7 @@ def _mapping_sigma(self, data, threshold, mask):

tc = np.transpose(
zscore(
np.abs(
np.real(
ifft(self.tc_fft *
np.expand_dims(self.hrf_fft[:, v],
axis=1), axis=0)), axis=0))
Expand Down

0 comments on commit 4d0b9cc

Please sign in to comment.