BrainAccess Connect C/C++ API Reference

SSVEP classifier

This section describes functions available for accessing the SSVEP classifier algorithm.

The steady-state visual evoked potential (SSVEP) is a repetitive evoked potential that is produces when viewing flashing stimuli. Activity at the same frequency as the visual stimulation can be detected in the occipital areas of the brain.

SSVEP classifier can recognize steady-state visual evoked potentials (SSVEP). Meaning that given a visual stimulus flickering at a constant frequency, SSVEP classifier can determine if the user is currently looking at it. This can be used as motionless control, where the user chooses an option by looking at the corresponding visual stimulus.

The workflow of using SSVEP classifier is as follows:

  1. Acquisition Setup. We recommend using 2-6 electrodes in the ocipital region (O1, O2, P3, P4, Oz, Pz) with reference at Fp1 and bias at Fp2.

  2. Initialize classifier with desired frequency combinations, prediction time interval and EEG sampling rate.

  3. Get predictions on input data

See all function descriptions for more information.

SSVEP classifier.

Functions

BA_BCICONNECT_DLL_EXPORT size_t ba_bci_connect_ssvep_classify (const double *x, size_t n_time_steps, size_t n_chans, double sampling_rate, const double *freqs, size_t n_classes, double *score) NOEXCEPT

Classifies EEG SSVEP (steady state visually evoked potentials).

Classifies EEG SSVEP (steady state visually evoked potentials) into a given set of class frequencies.

Parameters:
  • x – a pointer to an array containing EEG signals from different channels, channel n data should statrt at position x[n_chans*n_time_steps], total length of x array should be n_chans*n_time_steps

  • n_time_steps – number of time samples in each channel recording

  • n_chans – number of recording channels

  • sampling_rate – sampling rate in hertz.

  • freqs – a pointer to frequency class array.

  • n_classes – a number of frequency classes.

  • score – address where classification score will be stored.

Returns:

Best matching class, selected from given frequency class array.

Visual P300 classifier

This section describes functions available for accessing the Visual P300 classifier algorithm.

The P300 (P3) wave is an event-related potential (ERP) component elicited in the process of decision making. The P300 is thought to reflect processes involved in stimulus evaluation or categorization. It is usually elicited using the oddball paradigm, in which low-probability target items are mixed with high-probability non-target (or “standard”) items. When recorded by electroencephalography (EEG), it surfaces as a positive deflection in voltage with a latency (delay between stimulus and response) of roughly 250 to 500 ms. The signal is typically measured most strongly by the electrodes covering the parietal lobe [1] . This can be used as lie detector [2], speller [3] etc.

The workflow of using Visual P300 classifier is as follows:

  1. Acquisition Setup. 8 electrode setup (F3, F4, C3, C4, P3, P4, O1, O2) or 2 electrode setup (O1, O2) with reference at Fp1 and bias at Fp2 is required.

  2. Initialize classifier with model number (0-3).

    • 0 - 8 electrode Standard Kit setup, 1 repetitions

    • 1 - 8 electrode Standard Kit setup, 3 repetition

    • 2 - 8 electrode Standard Kit setup, 3 repetitions, “fast” - inter trial interval is 215ms

    • 3 - O1 and O2 electrodes only, 3 repetitions, “fast” - inter trial interval is 215ms

  3. Get predictions on input data sampled at 250 Hz

See all function descriptions for more information.

P300 classifier.

Functions

BA_BCICONNECT_DLL_EXPORT ba_bci_connect_error ba_bci_connect_p300_init (void **const p, const uint8_t model_number) NOEXCEPT

Initializes neural network model for P300.

This function initializes the P300 model, which can be selected from a model zoo. Models differ in the required number EEG electrode placements, number of repetitions and interstimuli time.

Parameters:
  • p – Pointer to P300 model instance

  • Model – number from a model zoo, currently available options are: 0 - 8 electrode Standard Kit setup, 3 repetitions 1 - 8 electrode Standard Kit setup, 1 repetition 2 - 8 electrode Standard Kit setup, 3 repetitions, “fast” - time between start of subsequent stimuli is 215ms 3 - O1 and O2 electrodes only, 3 repetitions, “fast” - time between start of subsequent stimuli is 215ms

Returns:

Error code

BA_BCICONNECT_DLL_EXPORT ba_bci_connect_error ba_bci_connect_p300_predict (void *const p, const double *const measurements, double *const result) NOEXCEPT

Predicts the probability of EEG signals containing P300 potential.

This function predicts the score of signal containing P300 potential.

Parameters:
  • A – pointer to an array containing EEG signals with dimensions number of channels * repetitions * no of samples (176). The data in the array should be arranged in such a manner [Channel0_1st_repetition, Channel0_2repetition, …, Channel1_1st_repetition, Channel1_2repetition …]

  • A – pointer to a result that reflects the probability of signal having P300 potential.

Returns:

Error code

BA_BCICONNECT_DLL_EXPORT ba_bci_connect_error ba_bci_connect_p300_free (void *const p) NOEXCEPT

Deletes a P300 instance.

Call exactly once to avoid undefined behavior and memory leaks

Parameters:

p – P300 instance to destroy

Processor

EEG signal processing.

Functions

BA_BCICONNECT_DLL_EXPORT void ba_bci_connect_get_signal_quality (double *x, const size_t n_chans, const size_t n_time_steps, double fs, double *quality) NOEXCEPT

Estimates the EEG signal quality.

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 – a pointer to an array containing EEG signals from different channels, channel n data should start at position x[n_chans * n_time_steps], total length of x array should be n_chans * n_time_steps

  • n_chans – number of recording channels

  • n_time_steps – number of time samples in each channel recording

  • quality – a pointer to an array which returns the quality of each channel, its length should be n_chans. Possible quality values: 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

BA_BCICONNECT_DLL_EXPORT void ba_bci_connect_detrend (double *x, const size_t n_chans, const size_t n_time_steps, double *x_detrend) NOEXCEPT

Detrends EEG signals.

This function subtracts the linear fit from EEG signals, essentially removing a linear trend from signals, calculated individually for each EEG channel

Parameters:
  • x – a pointer to an array containing EEG signals from different channels, channel n data should start at position x[n_chans * n_time_steps], total length of x array should be n_chans * n_time_steps

  • n_chans – number of recording channels

  • n_time_steps – number of time samples in each channel recording

  • x_detrend – a pointer to an array which returns detrended EEG signals, its length is the same as x

BA_BCICONNECT_DLL_EXPORT void ba_bci_connect_mean (const double *x, size_t n_chans, size_t n_time_steps, double *mean) NOEXCEPT

Calcultates the means of EEG signals.

This function calculates the means of EEG signals.

Parameters:
  • x – a pointer to an array containing EEG signals from different channels, channel n data should start at position x[n_chans * n_time_steps], total length of x array should be n_chans * n_time_steps

  • n_chans – number of recording channels

  • n_time_steps – number of time samples in each channel recording

  • mean – a pointer to an array which returns the mean of each channel, its length should be n_chans

BA_BCICONNECT_DLL_EXPORT void ba_bci_connect_std (const double *x, size_t n_chans, size_t n_time_steps, double *std) NOEXCEPT

Calcultates the standard deviation of EEG signals.

This function calculates the standard deviation of EEG signals.

Parameters:
  • x – a pointer to an array containing EEG signals from different channels, channel n data should start at position x[n_chans * n_time_steps], total length of x array should be n_chans * n_time_steps

  • n_chans – number of recording channels

  • n_time_steps – number of time samples in each channel recording

  • std – a pointer to an array which returns the standard deviation of each channel, its length should be n_chans

BA_BCICONNECT_DLL_EXPORT void ba_bci_connect_median (double *x, const size_t n_chans, const size_t n_time_steps, double *median) NOEXCEPT

Calcultates the median of EEG signals.

This function calculates the median of EEG signals.

Parameters:
  • x – a pointer to an array containing EEG signals from different channels, channel n data should start at position x[n_chans * n_time_steps], total length of x array should be n_chans * n_time_steps

  • n_chans – number of recording channels

  • n_time_steps – number of time samples in each channel recording

  • median – a pointer to an array which returns the median of each channel, its length should be n_chans

BA_BCICONNECT_DLL_EXPORT void ba_bci_connect_mad (double *x, const size_t n_chans, const size_t n_time_steps, double *mad) NOEXCEPT

Calcultates the median absolute deviation of EEG signals.

This function calculates the meadian absolute deviation of EEG signals.

Parameters:
  • x – a pointer to an array containing EEG signals from different channels, channel n data should start at position x[n_chans * n_time_steps], total length of x array should be n_chans * n_time_steps

  • n_chans – number of recording channels

  • n_time_steps – number of time samples in each channel recording

  • mad – a pointer to an array which returns the meadian absolute deviation of each channel, its length should be n_chans

BA_BCICONNECT_DLL_EXPORT void ba_bci_connect_demean (const double *x, size_t n_chans, size_t n_time_steps, double *x_demean) NOEXCEPT

Subtracts the mean from EEG signals.

This function subtracts the mean from EEG signals, essentially removing the DC offset in the EEG recordings

Parameters:
  • x – a pointer to an array containing EEG signals from different channels, channel n data should start at position x[n_chans * n_time_steps], total length of x array should be n_chans * n_time_steps

  • n_chans – number of recording channels

  • n_time_steps – number of time samples in each channel recording

  • x_demean – a pointer to an array which returns EEG signals with subtracted mean, its length is the same as x

BA_BCICONNECT_DLL_EXPORT void ba_bci_connect_standartize (const double *x, size_t n_chans, size_t n_time_steps, double *x_standard) NOEXCEPT

Standardizes the provided EEG signals.

This function standardizes the provided EEG signals, essentially making the mean of the signals equal to zero and standard deviation to one.

Parameters:
  • x – a pointer to an array containing EEG signals from different channels, channel n data should start at position x[n_chans * n_time_steps], total length of x array should be n_chans * n_time_steps

  • n_chans – number of recording channels

  • n_time_steps – number of time samples in each channel recording

  • x_standard – a pointer to an array which returns standardized EEG signals, its length is the same as x

BA_BCICONNECT_DLL_EXPORT void ba_bci_connect_ewma (const double *x, size_t n_chans, size_t n_time_steps, double alpha, double *ewma) NOEXCEPT

Calculates exponential weigted moving average of EEG signals.

This function calculates exponential weighted moving average of EEG signals

Parameters:
  • x – a pointer to an array containing EEG signals from different channels, channel n data should start at position x[n_chans * n_time_steps], total length of x array should be n_chans * n_time_steps

  • n_chans – number of recording channels

  • n_time_steps – number of time samples in each channel data

  • ewma – a pointer to an array which returns the calculated average for each channel, its length should be n_chans

BA_BCICONNECT_DLL_EXPORT void ba_bci_connect_ewma_standartize (const double *x, size_t n_chans, size_t n_time_steps, double alpha, double epsilon, double *x_standard) NOEXCEPT

Standardizes the provided EEG signals using exponential weighted moving average.

This function standardizes the provided EEG signals using exponential weighted moving average

Parameters:
  • x – a pointer to an array containing EEG signals from different channels, channel n data should start at position x[n_chans * n_time_steps], total length of x array should be n_chans * n_time_steps

  • n_chans – number of recording channels

  • n_time_steps – number of time samples in each channel data

  • alpha – smoothing factor, in braindecode alpha = 0.001

  • epsilon – stabilizer for division by zero variance, in braindecode epsilon = 1e-4

  • x_standard – a pointer to an array which returns standardized EEG signals, its length should be the same as x

BA_BCICONNECT_DLL_EXPORT void ba_bci_connect_filter_lowpass (double *x, size_t n_chans, size_t n_time_steps, double sampling_freq, double cutoff_freq) NOEXCEPT

Lowpass filtering of the provided EEG signals.

This function lowpass filters the provided EEG signals using 5th order Butterworth filter, phase is corrected for zero lag

Parameters:
  • x – a pointer to an array containing EEG signals from different channels, channel n data should start at position x[n_chans * n_time_steps], total length of x array should be n_chans * n_time_steps, the array data is replaced with filtered signals, so the user is responsible in making a copy of original EEG signals if needed

  • n_chans – number of recording channels

  • n_time_steps – number of time samples in each channel data

  • sampling – frequency of EEG signals

  • cutoff_freq – cutoff frequency of low pass filter

BA_BCICONNECT_DLL_EXPORT void ba_bci_connect_filter_highpass (double *x, size_t n_chans, size_t n_time_steps, double sampling_freq, double cutoff_freq) NOEXCEPT

Highpass filtering of the provided EEG signals.

This function highpass filters the provided EEG signals using 5th order Butterworth filter, phase is corrected for zero lag

Parameters:
  • x – a pointer to an array containing EEG signals from different channels, channel n data should start at position x[n_chans * n_time_steps], total length of x array should be n_chans * n_time_steps, the array data is replaced with filtered signals, so the user is responsible in making a copy of original EEG signals if needed

  • n_chans – number of recording channels

  • n_time_steps – number of time samples in each channel data

  • sampling – frequency of EEG signals

  • cutoff_freq – cutoff frequency of highpass filter

BA_BCICONNECT_DLL_EXPORT void ba_bci_connect_filter_bandpass (double *x, size_t n_chans, size_t n_time_steps, double sampling_freq, double low_freq, double high_freq) NOEXCEPT

Bandpass filtering of the provided EEG signals.

This function bandpass filters the provided EEG signals using 4th order Butterworth filter, phase is corrected for zero lag

Parameters:
  • x – a pointer to an array containing EEG signals from different channels, channel n data should start at position x[n_chans * n_time_steps], total length of x array should be n_chans * n_time_steps, the array data is replaced with filtered signals, so the user is responsible in making a copy of original EEG signals if needed

  • n_chans – number of recording channels

  • n_time_steps – number of time samples in each channel data

  • sampling – frequency of EEG signals

  • low_freq – the low cutoff frequency

  • high_freq – the high cutoff frequency

BA_BCICONNECT_DLL_EXPORT void ba_bci_connect_filter_notch (double *x, size_t n_chans, size_t n_time_steps, double sampling_freq, double center_freq, double width_freq) NOEXCEPT

Notch filtering of the provided EEG signals.

This function notch filters the provided EEG signals using 4th order Butterworth filter, phase is corrected for zero lag

Parameters:
  • x – a pointer to an array containing EEG signals from different channels, channel n data should start at position x[n_chans * n_time_steps], total length of x array should be n_chans * n_time_steps, the array data is replaced with filtered signals, so the user is responsible in making a copy of original EEG signals if needed

  • n_chans – number of recording channels

  • n_time_steps – number of time samples in each channel data

  • sampling – frequency of EEG signals

  • center_freq – the center frequency of the notch filter

  • width_freq – the width of the filter, the filter cutoff frequencies are essentially centre_freq -/+ width_freq/2

BA_BCICONNECT_DLL_EXPORT void ba_bci_connect_fft (const double *x, size_t n_chans, size_t n_time_steps, double sampling_freq, double *magnitudes, double *phases) NOEXCEPT

Calculates FFT of the provided EEG signals.

This function calculates FFT of the provided EEG signals.

Parameters:
  • x – array containing EEG signals from different channels, channel n data should start at position x[n_chans * n_time_steps], total length of x array should be n_chans * n_time_steps,

  • n_chans – Number of recording channels

  • n_time_steps – Number of samples in each channel

  • sampling_freq – Frequency of EEG signals

  • magnitudes – Magnitudes output from FFT result. Must be of length n_chans * ((n_time_steps - (n_time_steps % 2)) / 2 + 1)

  • phases – Phases output from FFT result, in radians. Must be of length n_chans * ((n_time_steps - (n_time_steps % 2)) / 2 + 1)

BA_BCICONNECT_DLL_EXPORT void ba_bci_connect_minmax (double *x, const size_t n_chans, const size_t n_time_steps, double *x_min, double *x_max) NOEXCEPT

Calculates the min and max values of EEG signals.

This function calculates min and max values of each EEG channel signal

Parameters:
  • x – a pointer to an array containing EEG signals from different channels, channel n data should start at position x[n_chans * n_time_steps], total length of x array should be n_chans * n_time_steps

  • n_chans – number of recording channels

  • n_time_steps – number of time samples in each channel recording

  • x_min – a pointer to an array which returns the min value calculated for each channel

  • x_max – a pointer to an array which returns the max value calculated for each channel

Version numbers.

Functions

BA_BCICONNECT_DLL_EXPORT const ba_version * ba_bci_connect_get_version () NOEXCEPT

Returns the installed library’s actual version.

Uses semantic versioning

Returns:

Installed library’s actual version

struct ba_version
#include <version.h>

Struct describing version numbers.

Uses semantic versioning

Public Members

uint8_t major

API-breaking changes.

uint8_t minor

Feature updates.

uint8_t patch

Bugfixes.