brainaccess.connect package
Submodules
brainaccess.connect.P300 module
- class brainaccess.connect.P300.P300(repetitions: int)[source]
Bases:
object
P300 BCI library
Initialize P300 model as per selected number of repetitions.
- Parameters:
repetitions (int) – number of repetitions to consider on each stimuli, can be either 1 or 3.
- Raises:
Exception – An error is raised if initializing failed
- predict(x: ndarray) float [source]
Predict P300
- Parameters:
x (np.ndarray) – data for classifier
- Returns:
probability that data was P300 event
- Return type:
float
- Raises:
Exception – An error is raised if prediction failed
Warning
Data sampled at 250 Hz must have these properties:
standardized with ewma and filtered with 1-40 Hz filter
(8, 176 * repetitions) shape (channels x samples),
each repetition 200 ms prior to stimulus onset up to 500 ms after stimulus onset
Channels must be in exactly this order: F3, F4, C3, C4, P3, P4, O1, O2
brainaccess.connect.SSVEP module
- class brainaccess.connect.SSVEP.SSVEP(frequencies: list = [], sample_rate: float = 250)[source]
Bases:
object
SSVEP BCI library
Initialize SSVEP model
- Parameters:
frequencies (list) – list of stimulation frequencies
sample_rate (float) – data sampling rate
- Raises:
Exception – An error is raised if initializing failed
- predict(x: ndarray, frequencies: Optional[list] = None, sample_rate: Optional[float] = None) tuple [source]
Classify EEG SSVEP (steady state visually evoked potentials) given a set of class frequencies
- Parameters:
x (np.ndarray) – EEG data (channels x samples) for classifier
frequencies (list) – list of stimulation frequencies
sample_rate (float) – data sampling rate
- Returns:
float – target frequency
float – target threshold value
- Raises:
Exception – An error is raised if prediction failed
Warning
Data must have these properties:
filtered with 1-90 Hz filter
selected channels must be from ocipital region
brainaccess.connect.processor module
- brainaccess.connect.processor.demean(x: ndarray) ndarray [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.ewma(x: ndarray, alpha: float = 0.001) ndarray [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: ndarray, alpha: float = 0.001, epsilon: float = 0.0001) ndarray [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: ndarray, sampling_freq: float) dict [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: ndarray, sampling_freq: float, freq_low: float, freq_high: float) ndarray [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: ndarray, sampling_freq: float, freq: float) ndarray [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: ndarray, sampling_freq: float, freq: float) ndarray [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: ndarray, sampling_freq: float, center_freq: float, width_freq: float) ndarray [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.mean(x: ndarray) ndarray [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