macro_eeg_model.evaluation.coherence_computer#
Classes#
A class responsible for computing the coherence between signals. |
Module Contents#
- class macro_eeg_model.evaluation.coherence_computer.CoherenceComputer(fs, window_type='hann')[source]#
A class responsible for computing the coherence between signals.
- fs#
The sampling frequency of the signals.
- Type:
int
- _window_type#
The type of window used for smoothing signals before coherence computation.
- Type:
str
- __init__(fs, window_type='hann')[source]#
Initializes the CoherenceComputer with the given sampling frequency and window type.
- Parameters:
fs (int) – The sampling frequency of the signals.
window_type (str, optional) – The type of window to apply for smoothing the signals before coherence computation (default is ‘hann’).
- compute_coherence_matched(sig1, sig2, smooth_signals=True)[source]#
Computes the coherence between two signals using
_compute_coherence(), with an option to smooth the signals before computation using_smooth_signal().- Parameters:
sig1 (numpy.ndarray) – The first signal array.
sig2 (numpy.ndarray) – The second signal array.
smooth_signals (bool, optional) – If True, applies a smoothing window to the signals before computing coherence (default is True).
- Returns:
A tuple containing:
positive_freqs (numpy.ndarray): The array of positive frequency values.
positive_coherence (numpy.ndarray): The coherence values corresponding to the positive frequencies.
- Return type:
tuple
- Raises:
AssertionError – If the two signals do not have the same shape.
- _compute_coherence(sig1, sig2)[source]#
Computes the coherence between two signals using their cross-spectrum and power spectra.
- Parameters:
sig1 (numpy.ndarray) – The first signal array with shape (nr_epochs, n_samples).
sig2 (numpy.ndarray) – The second signal array with the same shape as sig1.
- Returns:
A tuple containing:
positive_freqs (numpy.ndarray): The array of positive frequency values.
positive_coherence (numpy.ndarray): The coherence values corresponding to the positive frequencies.
- Return type:
tuple