Skip to content
Merged
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
14 changes: 10 additions & 4 deletions hypyp/analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ def compute_single_freq(data: np.ndarray, sampling_rate: int, freq_range: list)
return complex_signal


def compute_freq_bands(data: np.ndarray, sampling_rate: int, freq_bands: dict, **filter_options) -> np.ndarray:
def compute_freq_bands(data: np.ndarray, sampling_rate: int, freq_bands: dict, filter_signal: bool = True , **filter_options) -> np.ndarray:
"""
Computes analytic signal per frequency band using FIR filtering
and Hilbert transform.
Expand All @@ -678,9 +678,12 @@ def compute_freq_bands(data: np.ndarray, sampling_rate: int, freq_bands: dict, *
real-valued data to compute analytic signal from.
sampling_rate:
sampling rate.
filter_signal:
bool: whether to apply a filter on the signal,
default, true
freq_bands:
a dictionary specifying frequency band labels and corresponding frequency ranges
e.g. {'alpha':[8,12],'beta':[12,20]} indicates that computations are performed over two frequency bands: 8-12 Hz for the alpha band and 12-20 Hz for the beta band.
e.g. {'alpha':[8,12], 'beta':[12,20]} indicates that computations are performed over two frequency bands: 8-12 Hz for the alpha band and 12-20 Hz for the beta band.
**filter_options:
additional arguments for mne.filter.filter_data, such as filter_length, l_trans_bandwidth, h_trans_bandwidth
Returns:
Expand All @@ -690,16 +693,19 @@ def compute_freq_bands(data: np.ndarray, sampling_rate: int, freq_bands: dict, *
assert data[0].shape[0] == data[1].shape[0], "Two data streams should have the same number of trials."
data = np.array(data)

# filtering and hilbert transform
# filtering and Hilbert transform
complex_signal = []
for freq_band in freq_bands.values():
filtered = np.array([mne.filter.filter_data(data[participant],
if filter_signal:
filtered = np.array([mne.filter.filter_data(data[participant],
sampling_rate, l_freq=freq_band[0], h_freq=freq_band[1],
**filter_options,
verbose=False)
for participant in range(2)
# for each participant
])
else:
filtered=np.array([data[participant] for participant in range(2)])
hilb = signal.hilbert(filtered)
complex_signal.append(hilb)

Expand Down