brainaccess.connect.processor#
Functions#
|
Cut data into epochs |
|
Subtract mean from each channel |
|
Remove linear trend from each channel |
|
Exponential weighed moving average helper_function |
|
Exponential weighed moving average standardization |
|
Compute the discrete Fourier Transform (DFT) with the efficient Fast Fourier Transform (FFT) algorithm |
|
Bandpass filter |
|
High-pass filter |
|
Low-pass filter |
|
Notch filter at desired frequency |
|
EEG power in delta, theta, alpha, beta and gamma frequency bands for each channel |
|
Calculate min and max for each channel in the data |
|
Power Spectrum (computed by frequency bands). |
Calculate signal quality for each channel in the data |
|
|
Calculate median absolute deviation for each channel in the data |
|
Calculate mean for each channel in the data |
|
Calculate median for each channel in the data |
|
Data standardization |
|
Calculate standard deviation for each channel in the data |
Module Contents#
- brainaccess.connect.processor.cut_into_epochs(data, sfreq, epoch_length=None, overlap=0.5)[source]#
Cut data into epochs
- Parameters:
data (ndarray) – np.ndarray: (n_channels, n_times)
sfreq (float) – float: sampling frequency
epoch_len – float: (Default value = 1.0) length of epoch in seconds
overlap (float) – float: (Default value = 0.0) ratio of overlap between epochs
epoch_length (float | None)
- Returns:
np.ndarray: (n_epochs, n_channels, n_times)
- Return type:
output
- brainaccess.connect.processor.demean(x)[source]#
Subtract mean from each channel
- Parameters:
x (np.ndarray) – data array, shape (channels, time)
- Returns:
data array, shape (channels, time)
- Return type:
np.ndarray
- brainaccess.connect.processor.detrend(x)[source]#
Remove linear trend from each channel
- Parameters:
x (np.ndarray) – data array, shape (channels, time)
- Returns:
data array, shape (channels, time)
- Return type:
np.ndarray
- brainaccess.connect.processor.ewma(x, alpha=0.001)[source]#
Exponential weighed moving average helper_function
- Parameters:
x (np.ndarray) – data array, shape (channels, time)
alpha (float) – new factor
- Returns:
data array, shape (channels, time)
- Return type:
np.ndarray
- brainaccess.connect.processor.ewma_standardize(x, alpha=0.001, epsilon=0.0001)[source]#
Exponential weighed moving average standardization
First-order infinite impulse response filter that applies weighting factors which decrease exponentially
- Parameters:
x (np.ndarray) – data array, shape (channels, time)
alpha (float) – Represents the degree of weighting decrease, a constant smoothing factor between 0 and 1. A higher alpha discounts older observations faster.
epsilon (float) – Stabilizer for division by zero variance
- Returns:
data array, shape (channels, time)
- Return type:
np.ndarray
- brainaccess.connect.processor.fft(x, sampling_freq)[source]#
Compute the discrete Fourier Transform (DFT) with the efficient Fast Fourier Transform (FFT) algorithm
- Parameters:
x (np.ndarray) – data array, shape (channels, time)
sampling_freq (float) – data sampling rate
- Returns:
dictionary (key: value) - freq: frequencies - mag: amplitudes - phase: phases
- Return type:
dict
- brainaccess.connect.processor.filter_bandpass(x, sampling_freq, freq_low, freq_high)[source]#
Bandpass filter
Butterworth 5th order zero phase bandpass filter
- Parameters:
x (np.ndarray) – data array, shape (channels, time)
sampling_freq (float) – data sampling rate
freq_low (float) – frequency to filter from
freq_high (float) – frequency to filter to
- Returns:
filtered data, shape (channels, time)
- Return type:
np.ndarray
Warning
Data must be detrended or passed through ba_bci_connect_ewma_standartize before applying notch filter
- brainaccess.connect.processor.filter_highpass(x, sampling_freq, freq)[source]#
High-pass filter
Butterworth 5th order zero phase high-pass filter
- Parameters:
x (np.ndarray) – data array, shape (channels, time)
sampling_freq (float) – data sampling rate
freq (float) – edge frequency
- Returns:
filtered data, shape (channels, time)
- Return type:
np.ndarray
Warning
Data must be detrended or passed through ba_bci_connect_ewma_standartize before applying notch filter
- brainaccess.connect.processor.filter_lowpass(x, sampling_freq, freq)[source]#
Low-pass filter
Butterworth 5th order zero phase low-pass filter
- Parameters:
x (np.ndarray) – data array, shape (channels, time)
sampling_freq (float) – data sampling rate
freq (float) – edge frequency
- Returns:
filtered data, shape (channels, time)
- Return type:
np.ndarray
Warning
Data must be detrended or passed through ba_bci_connect_ewma_standartize before applying notch filter
- brainaccess.connect.processor.filter_notch(x, sampling_freq, center_freq, width_freq)[source]#
Notch filter at desired frequency
Butterworth 4th order zero phase bandpass filter
- Parameters:
x (np.ndarray) – data array, shape (channels, time)
sampling_freq (float) – data sampling rate
center_freq (float) – notch filter center frequency
width_freq (float) – notch filter width
- Returns:
data array, shape (channels, time)
- Return type:
np.ndarray
Warning
Data must be detrended or passed through ba_bci_connect_ewma_standartize before applying notch filter
- brainaccess.connect.processor.get_bands(data, sfreq, epoch_length=None, overlap=0.1, normalize=False)[source]#
EEG power in delta, theta, alpha, beta and gamma frequency bands for each channel
- Parameters:
data (ndarray) – np.ndarray: (n_channels, n_times)
sfreq (float) – float: sampling frequency
epoch_length (float | None) – Optional[float]: (Default value = None) To reduce noise, data is cut into epochs and mean power values calculated If None, epoch length is 5 seconds for data longer then 15 seconds, otherwise all data is used without epoching
overlap (float) – float: (Default value = 0.1) Ratio of overlap between epochs
normalize (bool) – bool: (Default value = False) Normalize power in each frequency band by total power
- Returns:
- dict:
delta: np.ndarray (n_channels)
theta: np.ndarray (n_channels)
alpha: np.ndarray (n_channels)
beta: np.ndarray (n_channels)
gamma: np.ndarray (n_channels)
- Return type:
output
- brainaccess.connect.processor.get_minmax(x)[source]#
Calculate min and max for each channel in the data
- Parameters:
x (np.ndarray) – data array, shape (channels, time)
- Returns:
min and max for each channel in the same order as x
- Return type:
dict
- brainaccess.connect.processor.get_pow_freq_bands(data, sfreq, freq_bands=np.array([0.5, 4.0, 8.0, 13.0, 30.0, 100.0]), normalize=False)[source]#
Power Spectrum (computed by frequency bands).
- Parameters:
data (ndarray) – np.ndarray: (n_channels, n_times)
sfreq (float) – float: sampling frequency
freq_bands (ndarray) – np.ndarray: (Default value = np.array([0.5, 4.0, 8.0, 13.0, 30.0,
100.0])) – frequency intervals defining bands: delta, theta, alpha, beta, gamma (default)
normalize (bool) – bool: (Default value = True) normalize power in each frequency band by total power
- Returns:
ndarray, shape (n_channels, (len(freq_bands)- 1),)
- Return type:
output
- brainaccess.connect.processor.get_signal_quality(x)[source]#
Calculate signal quality for each channel in the data This function estimates the EEG signal quality for each channel based on amplitude variation and 50/60Hz noise level. The supplied data should be unprocessed of 2-3 seconds length. If signals do not pass the quality measures of this function, then it means that they are really corrupted or the electrodes are not fitted. Eye or muscle artifacts are not evaluated by this function, signals containing theses should still pass the quality measures.
- Parameters:
x (np.ndarray) – data array, shape (channels, time)
- Returns:
signal quality for each channel in the same order as x * 0 - signal is bad and did not pass any quality measure * 1 - signal passed amplitude related quality measures * 2 - signal also do not contain significant amounts of 50/60Hz noise
- Return type:
np.ndarray
- brainaccess.connect.processor.mad(x)[source]#
Calculate median absolute deviation for each channel in the data
- Parameters:
x (np.ndarray) – data array, shape (channels, time)
- Return type:
np.ndarray
- brainaccess.connect.processor.mean(x)[source]#
Calculate mean for each channel in the data
- Parameters:
x (np.ndarray) – data array, shape (channels, time)
- Returns:
means for each channel in the same order as x
- Return type:
np.ndarray
- brainaccess.connect.processor.median(x)[source]#
Calculate median for each channel in the data
- Parameters:
x (np.ndarray) – data array, shape (channels, time)
- Returns:
medians for each channel in the same order as x
- Return type:
np.ndarray