-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1eb65f3
commit 784d574
Showing
1 changed file
with
25 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,30 @@ | ||
time_series = masker.fit_transform(sub, confounds=confounds[i]) | ||
|
||
#Clean data using bandpass filtering Butterworth from Nilearn | ||
import nilearn | ||
time_series_cleaned = nilearn.signal.clean(time_series, sessions=None, detrend=True, standardize=None, confounds=None, low_pass=0.25, high_pass=0.01, t_r=2.0, ensure_finite=True) | ||
from scipy import signal | ||
import numpy as np | ||
|
||
def create_falff(time_series): | ||
#Clean data using bandpass filtering Butterworth from Nilearn | ||
time_series_cleaned = nilearn.signal.clean(time_series.T, sessions=None, detrend=True, | ||
standardize=None, confounds=None, | ||
low_pass=0.25, high_pass=0.01, t_r=2.0, | ||
ensure_finite=True) | ||
|
||
#Compute power spectra | ||
freqs_cleaned, psd_cleaned = signal.welch(time_series_cleaned, fs=0.5, window='boxcar', | ||
nperseg=None, noverlap=None, nfft=168, | ||
detrend='constant', return_onesided=False, | ||
scaling='spectrum', axis=-1, average='mean') | ||
|
||
#Compute power spectra | ||
freqs_cleaned, psd_cleaned = signal.welch(time_series_cleaned, fs=0.5, window='boxcar', nperseg=None, noverlap=None, nfft=168, detrend='constant', return_onesided=False, scaling='spectrum', axis=-1, average='mean') | ||
#Compute fALFF | ||
fALFF_container = [] | ||
for row in psd_cleaned: | ||
low_freq = row[(freqs_cleaned>=0) & (freqs_cleaned<=0.08)] | ||
sum_low_freq = np.sum(low_freq) | ||
all_freq = row[(freqs_cleaned>=0) & (freqs_cleaned<=0.25)] | ||
sum_all_freq = np.sum(all_freq) | ||
fALFF=sum_low_freq/sum_all_freq | ||
|
||
#Compute fALFF | ||
low_freq=psd_cleaned[0,(freqs_cleaned>=0) & (freqs_cleaned<=0.08)] | ||
sum_low_freq = np.sum(low_freq) | ||
all_freq = psd_cleaned[0,(freqs_cleaned>=0) & (freqs_cleaned<=0.25)] | ||
sum_all_freq = np.sum(all_freq) | ||
fALFF=sum_low_freq/sum_all_freq | ||
fALFF_container.append(fALFF) | ||
|
||
|
||
return fALFF_container |