User API

BrainFlow User API has three main modules:

  • BoardShim to read data from a board, it calls methods from underlying BoardController library

  • DataFilter to perform signal processing, it calls methods from underlying DataHandler library

  • MLModel to calculate derivative metrics, it calls methods from underlying MLModule library

These classes are independent, so if you want, you can use BrainFlow API only for data streaming and perform signal processing by yourself and vice versa.

BrainFlow data acqusition API is board agnostic, so to select a specific board you need to pass BrainFlow’s board id to BoardShim’s constructor and an instance of BrainFlowInputParams structure which should hold information for your specific board, check Supported Boards. for details. This abstraction allows you to switch boards without any changes in code.

In BoardShim, all board data is returned as a 2d array. Rows in this array may contain timestamps, EEG and EMG data and so on. To see instructions how to query specific kind of data check Data Format Description and Code Samples.

Python API Reference

brainflow.board_shim

class brainflow.board_shim.BoardIds(value)

Bases: enum.IntEnum

Enum to store all supported Board Ids

PLAYBACK_FILE_BOARD = -3
STREAMING_BOARD = -2
SYNTHETIC_BOARD = -1
CYTON_BOARD = 0
GANGLION_BOARD = 1
CYTON_DAISY_BOARD = 2
GALEA_BOARD = 3
GANGLION_WIFI_BOARD = 4
CYTON_WIFI_BOARD = 5
CYTON_DAISY_WIFI_BOARD = 6
BRAINBIT_BOARD = 7
UNICORN_BOARD = 8
CALLIBRI_EEG_BOARD = 9
CALLIBRI_EMG_BOARD = 10
CALLIBRI_ECG_BOARD = 11
FASCIA_BOARD = 12
NOTION_OSC_BOARD = 13
NOTION_1_BOARD = 13
NOTION_2_BOARD = 14
IRONBCI_BOARD = 15
GFORCE_PRO_BOARD = 16
FREEEEG32_BOARD = 17
BRAINBIT_BLED_BOARD = 18
GFORCE_DUAL_BOARD = 19
GALEA_SERIAL_BOARD = 20
class brainflow.board_shim.LogLevels(value)

Bases: enum.IntEnum

Enum to store all log levels supported by BrainFlow

LEVEL_TRACE = 0
LEVEL_DEBUG = 1
LEVEL_INFO = 2
LEVEL_WARN = 3
LEVEL_ERROR = 4
LEVEL_CRITICAL = 5
LEVEL_OFF = 6
class brainflow.board_shim.IpProtocolType(value)

Bases: enum.IntEnum

Enum to store Ip Protocol types

NONE = 0
UDP = 1
TCP = 2
class brainflow.board_shim.BrainFlowInputParams

Bases: object

inputs parameters for prepare_session method

Parameters
  • serial_port (str) – serial port name is used for boards which reads data from serial port

  • mac_address (str) – mac address for example its used for bluetooth based boards

  • ip_address (str) – ip address is used for boards which reads data from socket connection

  • ip_port (int) – ip port for socket connection, for some boards where we know it in front you dont need this parameter

  • ip_protocol (int) – ip protocol type from IpProtocolType enum

  • other_info (str) – other info

  • serial_number (str) – serial number

  • file (str) – file

exception brainflow.board_shim.BrainFlowError(message: str, exit_code: int)

Bases: Exception

This exception is raised if non-zero exit code is returned from C code

Parameters
  • message (str) – exception message

  • exit_code (int) – exit code flow low level API

class brainflow.board_shim.BoardShim(board_id: int, input_params: brainflow.board_shim.BrainFlowInputParams)

Bases: object

BoardShim class is a primary interface to all boards

Parameters
  • board_id (int) – Id of your board

  • input_params (BrainFlowInputParams) – board specific structure to pass required arguments

classmethod set_log_level(log_level: int) → None

set BrainFlow log level, use it only if you want to write your own messages to BrainFlow logger, otherwise use enable_board_logger, enable_dev_board_logger or disable_board_logger

Parameters

log_level (int) – log level, to specify it you should use values from LogLevels enum

classmethod enable_board_logger() → None

enable BrainFlow Logger with level INFO, uses stderr for log messages by default

classmethod disable_board_logger() → None

disable BrainFlow Logger

classmethod enable_dev_board_logger() → None

enable BrainFlow Logger with level TRACE, uses stderr for log messages by default

classmethod log_message(log_level: int, message: str) → None

write your own log message to BrainFlow logger, use it if you wanna have single logger for your own code and BrainFlow’s code

Parameters
  • log_level – log level

  • message (str) – message

classmethod set_log_file(log_file: str) → None

redirect logger from stderr to file, can be called any time

Parameters

log_file (str) – log file name

classmethod get_sampling_rate(board_id: int) → int

get sampling rate for a board

Parameters

board_id (int) – Board Id

Returns

sampling rate for this board id

Return type

int

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_package_num_channel(board_id: int) → int

get package num channel for a board

Parameters

board_id (int) – Board Id

Returns

number of package num channel

Return type

int

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_battery_channel(board_id: int) → int

get battery channel for a board

Parameters

board_id (int) – Board Id

Returns

number of batter channel

Return type

int

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_num_rows(board_id: int) → int

get number of rows in resulting data table for a board

Parameters

board_id (int) – Board Id

Returns

number of rows in returned numpy array

Return type

int

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_timestamp_channel(board_id: int) → int

get timestamp channel in resulting data table for a board

Parameters

board_id (int) – Board Id

Returns

number of timestamp channel in returned numpy array

Return type

int

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_marker_channel(board_id: int) → int

get marker channel in resulting data table for a board

Parameters

board_id (int) – Board Id

Returns

number of marker channel in returned numpy array

Return type

int

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_eeg_names(board_id: int) → List[str]

get names of EEG channels in 10-20 system if their location is fixed

Parameters

board_id (int) – Board Id

Returns

EEG channels names

Return type

List[str]

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_device_name(board_id: int) → str

get device name

Parameters

board_id (int) – Board Id

Returns

Device Name

Return type

str

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_eeg_channels(board_id: int) → List[int]

get list of eeg channels in resulting data table for a board

Parameters

board_id (int) – Board Id

Returns

list of eeg channels in returned numpy array

Return type

List[int]

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_exg_channels(board_id: int) → List[int]

get list of exg channels in resulting data table for a board

Parameters

board_id (int) – Board Id

Returns

list of eeg channels in returned numpy array

Return type

List[int]

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_emg_channels(board_id: int) → List[int]

get list of emg channels in resulting data table for a board

Parameters

board_id (int) – Board Id

Returns

list of eeg channels in returned numpy array

Return type

List[int]

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_ecg_channels(board_id: int) → List[int]

get list of ecg channels in resulting data table for a board

Parameters

board_id (int) – Board Id

Returns

list of ecg channels in returned numpy array

Return type

List[int]

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_eog_channels(board_id: int) → List[int]

get list of eog channels in resulting data table for a board

Parameters

board_id (int) – Board Id

Returns

list of eog channels in returned numpy array

Return type

List[int]

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_eda_channels(board_id: int) → List[int]

get list of eda channels in resulting data table for a board

Parameters

board_id (int) – Board Id

Returns

list of eda channels in returned numpy array

Return type

List[int]

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_ppg_channels(board_id: int) → List[int]

get list of ppg channels in resulting data table for a board

Parameters

board_id (int) – Board Id

Returns

list of ppg channels in returned numpy array

Return type

List[int]

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_accel_channels(board_id: int) → List[int]

get list of accel channels in resulting data table for a board

Parameters

board_id (int) – Board Id

Returns

list of accel channels in returned numpy array

Return type

List[int]

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_analog_channels(board_id: int) → List[int]

get list of analog channels in resulting data table for a board

Parameters

board_id (int) – Board Id

Returns

list of analog channels in returned numpy array

Return type

List[int]

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_gyro_channels(board_id: int) → List[int]

get list of gyro channels in resulting data table for a board

Parameters

board_id (int) – Board Id

Returns

list of gyro channels in returned numpy array

Return type

List[int]

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_other_channels(board_id: int) → List[int]

get list of other channels in resulting data table for a board

Parameters

board_id (int) – Board Id

Returns

list of other channels in returned numpy array

Return type

List[int]

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_temperature_channels(board_id: int) → List[int]

get list of temperature channels in resulting data table for a board

Parameters

board_id (int) – Board Id

Returns

list of temperature channels in returned numpy array

Return type

List[int]

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

classmethod get_resistance_channels(board_id: int) → List[int]

get list of resistance channels in resulting data table for a board

Parameters

board_id (int) – Board Id

Returns

list of resistance channels in returned numpy array

Return type

List[int]

Raises

BrainFlowError – If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

prepare_session() → None

prepare streaming sesssion, init resources, you need to call it before any other BoardShim object methods

start_stream(num_samples: int = 450000, streamer_params: str = None) → None

Start streaming data, this methods stores data in ringbuffer

Parameters
  • num_samples (int) – size of ring buffer to keep data

  • parameter to stream data from brainflow, supported vals (streamer_params) – “file://%file_name%:w”, “file://%file_name%:a”, “streaming_board://%multicast_group_ip%:%port%”. Range for multicast addresses is from “224.0.0.0” to “239.255.255.255”

stop_stream() → None

Stop streaming data

release_session() → None

release all resources

get_current_board_data()

Get specified amount of data or less if there is not enough data, doesnt remove data from ringbuffer

Parameters

num_samples (int) – max number of samples

Returns

latest data from a board

Return type

NDArray[Float64]

get_board_data_count() → int

Get num of elements in ringbuffer

Returns

number of elements in ring buffer

Return type

int

get_board_id() → int

Get’s the actual board id, can be different than provided

Returns

board id

Return type

int

insert_marker(value: float) → None

Insert Marker to Data Stream

Parameters

value (float) – value to insert

Returns

board id

Return type

int

is_prepared() → bool

Check if session is ready or not

Returns

session status

Return type

bool

get_board_data()

Get all board data and remove them from ringbuffer

Returns

all data from a board

Return type

NDArray[Float64]

config_board(config) → None

Use this method carefully and only if you understand what you are doing, do NOT use it to start or stop streaming

Parameters

config (str) – string to send to a board

Returns

response string if any

Return type

str

brainflow.exit_codes

class brainflow.exit_codes.BrainflowExitCodes(value)

Bases: enum.IntEnum

Enum to store all possible exit codes

STATUS_OK = 0
PORT_ALREADY_OPEN_ERROR = 1
UNABLE_TO_OPEN_PORT_ERROR = 2
SER_PORT_ERROR = 3
BOARD_WRITE_ERROR = 4
INCOMMING_MSG_ERROR = 5
INITIAL_MSG_ERROR = 6
BOARD_NOT_READY_ERROR = 7
STREAM_ALREADY_RUN_ERROR = 8
INVALID_BUFFER_SIZE_ERROR = 9
STREAM_THREAD_ERROR = 10
STREAM_THREAD_IS_NOT_RUNNING = 11
EMPTY_BUFFER_ERROR = 12
INVALID_ARGUMENTS_ERROR = 13
UNSUPPORTED_BOARD_ERROR = 14
BOARD_NOT_CREATED_ERROR = 15
ANOTHER_BOARD_IS_CREATED_ERROR = 16
GENERAL_ERROR = 17
SYNC_TIMEOUT_ERROR = 18
JSON_NOT_FOUND_ERROR = 19
NO_SUCH_DATA_IN_JSON_ERROR = 20
CLASSIFIER_IS_NOT_PREPARED_ERROR = 21
ANOTHER_CLASSIFIER_IS_PREPARED_ERROR = 22
UNSUPPORTED_CLASSIFIER_AND_METRIC_COMBINATION_ERROR = 23

brainflow.data_filter

class brainflow.data_filter.FilterTypes(value)

Bases: enum.IntEnum

Enum to store all supported Filter Types

BUTTERWORTH = 0
CHEBYSHEV_TYPE_1 = 1
BESSEL = 2
class brainflow.data_filter.AggOperations(value)

Bases: enum.IntEnum

Enum to store all supported aggregation operations

MEAN = 0
MEDIAN = 1
EACH = 2
class brainflow.data_filter.WindowFunctions(value)

Bases: enum.IntEnum

Enum to store all supported window functions

NO_WINDOW = 0
HANNING = 1
HAMMING = 2
BLACKMAN_HARRIS = 3
class brainflow.data_filter.DetrendOperations(value)

Bases: enum.IntEnum

Enum to store all supported detrend options

NONE = 0
CONSTANT = 1
LINEAR = 2
class brainflow.data_filter.NoiseTypes(value)

Bases: enum.IntEnum

Enum to store noise types

class brainflow.data_filter.DataFilter

Bases: object

DataFilter class contains methods for signal processig

classmethod enable_data_logger() → None

enable Data Logger with level INFO, uses stderr for log messages by default

classmethod disable_data_logger() → None

disable Data Logger

classmethod enable_dev_data_logger() → None

enable Data Logger with level TRACE, uses stderr for log messages by default

classmethod set_log_file(log_file: str) → None

redirect logger from stderr to file, can be called any time

Parameters

log_file (str) – log file name

classmethod perform_lowpass()

apply low pass filter to provided data

Parameters
  • data (NDArray[Float64]) – data to filter, filter works in-place

  • sampling_rate (int) – board’s sampling rate

  • cutoff (float) – cutoff frequency

  • order (int) – filter order

  • filter_type (int) – filter type from special enum

  • ripple (float) – ripple value for Chebyshev filter

classmethod perform_highpass()

apply high pass filter to provided data

Parameters
  • data (NDArray[Float64]) – data to filter, filter works in-place

  • sampling_rate (int) – board’s sampling rate

  • cutoff (float) – cutoff frequency

  • order (int) – filter order

  • filter_type (int) – filter type from special enum

  • ripple (float) – ripple value for Chebyshev filter

classmethod perform_bandpass()

apply band pass filter to provided data

Parameters
  • data (NDArray[Float64]) – data to filter, filter works in-place

  • sampling_rate (int) – board’s sampling rate

  • center_freq (float) – center frequency

  • band_width (float) – band width

  • order (int) – filter order

  • filter_type (int) – filter type from special enum

  • ripple (float) – ripple value for Chebyshev filter

classmethod perform_bandstop()

apply band stop filter to provided data

Parameters
  • data (NDArray[Float64]) – data to filter, filter works in-place

  • sampling_rate (int) – board’s sampling rate

  • center_freq (float) – center frequency

  • band_width (float) – band width

  • order (int) – filter order

  • filter_type (int) – filter type from special enum

  • ripple (float) – ripple value for Chebyshev filter

classmethod remove_environmental_noise()

remove env noise using notch filter

Parameters
  • data (NDArray[Float64]) – data to filter, filter works in-place

  • sampling_rate (int) – board’s sampling rate

  • noise_type (int) – noise type

classmethod perform_rolling_filter()

smooth data using moving average or median

Parameters
  • data (NDArray[Float64]) – data to smooth, it works in-place

  • period (int) – window size

  • operation (int) – int value from AggOperation enum

classmethod perform_downsampling()

perform data downsampling, it doesnt apply lowpass filter for you, it just aggregates several data points

Parameters
  • data (NDArray[Float64]) – initial data

  • period (int) – downsampling period

  • operation (int) – int value from AggOperation enum

Returns

downsampled data

Return type

NDArray[Float64]

classmethod perform_wavelet_transform()

perform wavelet transform

Parameters
  • data (NDArray[Float64]) – initial data

  • wavelet (str) – supported vals: db1..db15,haar,sym2..sym10,coif1..coif5,bior1.1,bior1.3,bior1.5,bior2.2,bior2.4,bior2.6,bior2.8,bior3.1,bior3.3,bior3.5 ,bior3.7,bior3.9,bior4.4,bior5.5,bior6.8

  • decomposition_level (int) – level of decomposition

Returns

tuple of wavelet coeffs in format [A(J) D(J) D(J-1) ….. D(1)] where J is decomposition level, A - app coeffs, D - detailed coeffs, and array with lengths for each block

Return type

tuple

classmethod perform_inverse_wavelet_transform()

perform wavelet transform

Parameters
  • wavelet_output – tuple of wavelet_coeffs and array with lengths

  • original_data_len (int) – len of signal before wavelet transform

  • wavelet (str) – supported vals: db1..db15,haar,sym2..sym10,coif1..coif5,bior1.1,bior1.3,bior1.5,bior2.2,bior2.4,bior2.6,bior2.8,bior3.1,bior3.3,bior3.5 ,bior3.7,bior3.9,bior4.4,bior5.5,bior6.8

  • decomposition_level (int) – level of decomposition

Returns

restored data

Return type

NDArray[Float64]

classmethod perform_wavelet_denoising()

perform wavelet denoising

Parameters
  • data (NDArray[Float64]) – data to denoise

  • wavelet (str) – supported vals: db1..db15,haar,sym2..sym10,coif1..coif5,bior1.1,bior1.3,bior1.5,bior2.2,bior2.4,bior2.6,bior2.8,bior3.1,bior3.3,bior3.5 ,bior3.7,bior3.9,bior4.4,bior5.5,bior6.8

  • decomposition_level (int) – decomposition level

classmethod get_csp()

calculate filters and the corresponding eigenvalues using the Common Spatial Patterns

Parameters
  • data (NDArray[Float64]) – [epochs x channels x times]-shaped 3D array of data for two classes

  • labels (NDArray[Int64]) – n_epochs-length 1D array of zeros and ones that assigns class labels for each epoch. Zero corresponds to the first class

Returns

[channels x channels]-shaped 2D array of filters and [channels]-length 1D array of the corresponding eigenvalues

Return type

Tuple

classmethod get_window()

perform data windowing

Parameters
  • window_function – window function

  • window_len – len of the window function

Returns

numpy array, len of the array is the same as data

Return type

NDArray[Float64]

classmethod perform_fft()

perform direct fft

Parameters
  • data (NDArray[Float64]) – data for fft, len of data must be a power of 2

  • window (int) – window function

Returns

numpy array of complex values, len of this array is N / 2 + 1

Return type

NDArray[Complex128]

classmethod get_psd()

calculate PSD

Parameters
  • data (NDArray[Float64]) – data to calc psd, len of data must be a power of 2

  • sampling_rate (int) – sampling rate

  • window (int) – window function

Returns

amplitude and frequency arrays of len N / 2 + 1

Return type

tuple

classmethod get_psd_welch()

calculate PSD using Welch method

Parameters
  • data (NDArray[Float64]) – data to calc psd

  • nfft (int) – FFT Window size, must be power of 2

  • overlap (int) – overlap of FFT Windows, must be between 0 and nfft

  • sampling_rate (int) – sampling rate

  • window (int) – window function

Returns

amplitude and frequency arrays of len N / 2 + 1

Return type

tuple

classmethod detrend()

detrend data

Parameters
  • data (NDArray[Float64]) – data to calc psd

  • detrend_operation (int) – Type of detrend operation

classmethod get_band_power(psd: Tuple, freq_start: float, freq_end: float) → float

calculate band power

Parameters
  • psd (typle) – psd from get_psd

  • freq_start (int) – start freq

  • freq_end (int) – end freq

Returns

band power

Return type

float

classmethod get_avg_band_powers(data: nptyping.types._ndarray.NDArray, channels: List, sampling_rate: int, apply_filter: bool) → Tuple

calculate avg and stddev of BandPowers across all channels

Parameters
  • data (NDArray) – 2d array for calculation

  • channels (List) – channels - rows of data array which should be used for calculation

  • sampling_rate (int) – sampling rate

  • apply_filter (bool) – apply bandpass and bandstop filtrers or not

Returns

avg and stddev arrays for bandpowers

Return type

tuple

classmethod perform_ifft()

perform inverse fft

Parameters

data (NDArray[Complex128]) – data from fft

Returns

restored data

Return type

NDArray[Float64]

classmethod get_nearest_power_of_two(value: int) → int

calc nearest power of two

Parameters

value (int) – input value

Returns

nearest power of two

Return type

int

classmethod write_file(data, file_name: str, file_mode: str) → None

write data to file, in file data will be transposed

Parameters
  • data (2d numpy array) – data to store in a file

  • file_name (str) – file name to store data

  • file_mode (str) – ‘w’ to rewrite file or ‘a’ to append data to file

classmethod read_file(file_name: str)

read data from file

Parameters

file_name (str) – file name to read

Returns

2d numpy array with data from this file, data will be transposed to original dimensions

Return type

2d numpy array

brainflow.ml_model

class brainflow.ml_model.BrainFlowMetrics(value)

Bases: enum.IntEnum

Enum to store all supported metrics

RELAXATION = 0
CONCENTRATION = 1
class brainflow.ml_model.BrainFlowClassifiers(value)

Bases: enum.IntEnum

Enum to store all supported classifiers

REGRESSION = 0
KNN = 1
SVM = 2
LDA = 3
class brainflow.ml_model.BrainFlowModelParams(metric, classifier)

Bases: object

inputs parameters for prepare_session method

Parameters
  • metric (int) – metric to calculate

  • classifier (int) – classifier to use

  • file (str) – file to load model

  • other_info (int) – additional information

class brainflow.ml_model.MLModel(model_params: brainflow.ml_model.BrainFlowModelParams)

Bases: object

MLModel class used to calc derivative metrics from raw data

Parameters

model_params (BrainFlowModelParams) – Model Params

classmethod enable_ml_logger() → None

enable ML Logger with level INFO, uses stderr for log messages by default

classmethod disable_ml_logger() → None

disable BrainFlow Logger

classmethod enable_dev_ml_logger() → None

enable ML Logger with level TRACE, uses stderr for log messages by default

classmethod set_log_file(log_file: str) → None

redirect logger from stderr to file, can be called any time

Parameters

log_file (str) – log file name

prepare() → None

prepare classifier

release() → None

release classifier

predict(data: nptyping.types._ndarray.NDArray) → float

calculate metric from data

Parameters

data (NDArray) – input array

Returns

metric value

Return type

float

C++ API Reference

BoardShim class

class BoardShim

BoardShim class to communicate with a board.

Public Functions

BoardShim(int board_id, struct BrainFlowInputParams params)
~BoardShim()
void prepare_session()

prepare BrainFlow’s streaming session, should be called first

void start_stream(int buffer_size = 450000, std::string streamer_params = "")

start streaming thread and store data in ringbuffer

Parameters
  • buffer_size: size of internal ring buffer

  • streamer_params:

    use it to pass data packages further or store them directly during streaming, supported values: “file://%file_name%:w”, “file://%file_name%:a”, “streaming_board://%multicast_group_ip%:%port%””.

    Range for multicast addresses is from “224.0.0.0” to “239.255.255.255”

bool is_prepared()

check if session is ready or not

void stop_stream()

stop streaming thread, doesnt release other resources

void release_session()

release streaming session

BrainFlowArray<double, 2> get_current_board_data(int num_samples)

get latest collected data, doesnt remove it from ringbuffer

int get_board_id()

Get board id, for some boards can be different than provided (playback, streaming)

int get_board_data_count()

get number of packages in ringbuffer

BrainFlowArray<double, 2> get_board_data()

get all collected data and flush it from internal buffer

std::string config_board(char *config)

send string to a board, use it carefully and only if you understand what you are doing

void insert_marker(double value)

insert marker in data stream

Public Members

int board_id

Public Static Functions

void disable_board_logger()

disable BrainFlow loggers

void enable_board_logger()

enable BrainFlow logger with LEVEL_INFO

void enable_dev_board_logger()

enable BrainFlow logger with LEVEL_TRACE

void set_log_file(std::string log_file)

redirect BrainFlow logger from stderr to file

void set_log_level(int log_level)

use set_log_level only if you want to write your own log messages to BrainFlow logger

void log_message(int log_level, const char *format, ...)

write user defined string to BrainFlow logger

int get_sampling_rate(int board_id)

get sampling rate for this board

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

int get_package_num_channel(int board_id)

get row index which holds package nums

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

int get_timestamp_channel(int board_id)

get row index which holds timestamps

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

int get_marker_channel(int board_id)

get row index which holds markers

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

int get_battery_channel(int board_id)

get row index which holds battery level info

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

int get_num_rows(int board_id)

get number of rows in returned from get_board_data() 2d array

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

std::string get_device_name(int board_id)

get device name

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

std::vector<std::string> get_eeg_names(int board_id)

get eeg channel names in 10-20 system for devices with fixed electrode locations

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

std::vector<int> get_eeg_channels(int board_id)

get row indices which hold EEG data, for some board we can not split EEG…

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

std::vector<int> get_emg_channels(int board_id)

get row indices which hold EMG data, for some board we can not split EEG…

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

std::vector<int> get_ecg_channels(int board_id)

get row indices which hold ECG data, for some board we can not split EEG…

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

std::vector<int> get_eog_channels(int board_id)

get row indices which hold EOG data, for some board we can not split EEG…

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

std::vector<int> get_exg_channels(int board_id)

get row indices which hold EXG data

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

std::vector<int> get_ppg_channels(int board_id)

get row indices which hold PPG data

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

std::vector<int> get_eda_channels(int board_id)

get row indices which hold EDA data

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

std::vector<int> get_accel_channels(int board_id)

get row indices which hold accel data

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

std::vector<int> get_analog_channels(int board_id)

get row indices which hold analog data

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

std::vector<int> get_gyro_channels(int board_id)

get row indices which hold gyro data

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

std::vector<int> get_other_channels(int board_id)

get row indices which hold other information

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

std::vector<int> get_temperature_channels(int board_id)

get row indices which hold temperature data

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

std::vector<int> get_resistance_channels(int board_id)

get row indices which hold resistance data

Parameters
  • board_id: board id of your device

Exceptions
  • BrainFlowException: If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR

DataFilter class

class DataFilter

DataFilter class to perform signal processing.

Public Static Functions

void enable_data_logger()

enable Data logger with LEVEL_INFO

void disable_data_logger()

disable Data loggers

void enable_dev_data_logger()

enable Data logger with LEVEL_TRACE

void set_log_level(int log_level)

set log level

void set_log_file(std::string log_file)

set log file

void perform_lowpass(double *data, int data_len, int sampling_rate, double cutoff, int order, int filter_type, double ripple)

perform low pass filter in-place

void perform_highpass(double *data, int data_len, int sampling_rate, double cutoff, int order, int filter_type, double ripple)

perform high pass filter in-place

void perform_bandpass(double *data, int data_len, int sampling_rate, double center_freq, double band_width, int order, int filter_type, double ripple)

perform bandpass filter in-place

void perform_bandstop(double *data, int data_len, int sampling_rate, double center_freq, double band_width, int order, int filter_type, double ripple)

perform bandstop filter in-place

void remove_environmental_noise(double *data, int data_len, int sampling_rate, int noise_type)

apply notch filter to remove env noise

void perform_rolling_filter(double *data, int data_len, int period, int agg_operation)

perform moving average or moving median filter in-place

double *perform_downsampling(double *data, int data_len, int period, int agg_operation, int *filtered_size)

perform data downsampling, it just aggregates several data points

std::pair<double*, int*> perform_wavelet_transform(double *data, int data_len, std::string wavelet, int decomposition_level)

perform wavelet transform

Return

std::pair of wavelet coeffs array in format [A(J) D(J) D(J-1) ….. D(1)] where J is decomposition level A - app coeffs, D - detailed coeffs, and array of lengths for each block in wavelet coeffs array, length of this array is decomposition_level + 1

Parameters
  • data: input array, any size

  • data_len: length of input array

  • wavelet: supported vals: db1..db15,haar,sym2..sym10,coif1..coif5,bior1.1,bior1.3,bior1.5,bior2.2,bior2.4,bior2.6,bior2.8,bior3.1,bior3.3,bior3.5 ,bior3.7,bior3.9,bior4.4,bior5.5,bior6.8

  • decomposition_level: level of decomposition in wavelet transform

double *perform_inverse_wavelet_transform(std::pair<double*, int*> wavelet_output, int original_data_len, std::string wavelet, int decomposition_level)

performs inverse wavelet transform

void perform_wavelet_denoising(double *data, int data_len, std::string wavelet, int decomposition_level)

perform wavelet denoising

std::pair<BrainFlowArray<double, 2>, BrainFlowArray<double, 1>> get_csp(const BrainFlowArray<double, 3> &data, const BrainFlowArray<double, 1> &labels)

calculate filters and the corresponding eigenvalues using the Common Spatial Patterns

Return

pair of two arrays. The first [n_channel x n_channel]-shaped 2D array represents filters. The second n-channel length 1D array represents eigenvalues

Parameters
  • data: [n_epochs x n_channels x n_times]-shaped 3D array of data for two classes

  • labels: n_epochs-length 1D array of zeros and ones that assigns class labels for each epoch. Zero corresponds to the first class

  • n_epochs: the total number of epochs

  • n_channels: the number of EEG channels

  • n_times: the number of samples (observations) for a single epoch for a single channel

double *get_window(int window_function, int window_len)

perform data windowing

std::complex<double> *perform_fft(double *data, int data_len, int window)

perform direct fft

Return

complex array with size data_len / 2 + 1, it holds only positive im values

Parameters
  • data: input array

  • data_len: must be power of 2

  • window: window function

double *perform_ifft(std::complex<double> *data, int data_len)

perform inverse fft

Return

restored data

Parameters
  • data: complex array from perform_fft

  • data_len: len of original array, must be power of 2

int get_nearest_power_of_two(int value)

calculate nearest power of 2

Return

nearest power of 2

Parameters
  • value: input value

std::pair<double*, double*> get_psd(double *data, int data_len, int sampling_rate, int window)

calculate PSD

Return

pair of amplitude and freq arrays of size data_len / 2 + 1

Parameters
  • data: input array

  • data_len: must be power of 2

  • sampling_rate: sampling rate

  • window: window function

void detrend(double *data, int data_len, int detrend_operation)

subtract trend from data

Parameters
  • data: input array

  • data_len:

  • detrend_operation: use DetrendOperations enum

std::pair<double*, double*> get_psd_welch(double *data, int data_len, int nfft, int overlap, int sampling_rate, int window)
double get_band_power(std::pair<double*, double*> psd, int data_len, double freq_start, double freq_end)

calculate band power

Return

band power

Parameters
  • psd: psd calculated using get_psd

  • data_len: len of ampl and freq arrays: N / 2 + 1 where N is FFT size

  • freq_start: lowest frequency

  • freq_end: highest frequency

std::pair<double*, double*> get_avg_band_powers(const BrainFlowArray<double, 2> &data, std::vector<int> channels, int sampling_rate, bool apply_filters)

calculate avg and stddev of BandPowers across all channels

Return

pair of double arrays of size 5, first of them - avg band powers, second stddev

Parameters
  • data: input 2d array

  • cols: number of cols in 2d array - number of datapoints

  • channels: vector of rows - eeg channels which should be used

  • sampling_rate: sampling rate

  • apply_filters: set to true to apply filters before band power calculations

void write_file(const BrainFlowArray<double, 2> &data, std::string file_name, std::string file_mode)

write file, in file data will be transposed

BrainFlowArray<double, 2> read_file(std::string file_name)

read data from file, data will be transposed to original format

MLModel class

class MLModel

Calculates different metrics from raw data.

Public Functions

MLModel(struct BrainFlowModelParams params)
~MLModel()
void prepare()

initialize classifier, should be called first

double predict(double *data, int data_len)

calculate metric from data

void release()

release classifier

Public Static Functions

void set_log_file(std::string log_file)

redirect logger to a file

void enable_ml_logger()

enable ML logger with LEVEL_INFO

void disable_ml_logger()

disable ML loggers

void enable_dev_ml_logger()

enable ML logger with LEVEL_TRACE

void set_log_level(int log_level)

set log level

BrainFlow constants

#pragma once

enum class BrainFlowExitCodes : int
{
    STATUS_OK = 0,
    PORT_ALREADY_OPEN_ERROR = 1,
    UNABLE_TO_OPEN_PORT_ERROR = 2,
    SET_PORT_ERROR = 3,
    BOARD_WRITE_ERROR = 4,
    INCOMMING_MSG_ERROR = 5,
    INITIAL_MSG_ERROR = 6,
    BOARD_NOT_READY_ERROR = 7,
    STREAM_ALREADY_RUN_ERROR = 8,
    INVALID_BUFFER_SIZE_ERROR = 9,
    STREAM_THREAD_ERROR = 10,
    STREAM_THREAD_IS_NOT_RUNNING = 11,
    EMPTY_BUFFER_ERROR = 12,
    INVALID_ARGUMENTS_ERROR = 13,
    UNSUPPORTED_BOARD_ERROR = 14,
    BOARD_NOT_CREATED_ERROR = 15,
    ANOTHER_BOARD_IS_CREATED_ERROR = 16,
    GENERAL_ERROR = 17,
    SYNC_TIMEOUT_ERROR = 18,
    JSON_NOT_FOUND_ERROR = 19,
    NO_SUCH_DATA_IN_JSON_ERROR = 20,
    CLASSIFIER_IS_NOT_PREPARED_ERROR = 21,
    ANOTHER_CLASSIFIER_IS_PREPARED_ERROR = 22,
    UNSUPPORTED_CLASSIFIER_AND_METRIC_COMBINATION_ERROR = 23
};

enum class BoardIds : int
{
    PLAYBACK_FILE_BOARD = -3,
    STREAMING_BOARD = -2,
    SYNTHETIC_BOARD = -1,
    CYTON_BOARD = 0,
    GANGLION_BOARD = 1,
    CYTON_DAISY_BOARD = 2,
    GALEA_BOARD = 3,
    GANGLION_WIFI_BOARD = 4,
    CYTON_WIFI_BOARD = 5,
    CYTON_DAISY_WIFI_BOARD = 6,
    BRAINBIT_BOARD = 7,
    UNICORN_BOARD = 8,
    CALLIBRI_EEG_BOARD = 9,
    CALLIBRI_EMG_BOARD = 10,
    CALLIBRI_ECG_BOARD = 11,
    FASCIA_BOARD = 12,
    NOTION_1_BOARD = 13,
    NOTION_2_BOARD = 14,
    IRONBCI_BOARD = 15,
    GFORCE_PRO_BOARD = 16,
    FREEEEG32_BOARD = 17,
    BRAINBIT_BLED_BOARD = 18,
    GFORCE_DUAL_BOARD = 19,
    GALEA_SERIAL_BOARD = 20,
    // use it to iterate
    FIRST = PLAYBACK_FILE_BOARD,
    LAST = GALEA_SERIAL_BOARD
};

enum class FilterTypes : int
{
    BUTTERWORTH = 0,
    CHEBYSHEV_TYPE_1 = 1,
    BESSEL = 2
};

enum class AggOperations : int
{
    MEAN = 0,
    MEDIAN = 1,
    EACH = 2
};

enum class WindowFunctions : int
{
    NO_WINDOW = 0,
    HANNING = 1,
    HAMMING = 2,
    BLACKMAN_HARRIS = 3
};

enum class DetrendOperations : int
{
    NONE = 0,
    CONSTANT = 1,
    LINEAR = 2
};

enum class BrainFlowMetrics : int
{
    RELAXATION = 0,
    CONCENTRATION = 1
};

enum class BrainFlowClassifiers : int
{
    REGRESSION = 0,
    KNN = 1,
    SVM = 2,
    LDA = 3
};

/// LogLevels enum to store all possible log levels
enum class LogLevels : int
{
    LEVEL_TRACE = 0,    /// TRACE
    LEVEL_DEBUG = 1,    /// DEBUG
    LEVEL_INFO = 2,     /// INFO
    LEVEL_WARN = 3,     /// WARN
    LEVEL_ERROR = 4,    /// ERROR
    LEVEL_CRITICAL = 5, /// CRITICAL
    LEVEL_OFF = 6       // OFF
};

enum class NoiseTypes : int
{
    FIFTY = 0,
    SIXTY = 1
};

Java API Reference

Content of Brainflow Package:

enum AggOperations

enum to store all supported aggregation operations

Public Functions

int get_code()
brainflow::AggOperations (final int code)

Public Members

brainflow::MEAN =(0)
brainflow::MEDIAN =(1)
brainflow::EACH =(2)

Public Static Functions

String brainflow::string_from_code (final int code)
AggOperations brainflow::from_code (final int code)
brainflow::[static initializer]

Private Members

final int brainflow::agg_operation

Private Static Attributes

final Map< Integer, AggOperations > brainflow::ao_map = new HashMap<Integer, AggOperations> ()
enum BoardIds

enum to store all supported boards

Public Functions

int get_code()
brainflow::BoardIds (final int code)

Public Members

brainflow::PLAYBACK_FILE_BOARD =(-3)
brainflow::STREAMING_BOARD =(-2)
brainflow::SYNTHETIC_BOARD =(-1)
brainflow::CYTON_BOARD =(0)
brainflow::GANGLION_BOARD =(1)
brainflow::CYTON_DAISY_BOARD =(2)
brainflow::GALEA_BOARD =(3)
brainflow::GANGLION_WIFI_BOARD =(4)
brainflow::CYTON_WIFI_BOARD =(5)
brainflow::CYTON_DAISY_WIFI_BOARD =(6)
brainflow::BRAINBIT_BOARD =(7)
brainflow::UNICORN_BOARD =(8)
brainflow::CALLIBRI_EEG_BOARD =(9)
brainflow::CALLIBRI_EMG_BOARD =(10)
brainflow::CALLIBRI_ECG_BOARD =(11)
brainflow::FASCIA_BOARD =(12)
brainflow::NOTION_1_BOARD =(13)
brainflow::NOTION_2_BOARD =(14)
brainflow::IRONBCI_BOARD =(15)
brainflow::GFORCE_PRO_BOARD =(16)
brainflow::FREEEEG32_BOARD =(17)
brainflow::BRAINBIT_BLED_BOARD =(18)
brainflow::GFORCE_DUAL_BOARD =(19)
brainflow::GALEA_SERIAL_BOARD =(20)

Public Static Functions

String brainflow::string_from_code (final int code)
BoardIds brainflow::from_code (final int code)
brainflow::[static initializer]

Private Members

final int brainflow::board_id

Private Static Attributes

final Map< Integer, BoardIds > brainflow::bi_map = new HashMap<Integer, BoardIds> ()
class brainflow::brainflow::BoardShim

BoardShim class to communicate with a board

Public Functions

BoardShim(int board_id, BrainFlowInputParams params)

Create BoardShim object

void prepare_session()

prepare steaming session, allocate resources

int get_board_id()

Get Board Id, can be different than provided (playback or streaming board)

String config_board(String config)

send string to a board, use this method carefully and only if you understand what you are doing

void start_stream(int buffer_size, String streamer_params)

start streaming thread, store data in internal ringbuffer and stream them from brainflow at the same time

Parameters
  • buffer_size: size of internal ringbuffer

  • streamer_params: supported vals: “file://%file_name%:w”, “file://%file_name%:a”, “streaming_board://%multicast_group_ip%:%port%”. Range for multicast addresses is from “224.0.0.0” to “239.255.255.255”

void start_stream()

start streaming thread, store data in internal ringbuffer

void start_stream(int buffer_size)

start streaming thread, store data in internal ringbuffer

void stop_stream()

stop streaming thread

void release_session()

release all resources

int get_board_data_count()

get number of packages in ringbuffer

void insert_marker(double value)

insert marker to data stream

boolean is_prepared()

check session status

double [][] get_current_board_data (int num_samples)

get latest collected data, can return less than “num_samples”, doesnt flush it from ringbuffer

double [][] get_board_data ()

get all data from ringbuffer and flush it

Public Members

int board_id

BrainFlow’s board id

Public Static Functions

void enable_board_logger()

enable BrainFlow logger with level INFO

void enable_dev_board_logger()

enable BrainFlow logger with level TRACE

void disable_board_logger()

disable BrainFlow logger

void set_log_file(String log_file)

redirect logger from stderr to a file

void set_log_level(int log_level)

set log level

void log_message(int log_level, String message)

send user defined strings to BrainFlow logger

int get_sampling_rate(int board_id)

get sampling rate for this board

int get_timestamp_channel(int board_id)

get row index in returned by get_board_data() 2d array which contains timestamps

int get_marker_channel(int board_id)

get row index in returned by get_board_data() 2d array which contains markers

int get_num_rows(int board_id)

get number of rows in returned by get_board_data() 2d array

int get_package_num_channel(int board_id)

get row index in returned by get_board_data() 2d array which contains package nums

int get_battery_channel(int board_id)

get row index in returned by get_board_data() 2d array which contains battery level

String [] get_eeg_names (int board_id)

Get names of EEG electrodes in 10-20 system. Only if electrodes have freezed locations

String get_device_name(int board_id)

Get device name

int [] get_eeg_channels (int board_id)

get row indices in returned by get_board_data() 2d array which contain EEG data, for some boards we can not split EEG… and return the same array

int [] get_emg_channels (int board_id)

get row indices in returned by get_board_data() 2d array which contain EMG data, for some boards we can not split EEG… and return the same array

int [] get_ecg_channels (int board_id)

get row indices in returned by get_board_data() 2d array which contain ECG data, for some boards we can not split EEG… and return the same array

int [] get_temperature_channels (int board_id)

get row indices in returned by get_board_data() 2d array which contain temperature data

int [] get_resistance_channels (int board_id)

get row indices in returned by get_board_data() 2d array which contain resistance data

int [] get_eog_channels (int board_id)

get row indices in returned by get_board_data() 2d array which contain EOG data, for some boards we can not split EEG… and return the same array

int [] get_exg_channels (int board_id)

get row indices in returned by get_board_data() 2d array which contain EXG data

int [] get_eda_channels (int board_id)

get row indices in returned by get_board_data() 2d array which contain EDA data, for some boards we can not split EEG… and return the same array

int [] get_ppg_channels (int board_id)

get row indices in returned by get_board_data() 2d array which contain PPG data, for some boards we can not split EEG… and return the same array

int [] get_accel_channels (int board_id)

get row indices in returned by get_board_data() 2d array which contain accel data

int [] get_analog_channels (int board_id)

get row indices in returned by get_board_data() 2d array which contain analog data

int [] get_gyro_channels (int board_id)

get row indices in returned by get_board_data() 2d array which contain gyro data

int [] get_other_channels (int board_id)

get row indices in returned by get_board_data() 2d array which contain other data

enum BrainFlowClassifiers

Public Functions

int get_code()
brainflow::BrainFlowClassifiers (final int code)

Public Members

brainflow::REGRESSION =(0)
brainflow::KNN =(1)
brainflow::SVM =(2)
brainflow::LDA =(3)

Public Static Functions

String brainflow::string_from_code (final int code)
BrainFlowClassifiers brainflow::from_code (final int code)
brainflow::[static initializer]

Private Members

final int brainflow::protocol

Private Static Attributes

final Map< Integer, BrainFlowClassifiers > brainflow::cl_map = new HashMap<Integer, BrainFlowClassifiers> ()
class brainflow::brainflow::BrainFlowError : public Exception

BrainFlowError exception to notify about errors

Public Functions

BrainFlowError(String message, int ec)

Public Members

String msg
int exit_code

exit code returned from low level API

class brainflow::brainflow::BrainFlowInputParams

to get fields which are required for your board check SupportedBoards section

Public Functions

BrainFlowInputParams()
String to_json()
String get_ip_address()
void set_ip_address(String ip_address)
String get_mac_address()
void set_mac_address(String mac_address)
String get_serial_port()
void set_serial_port(String serial_port)
int get_ip_port()
void set_ip_port(int ip_port)
int get_ip_protocol()
void set_ip_protocol(int ip_protocol)
String get_other_info()
void set_other_info(String other_info)
void set_timeout(int timeout)
int get_timeout()
String get_serial_number()
void set_serial_number(String serial_number)
String get_file()
void set_file(String file)

Public Members

String ip_address
String mac_address
String serial_port
int ip_port
int ip_protocol
String other_info
int timeout
String serial_number
String file
enum BrainFlowMetrics

Public Functions

int get_code()
brainflow::BrainFlowMetrics (final int code)

Public Members

brainflow::RELAXATION =(0)
brainflow::CONCENTRATION =(1)

Public Static Functions

String brainflow::string_from_code (final int code)
BrainFlowMetrics brainflow::from_code (final int code)
brainflow::[static initializer]

Private Members

final int brainflow::protocol

Private Static Attributes

final Map< Integer, BrainFlowMetrics > brainflow::metr_map = new HashMap<Integer, BrainFlowMetrics> ()
class brainflow::brainflow::BrainFlowModelParams

describe model parameters

Public Functions

BrainFlowModelParams(int metric, int classifier)
int get_metric()
void set_metric(int metric)
int get_classifier()
void set_classifier(int classifier)
String get_file()
void set_file(String file)
String get_other_info()
void set_other_info(String other_info)
String to_json()

Public Members

int metric
int classifier
String file
String other_info
class brainflow::brainflow::DataFilter

DataFilter class to perform signal processing

Public Static Functions

void enable_data_logger()

enable Data logger with level INFO

void enable_dev_data_logger()

enable Data logger with level TRACE

void disable_data_logger()

disable Data logger

void set_log_file(String log_file)

redirect logger from stderr to a file

void perform_lowpass (double[] data, int sampling_rate, double cutoff, int order, int filter_type, double ripple)

perform lowpass filter in-place

void perform_highpass (double[] data, int sampling_rate, double cutoff, int order, int filter_type, double ripple)

perform highpass filter in-place

void perform_bandpass (double[] data, int sampling_rate, double center_freq, double band_width, int order, int filter_type, double ripple)

perform bandpass filter in-place

void perform_bandstop (double[] data, int sampling_rate, double center_freq, double band_width, int order, int filter_type, double ripple)

perform bandstop filter in-place

void perform_rolling_filter (double[] data, int period, int operation)

perform moving average or moving median filter in-place

void detrend (double[] data, int operation)

subtract trend from data in-place

double [] perform_downsampling (double[] data, int period, int operation)

perform data downsampling, it doesnt apply lowpass filter for you, it just aggregates several data points

void remove_environmental_noise (double[] data, int sampling_rate, int noise_type)

removes noise using notch filter

void perform_wavelet_denoising (double[] data, String wavelet, int decomposition_level)

perform wavelet based denoising in-place

Parameters
  • wavelet: supported vals: db1..db15,haar,sym2..sym10,coif1..coif5,bior1.1,bior1.3,bior1.5,bior2.2,bior2.4,bior2.6,bior2.8,bior3.1,bior3.3,bior3.5 ,bior3.7,bior3.9,bior4.4,bior5.5,bior6.8

  • decomposition_level: level of decomposition of wavelet transform

Pair< double[], int[]> perform_wavelet_transform (double[] data, String wavelet, int decomposition_level)

perform wavelet transform

Parameters
  • wavelet: supported vals: db1..db15,haar,sym2..sym10,coif1..coif5,bior1.1,bior1.3,bior1.5,bior2.2,bior2.4,bior2.6,bior2.8,bior3.1,bior3.3,bior3.5 ,bior3.7,bior3.9,bior4.4,bior5.5,bior6.8

double [] perform_inverse_wavelet_transform (Pair< double[], int[]> wavelet_output, int original_data_len, String wavelet, int decomposition_level)

perform inverse wavelet transform

Pair< double[][], double[]> get_csp (double[][][] data, double[] labels)

get common spatial filters

double [] get_window (int window, int window_len)

perform data windowing

Return

array of the size specified in window_len

Parameters
  • window: window function

  • window_len: lenght of the window function

Complex [] perform_fft (double[] data, int start_pos, int end_pos, int window)

perform direct fft

Return

array of complex values with size N / 2 + 1

Parameters
  • data: data for fft transform

  • start_pos: starting position to calc fft

  • end_pos: end position to calc fft, total_len must be a power of two

  • window: window function

double [] perform_ifft (Complex[] data)

perform inverse fft

Return

restored data

Parameters
  • data: data from fft transform(array of complex values)

Pair< double[], double[]> get_avg_band_powers (double[][] data, int[] channels, int sampling_rate, boolean apply_filters)

calc average and stddev of band powers across all channels

Return

pair of avgs and stddevs for bandpowers

Parameters
  • data: data to process

  • channels: rows of data arrays which should be used in calculation

  • sampling_rate: sampling rate

  • apply_filters: apply bandpass and bandstop filters before calculation

Pair< double[], double[]> get_psd (double[] data, int start_pos, int end_pos, int sampling_rate, int window)

get PSD

Return

pair of ampl and freq arrays with len N / 2 + 1

Parameters
  • data: data to process

  • start_pos: starting position to calc PSD

  • end_pos: end position to calc PSD, total_len must be a power of two

  • sampling_rate: sampling rate

  • window: window function

Pair< double[], double[]> get_psd_welch (double[] data, int nfft, int overlap, int sampling_rate, int window)

get PSD using Welch Method

Return

pair of ampl and freq arrays

Parameters
  • data: data to process

  • nfft: size of FFT, must be power of two

  • overlap: overlap between FFT Windows, must be between 0 and nfft

  • sampling_rate: sampling rate

  • window: window function

double get_band_power(Pair<double[], double[]> psd, double freq_start, double freq_end)

get band power

Return

band power

Parameters
  • psd: PSD from get_psd or get_log_psd

  • freq_start: lowest frequency of band

  • freq_end: highest frequency of band

int get_nearest_power_of_two(int value)

calculate nearest power of two

void write_file (double[][] data, String file_name, String file_mode)

write data to csv file, in file data will be transposed

double [][] read_file (String file_name)

read data from file, transpose it back to original format

enum DetrendOperations

enum to store all supported detrend operations

Public Functions

int get_code()
brainflow::DetrendOperations (final int code)

Public Members

brainflow::NONE =(0)
brainflow::CONSTANT =(1)
brainflow::LINEAR =(2)

Public Static Functions

String brainflow::string_from_code (final int code)
DetrendOperations brainflow::from_code (final int code)
brainflow::[static initializer]

Private Members

final int brainflow::detrend_operation

Private Static Attributes

final Map< Integer, DetrendOperations > brainflow::dt_map = new HashMap<Integer, DetrendOperations> ()
enum ExitCode

Public Functions

int get_code()
brainflow::ExitCode (final int code)

Public Members

brainflow::STATUS_OK =(0)
brainflow::PORT_ALREADY_OPEN_ERROR =(1)
brainflow::UNABLE_TO_OPEN_PORT_ERROR =(2)
brainflow::SET_PORT_ERROR =(3)
brainflow::BOARD_WRITE_ERROR =(4)
brainflow::INCOMMING_MSG_ERROR =(5)
brainflow::INITIAL_MSG_ERROR =(6)
brainflow::BOARD_NOT_READY_ERROR =(7)
brainflow::STREAM_ALREADY_RUN_ERROR =(8)
brainflow::INVALID_BUFFER_SIZE_ERROR =(9)
brainflow::STREAM_THREAD_ERROR =(10)
brainflow::STREAM_THREAD_IS_NOT_RUNNING =(11)
brainflow::EMPTY_BUFFER_ERROR =(12)
brainflow::INVALID_ARGUMENTS_ERROR =(13)
brainflow::UNSUPPORTED_BOARD_ERROR =(14)
brainflow::BOARD_NOT_CREATED_ERROR =(15)
brainflow::ANOTHER_BOARD_IS_CREATED_ERROR =(16)
brainflow::GENERAL_ERROR =(17)
brainflow::SYNC_TIMEOUT_ERROR =(18)
brainflow::JSON_NOT_FOUND_ERROR =(19)
brainflow::NO_SUCH_DATA_IN_JSON_ERROR =(20)
brainflow::CLASSIFIER_IS_NOT_PREPARED_ERROR =(21)
brainflow::ANOTHER_CLASSIFIER_IS_PREPARED_ERROR =(22)
brainflow::UNSUPPORTED_CLASSIFIER_AND_METRIC_COMBINATION_ERROR =(23)

Public Static Functions

String brainflow::string_from_code (final int code)
ExitCode brainflow::from_code (final int code)
brainflow::[static initializer]

Private Members

final int brainflow::exit_code

Private Static Attributes

final Map< Integer, ExitCode > brainflow::ec_map = new HashMap<Integer, ExitCode> ()
enum FilterTypes

enum to store all possible filter types

Public Functions

int get_code()
brainflow::FilterTypes (final int code)

Public Members

brainflow::BUTTERWORTH =(0)
brainflow::CHEBYSHEV_TYPE_1 =(1)
brainflow::BESSEL =(2)

Public Static Functions

String brainflow::string_from_code (final int code)
FilterTypes brainflow::from_code (final int code)
brainflow::[static initializer]

Private Members

final int brainflow::filter_type

Private Static Attributes

final Map< Integer, FilterTypes > brainflow::ft_map = new HashMap<Integer, FilterTypes> ()
enum IpProtocolType

Public Functions

int get_code()
brainflow::IpProtocolType (final int code)

Public Members

brainflow::NONE =(0)
brainflow::UDP =(1)
brainflow::TCP =(2)

Public Static Functions

String brainflow::string_from_code (final int code)
IpProtocolType brainflow::from_code (final int code)
brainflow::[static initializer]

Private Members

final int brainflow::protocol

Private Static Attributes

final Map< Integer, IpProtocolType > brainflow::ip_map = new HashMap<Integer, IpProtocolType> ()
enum LogLevels

Public Functions

int get_code()
brainflow::LogLevels (final int code)

Public Members

brainflow::LEVEL_TRACE =(0)
brainflow::LEVEL_DEBUG =(1)
brainflow::LEVEL_INFO =(2)
brainflow::LEVEL_WARN =(3)
brainflow::LEVEL_ERROR =(4)
brainflow::LEVEL_CRITICAL =(5)
brainflow::LEVEL_OFF =(6)

Public Static Functions

String brainflow::string_from_code (final int code)
LogLevels brainflow::from_code (final int code)
brainflow::[static initializer]

Private Members

final int brainflow::log_level

Private Static Attributes

final Map< Integer, LogLevels > brainflow::ll_map = new HashMap<Integer, LogLevels> ()
class brainflow::brainflow::MLModel

Public Functions

MLModel(BrainFlowModelParams params)

Create MLModel object

void prepare()

Prepare classifier

Exceptions

void release()

Release classifier

Exceptions

double predict (double[] data)

Get score of classifier

Exceptions

Public Static Functions

void enable_ml_logger()

enable ML logger with level INFO

void enable_dev_ml_logger()

enable ML logger with level TRACE

void disable_ml_logger()

disable BrainFlow logger

void set_log_file(String log_file)

redirect logger from stderr to a file

enum NoiseTypes

enum to store all supported noise types

Public Functions

int get_code()
brainflow::NoiseTypes (final int code)

Public Members

brainflow::FIFTY =(0)
brainflow::SIXTY =(1)
brainflow::EACH =(2)

Public Static Functions

String brainflow::string_from_code (final int code)
NoiseTypes brainflow::from_code (final int code)
brainflow::[static initializer]

Private Members

final int brainflow::noise_type

Private Static Attributes

final Map< Integer, NoiseTypes > brainflow::nt_map = new HashMap<Integer, NoiseTypes> ()
enum WindowFunctions

Public Functions

int get_code()
brainflow::WindowFunctions (final int code)

Public Members

brainflow::NO_WINDOW =(0)
brainflow::HANNING =(1)
brainflow::HAMMING =(2)
brainflow::BLACKMAN_HARRIS =(3)

Public Static Functions

String brainflow::string_from_code (final int code)
WindowFunctions brainflow::from_code (final int code)
brainflow::[static initializer]

Private Members

final int brainflow::window

Private Static Attributes

final Map< Integer, WindowFunctions > brainflow::window_map = new HashMap<Integer, WindowFunctions> ()

C# API Reference

Content of brainflow namespace:

enum brainflow::LogLevels

Values:

enumerator LEVEL_TRACE = 0
enumerator LEVEL_DEBUG = 1
enumerator LEVEL_INFO = 2
enumerator LEVEL_WARN = 3
enumerator LEVEL_ERROR = 4
enumerator LEVEL_CRITICAL = 5
enumerator LEVEL_OFF = 6
enum brainflow::CustomExitCodes

Values:

enumerator STATUS_OK = 0
enumerator PORT_ALREADY_OPEN_ERROR = 1
enumerator UNABLE_TO_OPEN_PORT_ERROR = 2
enumerator SET_PORT_ERROR = 3
enumerator BOARD_WRITE_ERROR = 4
enumerator INCOMMING_MSG_ERROR = 5
enumerator INITIAL_MSG_ERROR = 6
enumerator BOARD_NOT_READY_ERROR = 7
enumerator STREAM_ALREADY_RUN_ERROR = 8
enumerator INVALID_BUFFER_SIZE_ERROR = 9
enumerator STREAM_THREAD_ERROR = 10
enumerator STREAM_THREAD_IS_NOT_RUNNING = 11
enumerator EMPTY_BUFFER_ERROR = 12
enumerator INVALID_ARGUMENTS_ERROR = 13
enumerator UNSUPPORTED_BOARD_ERROR = 14
enumerator BOARD_NOT_CREATED_ERROR = 15
enumerator ANOTHER_BOARD_IS_CREATED_ERROR = 16
enumerator GENERAL_ERROR = 17
enumerator SYNC_TIMEOUT_ERROR = 18
enumerator JSON_NOT_FOUND_ERROR = 19
enumerator NO_SUCH_DATA_IN_JSON_ERROR = 20
enumerator CLASSIFIER_IS_NOT_PREPARED_ERROR = 21
enumerator ANOTHER_CLASSIFIER_IS_PREPARED_ERROR = 22
enumerator UNSUPPORTED_CLASSIFIER_AND_METRIC_COMBINATION_ERROR = 23
enum brainflow::BoardIds

Values:

enumerator PLAYBACK_FILE_BOARD = -3
enumerator STREAMING_BOARD = -2
enumerator SYNTHETIC_BOARD = -1
enumerator CYTON_BOARD = 0
enumerator GANGLION_BOARD = 1
enumerator CYTON_DAISY_BOARD = 2
enumerator GALEA_BOARD = 3
enumerator GANGLION_WIFI_BOARD = 4
enumerator CYTON_WIFI_BOARD = 5
enumerator CYTON_DAISY_WIFI_BOARD = 6
enumerator BRAINBIT_BOARD = 7
enumerator UNICORN_BOARD = 8
enumerator CALLIBRI_EEG_BOARD = 9
enumerator CALLIBRI_EMG_BOARD = 10
enumerator CALLIBRI_ECG_BOARD = 11
enumerator FASCIA_BOARD = 12
enumerator NOTION_1_BOARD = 13
enumerator NOTION_2_BOARD = 14
enumerator IRONBCI_BOARD = 15
enumerator GFORCE_PRO_BOARD = 16
enumerator FREEEEG32_BOARD = 17
enumerator BRAINBIT_BLED_BOARD = 18
enumerator GFORCE_DUAL_BOARD = 19
enumerator GALEA_SERIAL_BOARD = 20
enum brainflow::IpProtocolType

Values:

enumerator NONE = 0
enumerator UDP = 1
enumerator TCP = 2
enum brainflow::FilterTypes

Values:

enumerator BUTTERWORTH = 0
enumerator CHEBYSHEV_TYPE_1 = 1
enumerator BESSEL = 2
enum brainflow::AggOperations

Values:

enumerator MEAN = 0
enumerator MEDIAN = 1
enumerator EACH = 2
enum brainflow::WindowFunctions

Values:

enumerator NO_WINDOW = 0
enumerator HANNING = 1
enumerator HAMMING = 2
enumerator BLACKMAN_HARRIS = 3
enum brainflow::DetrendOperations

Values:

enumerator NONE = 0
enumerator CONSTANT = 1
enumerator LINEAR = 2
enum brainflow::NoiseTypes

Values:

enumerator FIFTY = 0
enumerator SIXTY = 1
enum brainflow::BrainFlowMetrics

Values:

enumerator RELAXATION = 0
enumerator CONCENTRATION = 1
enum brainflow::BrainFlowClassifiers

Values:

enumerator REGRESSION = 0
enumerator KNN = 1
enumerator SVM = 2
enumerator LDA = 3
class brainflow::brainflow::BoardShim

BoardShim class to communicate with a board

Public Functions

BoardShim(int board_id, BrainFlowInputParams input_params)

Create an instance of BoardShim class

Parameters
  • board_id
  • input_params

void prepare_session()

prepare BrainFlow’s streaming session, allocate required resources

string config_board(string config)

send string to a board, use this method carefully and only if you understand what you are doing

Parameters
  • config

void insert_marker(double value)

insert marker to data array

void start_stream(int buffer_size = 3600 * 250, string streamer_params = "")

start streaming thread, store data in internal ringbuffer

Parameters

void stop_stream()

stop streaming thread, doesnt release other resources

void release_session()

release BrainFlow’s session

bool is_prepared()

check session status

summary> Get Board Id, for some boards can be different than provided /summary>

Return

session status

Return

Master board id

int get_board_id()
int get_board_data_count()

get number of packages in ringbuffer

Return

number of packages

double [,] get_current_board_data (int num_samples)

get latest collected data, doesnt remove it from ringbuffer

Return

latest collected data, can be less than “num_samples”

Parameters
  • num_samples

double [,] get_board_data ()

get all collected data and remove it from ringbuffer

Return

all collected data

Public Members

int board_id

BrainFlow’s board id

Public Static Functions

int get_sampling_rate(int board_id)

get sampling rate for this board id

Return

sampling rate

Parameters
  • board_id
Exceptions

int get_package_num_channel(int board_id)

get row index in returned by get_board_data() 2d array which holds package nums

Return

row num in 2d array

Parameters
  • board_id
Exceptions

int get_timestamp_channel(int board_id)

get row index which holds timestamps

Return

row num in 2d array

Parameters
  • board_id
Exceptions

int get_marker_channel(int board_id)

get row index which holds marker

Return

row num in 2d array

Parameters
  • board_id
Exceptions

int get_battery_channel(int board_id)

get row undex which holds battery level

Return

row num in 2d array

Parameters
  • board_id
Exceptions

int get_num_rows(int board_id)

get number of rows in returned by get_board_data() 2d array

Return

number of rows in 2d array

Parameters
  • board_id
Exceptions

string [] get_eeg_names (int board_id)

get names of EEG channels in 10-20 system. Only if electrodes have fixed locations

Return

array of 10-20 locations

Parameters
  • board_id
Exceptions

string get_device_name(int board_id)

get device name

Return

device name

Parameters
  • board_id
Exceptions

int [] get_eeg_channels (int board_id)

get row indices of EEG channels for this board, for some board we can not split EMG.. data and return the same array for all of them

Return

array of row nums

Parameters
  • board_id
Exceptions

int [] get_emg_channels (int board_id)

get row indices of EMG channels for this board, for some board we can not split EMG.. data and return the same array for all of them

Return

array of row nums

Parameters
  • board_id
Exceptions

int [] get_ecg_channels (int board_id)

get row indices of ECG channels for this board, for some board we can not split EMG.. data and return the same array for all of them

Return

array of row nums

Parameters
  • board_id
Exceptions

int [] get_eog_channels (int board_id)

get row indices of EOG channels for this board, for some board we can not split EMG.. data and return the same array for all of them

Return

array of row nums

Parameters
  • board_id
Exceptions

int [] get_exg_channels (int board_id)

get row indices of EXG channels for this board

Return

array of row nums

Parameters
  • board_id
Exceptions

int [] get_eda_channels (int board_id)

get row indices of EDA channels for this board, for some board we can not split EMG.. data and return the same array for all of them

Return

array of row nums

Parameters
  • board_id
Exceptions

int [] get_ppg_channels (int board_id)

get row indeces which hold ppg data

Return

array of row nums

Parameters
  • board_id
Exceptions

int [] get_accel_channels (int board_id)

get row indices which hold accel data

Return

array of row nums

Parameters
  • board_id
Exceptions

int [] get_analog_channels (int board_id)

get row indices which hold analog data

Return

array of row nums

Parameters
  • board_id
Exceptions

int [] get_gyro_channels (int board_id)

get row indices which hold gyro data

Return

array of row nums

Parameters
  • board_id
Exceptions

int [] get_other_channels (int board_id)

get other channels for this board

Return

array of row nums

Parameters
  • board_id
Exceptions

int [] get_temperature_channels (int board_id)

get temperature channels for this board

Return

array of row nums

Parameters
  • board_id
Exceptions

int [] get_resistance_channels (int board_id)

get resistance channels for this board

Return

array of row nums

Parameters
  • board_id
Exceptions

void set_log_level(int log_level)

set log level, logger is disabled by default

Parameters
  • log_level

void enable_board_logger()

enable BrainFlow’s logger with level INFO

void disable_board_logger()

disable BrainFlow’s logger

void enable_dev_board_logger()

enable BrainFLow’s logger with level TRACE

void set_log_file(string log_file)

redirect BrainFlow’s logger from stderr to file

Parameters
  • log_file

void log_message(int log_level, string message)

send your own log message to BrainFlow’s logger

Parameters
  • log_level
  • message

class brainflow::brainflow::BrainFlowException : public Exception

BrainFlowException class to notify about errors

Public Functions

BrainFlowException(int code)

Public Members

int exit_code

exit code returned from low level API

class brainflow::brainflow::BrainFlowInputParams

Check SuportedBoards to get information about fields which are required for specific board

Public Functions

BrainFlowInputParams()
string to_json()

Public Members

string serial_port

serial port name

string mac_address

MAC address

string ip_address

IP address

int ip_port

PORT

int ip_protocol

IP protocol, use IpProtocolType

string other_info

you can provide additional info to low level API using this field

int timeout

timeout for device discovery or connection

string serial_number

serial number

string file

file

class brainflow::brainflow::BrainFlowModelParams

Describe model

Public Functions

BrainFlowModelParams(int metric, int classifier)
string to_json()

Public Members

int metric

metric to caclulate

int classifier

classifier to use

string file

path to model file

string other_info

other info

class brainflow::brainflow::DataFilter

DataFilter class to perform signal processing

Public Static Functions

void enable_data_logger()

enable Data logger with level INFO

void disable_data_logger()

disable Data logger

void enable_dev_data_logger()

enable Data logger with level TRACE

void set_log_file(string log_file)

redirect BrainFlow’s logger from stderr to file

Parameters
  • log_file

double [] perform_lowpass (double[] data, int sampling_rate, double cutoff, int order, int filter_type, double ripple)

perform lowpass filter, unlike other bindings instead in-place calculation it returns new array

Return

filtered data

Parameters
  • data
  • sampling_rate
  • cutoff
  • order
  • filter_type
  • ripple

double [] remove_environmental_noise (double[] data, int sampling_rate, int noise_type)

remove env noise using notch filter

Return

filtered data

Parameters
  • data
  • sampling_rate
  • noise_type

double [] perform_highpass (double[] data, int sampling_rate, double cutoff, int order, int filter_type, double ripple)

perform highpass filter, unlike other bindings instead in-place calculation it returns new array

Return

filtered data

Parameters
  • data
  • sampling_rate
  • cutoff
  • order
  • filter_type
  • ripple

double [] perform_bandpass (double[] data, int sampling_rate, double center_freq, double band_width, int order, int filter_type, double ripple)

perform bandpass filter, unlike other bindings instead in-place calculation it returns new array

Return

filtered data

Parameters
  • data
  • sampling_rate
  • center_freq
  • band_width
  • order
  • filter_type
  • ripple

double [] perform_bandstop (double[] data, int sampling_rate, double center_freq, double band_width, int order, int filter_type, double ripple)

perform bandstop filter, unlike other bindings instead in-place calculation it returns new array

Return

filtered data

Parameters
  • data
  • sampling_rate
  • center_freq
  • band_width
  • order
  • filter_type
  • ripple

double [] perform_rolling_filter (double[] data, int period, int operation)

perform moving average or moving median filter, unlike other bindings instead in-place calculation it returns new array

Return

filered data

Parameters
  • data
  • period
  • operation

double [] detrend (double[] data, int operation)

detrend, unlike other bindings instead in-place calculation it returns new array

Return

data with removed trend

Parameters
  • data
  • operation

double [] perform_downsampling (double[] data, int period, int operation)

perform data downsampling, it just aggregates data without applying lowpass filter

Return

data after downsampling

Parameters
  • data
  • period
  • operation

Tuple< double[], int[]> perform_wavelet_transform (double[] data, string wavelet, int decomposition_level)

perform wavelet transform

Return

tuple of wavelet coeffs in format [A(J) D(J) D(J-1) ….. D(1)] where J is decomposition level, A - app coeffs, D - detailed coeffs, and array with lengths for each block

Parameters
  • data: data for wavelet transform

  • wavelet: db1..db15,haar,sym2..sym10,coif1..coif5,bior1.1,bior1.3,bior1.5,bior2.2,bior2.4,bior2.6,bior2.8,bior3.1,bior3.3,bior3.5 ,bior3.7,bior3.9,bior4.4,bior5.5,bior6.8

  • decomposition_level: decomposition level

double [] perform_inverse_wavelet_transform (Tuple< double[], int[]> wavelet_data, int original_data_len, string wavelet, int decomposition_level)

perform inverse wavelet transorm

Return

restored data

Parameters
  • wavelet_data: tuple returned by perform_wavelet_transform

  • original_data_len: size of original data before direct wavelet transform

  • wavelet: db1..db15,haar,sym2..sym10,coif1..coif5,bior1.1,bior1.3,bior1.5,bior2.2,bior2.4,bior2.6,bior2.8,bior3.1,bior3.3,bior3.5 ,bior3.7,bior3.9,bior4.4,bior5.5,bior6.8

  • decomposition_level: level of decomposition

double [] perform_wavelet_denoising (double[] data, string wavelet, int decomposition_level)

perform wavelet based denoising

Return

denoised data

Parameters
  • data: data for denoising

  • wavelet: db1..db15,haar,sym2..sym10,coif1..coif5,bior1.1,bior1.3,bior1.5,bior2.2,bior2.4,bior2.6,bior2.8,bior3.1,bior3.3,bior3.5 ,bior3.7,bior3.9,bior4.4,bior5.5,bior6.8

  • decomposition_level: level of decomposition in wavelet transform

Tuple< double[,], double[]> get_csp (double[,,] data, double[] labels)

get common spatial patterns

Return

Tuple of two arrays: [n_channels x n_channels] shaped array of filters and n_channels length array of eigenvalues

Parameters
  • data: data for csp

  • labels: labels for each class

double [] get_window (int window_function, int window_len)

perform windowing

Return

array of the size specified in window_len

Parameters
  • window_function: window function

  • window_len: len of the window

Complex [] perform_fft (double[] data, int start_pos, int end_pos, int window)

perform direct fft

Return

complex array of size N / 2 + 1 of fft data

Parameters
  • data: data for fft

  • start_pos: start pos

  • end_pos: end pos, end_pos - start_pos must be a power of 2

  • window: window function

double [] perform_ifft (Complex[] data)

perform inverse fft

Return

restored data

Parameters
  • data: data from perform_fft

void write_file (double[,] data, string file_name, string file_mode)

write data to csv file, data will be transposed

Parameters
  • data
  • file_name
  • file_mode

double [,] read_file (string file_name)

read data from file, data will be transposed back to original format

Return

Parameters
  • file_name

int get_nearest_power_of_two(int value)

calculate nearest power of two

Return

nearest power of two

Parameters
  • value

Tuple< double[], double[]> get_avg_band_powers (double[,] data, int[] channels, int sampling_rate, bool apply_filters)

calculate avg and stddev bandpowers across channels

Return

Tuple of avgs and stddev arrays

Parameters
  • data: 2d array with values

  • channels: rows of data array which should be used for calculation

  • sampling_rate: sampling rate

  • apply_filters: apply bandpass and bandstop filters before calculation

Tuple< double[], double[]> get_psd (double[] data, int start_pos, int end_pos, int sampling_rate, int window)

calculate PSD

Return

Tuple of ampls and freqs arrays of size N / 2 + 1

Parameters
  • data: data for PSD

  • start_pos: start pos

  • end_pos: end pos, end_pos - start_pos must be a power of 2

  • sampling_rate: sampling rate

  • window: window function

Tuple< double[], double[]> get_psd_welch (double[] data, int nfft, int overlap, int sampling_rate, int window)

calculate PSD using Welch method

Return

Tuple of ampls and freqs arrays

Parameters
  • data: data for log PSD

  • nfft: FFT Size

  • overlap: FFT Window overlap, must be between 0 and nfft

  • sampling_rate: sampling rate

  • window: window function

double get_band_power(Tuple<double[], double[]> psd, double start_freq, double stop_freq)

calculate band power

Return

band power

Parameters
  • psd: psd data returned by get_psd or get_psd_welch

  • start_freq: lowest frequency of band

  • stop_freq: highest frequency of band

class brainflow::brainflow::MLModel

Public Functions

MLModel(BrainFlowModelParams input_params)

Create an instance of MLModel class

Parameters
  • input_params

void prepare()

Prepare classifier

void release()

Release classifier

double predict (double[] data)

Get score of classifier

Public Static Functions

void enable_ml_logger()

enable ML logger with level INFO

void disable_ml_logger()

disable ML logger

void enable_dev_ml_logger()

enable ML logger with level TRACE

void set_log_file(string log_file)

redirect BrainFlow’s logger from stderr to file

Parameters
  • log_file

class brainflow::brainflow::PlatformHelper

Public Static Functions

LibraryEnvironment get_library_environment()

R API Reference

R binding is a wrapper on top of Python binding. It is implemented using reticulate.

Check R samples to see how to use it.

Full code for R binding:

#' @import reticulate
NULL

#' @export
brainflow_python <- NULL
#' @export
np <- NULL
#' @export
pandas <- NULL
sys <- NULL
type_map <- NULL

.onLoad <- function(libname, pkgname)
{
    brainflow_python <<- import('brainflow', delay_load = TRUE)
    np <<- import('numpy', delay_load = TRUE)
    pandas <<- import('pandas', delay_load = TRUE)
    sys <<- import('sys', delay_load = TRUE)
    type_map <<- function(type)
    {
        if (is.character(type))
        {
            return (list(
                'float32' = np$float32,
                'float64' = np$float64,
                'auto' = NULL
            )[[type]])
        }
        type
    }
}

Matlab API Reference

Matlab binding calls C/C++ code as any other binding, it’s not compatible with Octave.

A few general rules to keep in mind:

  • Use char arrays instead strings to work with BrainFlow API, it means 'my_string' instead "my_string", otherwise you will get calllib error

  • Use int32 values intead enums, it means int32 (BoardIDs.SYNTHETIC_BOARD) instead BoardIDs.SYNTHETIC_BOARD, the same is true for all enums in BrainFlow API

class brainflow.AggOperations

Bases: int32

Store all supported Agg Operations

class brainflow.BoardIDs

Bases: int32

Store all supported board ids

class brainflow.BoardShim(board_id, input_params)

BoardShim object to communicate with device

BoardShim constructor

board_id = None
static load_lib()
static check_ec(ec, task_name)
static set_log_level(log_level)

set log level for BoardShim

static set_log_file(log_file)

set log file for BoardShim, logger uses stderr by default

static enable_board_logger()

enable logger with level INFO

static enable_dev_board_logger()

enable logger with level TRACE

static disable_board_logger()

disable logger

static log_message(log_level, message)

write message to BoardShim logger

static get_sampling_rate(board_id)

get sampling rate for provided board id

static get_package_num_channel(board_id)

get package num channel for provided board id

static get_marker_channel(board_id)

get marker channel for provided board id

static get_battery_channel(board_id)

get battery channel for provided board id

static get_num_rows(board_id)

get num rows for provided board id

static get_timestamp_channel(board_id)

get timestamp channel for provided board id

static get_eeg_names(board_id)

get eeg names for provided board id

static get_device_name(board_id)

get device name for provided board id

static get_eeg_channels(board_id)

get eeg channels for provided board id

static get_exg_channels(board_id)

get exg channels for provided board id

static get_emg_channels(board_id)

get emg channels for provided board id

static get_ecg_channels(board_id)

get ecg channels for provided board id

static get_eog_channels(board_id)

get eog channels for provided board id

static get_ppg_channels(board_id)

get ppg channels for provided board id

static get_eda_channels(board_id)

get eda channels for provided board id

static get_accel_channels(board_id)

get accel channels for provided board id

static get_analog_channels(board_id)

get analog channels for provided board id

static get_other_channels(board_id)

get other channels for provided board id

static get_temperature_channels(board_id)

get temperature channels for provided board id

static get_resistance_channels(board_id)

get resistance channels for provided board id

BoardShim(board_id, input_params)

BoardShim constructor

prepare_session()

prepare BoardShim session

config_board(config)

send string to the board

start_stream(buffer_size, streamer_params)

start data acqusition

stop_stream()

stop acqusition

release_session()

release session

insert_marker(value)

insert marker

get_board_data_count()

get amount of datapoints in internal buffer

get_board_data()

get all collected data and remove it from the buffer

get_current_board_data(num_samples)

get latest datapoints, doesnt remove it from internal buffer

is_prepared()

check if brainflow session prepared

class brainflow.BrainFlowClassifiers

Bases: int32

Store supported classifiers

class brainflow.BrainFlowInputParams

BrainFlow input params, check docs for params for your device

serial_port = None
BrainFlowInputParams()
to_json()
class brainflow.BrainFlowMetrics

Bases: int32

Store all supported metrics

class brainflow.BrainFlowModelParams(metric, classifier)

Store MLModel params

metric = None
BrainFlowModelParams(metric, classifier)
to_json()
class brainflow.DataFilter

DataFilter class for signal processing

static load_lib()
static check_ec(ec, task_name)
static set_log_level(log_level)

set log level for DataFilter

static set_log_file(log_file)

set log file for DataFilter

static enable_data_logger()

enable logger with level INFO

static enable_dev_data_logger()

enable logger with level TRACE

static disable_data_logger()

disable logger

static perform_lowpass(data, sampling_rate, cutoff, order, filter_type, ripple)

perform lowpass filtering

static perform_highpass(data, sampling_rate, cutoff, order, filter_type, ripple)

perform highpass filtering

static perform_bandpass(data, sampling_rate, center_freq, band_width, order, filter_type, ripple)

perform bandpass filtering

You need to provide center freqs and bandwidth

static perform_bandstop(data, sampling_rate, center_freq, band_width, order, filter_type, ripple)

perform bandpass filtering

You need to provide center freqs and bandwidth

static remove_environmental_noise(data, sampling_rate, noise_type)

perform noth filtering

static perform_rolling_filter(data, period, operation)

apply rolling filter

static detrend(data, operation)

remove trend from data

static perform_downsampling(data, period, operation)

downsample data

static perform_wavelet_transform(data, wavelet, decomposition_level)

perform wavelet transform

static perform_inverse_wavelet_transform(wavelet_data, wavelet_sizes, original_data_len, wavelet, decomposition_level)

perform inverse wavelet transform

static perform_wavelet_denoising(data, wavelet, decomposition_level)

perform wavelet denoising

static get_csp(data, labels)

get common spatial patterns

static get_window(window_function, window_len)

get window

static perform_fft(data, window)

perform fft

static perform_ifft(fft_data)

perform inverse fft

static get_avg_band_powers(data, channels, sampling_rate, apply_filters)

calculate average band powers

static get_psd(data, sampling_rate, window)

calculate PSD

static get_psd_welch(data, nfft, overlap, sampling_rate, window)

calculate PSD using welch method

static get_band_power(ampls, freqs, freq_start, freq_end)

calculate band power

static get_nearest_power_of_two(value)

get nearest power of two

static write_file(data, file_name, file_mode)

write data to file, in file data will be transposed

static read_file(file_name)

read data from file

class brainflow.DetrendOperations

Bases: int32

Store possible detrend operations

class brainflow.ExitCodes

Bases: int32

Store all possible exit codes

class brainflow.FilterTypes

Bases: int32

Store all possible filters

class brainflow.IpProtocolType

Bases: int32

Store all possible IP protocols

class brainflow.LogLevels

Bases: int32

Store all possible log levels

class brainflow.MLModel(params)

MLModel for inference

input_json = None
static load_lib()
static check_ec(ec, task_name)
static set_log_level(log_level)

set log level for MLModel

static set_log_file(log_file)

set log file for MLModel

static enable_ml_logger()

enable logger with level INFO

static enable_dev_ml_logger()

enable logger with level TRACE

static disable_ml_logger()

disable logger

MLModel(params)
prepare()

prepare model

release()

release model

predict(input_data)

perform inference for input data

class brainflow.NoiseTypes

Bases: int32

Store noise types

class brainflow.WindowFunctions

Bases: int32

Store window functions

Julia API Reference

Julia binding calls CC++ code as any other binding. Use Julia examples and API reference for other languaes as a starting point.

Since Julia is not Object-Oriented language, there is no DataFilter class. BoardShim class exists but all BoardShim class methods were moved to BrainFlow package and you need to pass BoardShim object to them.

Like here:

using BrainFlow


# specify logging library to use
BrainFlow.enable_dev_logger(BrainFlow.BOARD_CONTROLLER)

params = BrainFlowInputParams()
board_shim = BrainFlow.BoardShim(BrainFlow.SYNTHETIC_BOARD, params)

BrainFlow.prepare_session(board_shim)
BrainFlow.start_stream(board_shim)
sleep(5)
BrainFlow.stop_stream(board_shim)
data = BrainFlow.get_current_board_data(32, board_shim)
BrainFlow.release_session(board_shim)

BrainFlow.write_file(data, "test.csv", "w")
restored_data = BrainFlow.read_file("test.csv")

println("Original Data")
println(data)
println("Restored Data")
println(restored_data)