Source code for brainaccess.sdk.alpha_detector

from ctypes import *
from brainaccess.sdk import ba_sdk
from brainaccess.utilities import *

sdk = ba_sdk.get_sdk()

# API

sdk.baSDK_initializeMotionClassifier.restype = c_int
[docs]def initialize(channel_indices): """ Initializes Alpha Detector's internal structures, intializes BrainAccess Core library and attempts to connect to BrainAccess EEG hardware. Must be called before other Alpha Detector functions. Args: ``channel_indices`` ( **list[int]** ): indices of channels that should be used by the algorithm (we recommend using channels placed in oxipital region). Maximum allowed number of channels is 3. Returns: ``bool``: True on success, False on error. """ ch_ptr = python_array_to_ctype(channel_indices, c_int) if sdk.baSDK_initializeAlphaDetector(ch_ptr, len(channel_indices)) != 0: print("Alpha Detector could not be initialized") return False return True
sdk.baSDK_startAlphaDetector.restype = c_int
[docs]def start(): """ Starts EEG data collection. Should be called before :meth:`brainaccess.sdk.alpha_detector.predict` or :meth:`brainaccess.sdk.alpha_detector.predict_from_now`. Returns: ``bool``: True on success, False on error. """ return sdk.baSDK_startAlphaDetector() == 0
sdk.baSDK_stopAlphaDetector.restype = c_int
[docs]def stop(): """ Stops EEG data collection Should be called when Alpha Detector is no longer needed. Returns: ``bool``: True on success, False on error. """ return sdk.baSDK_stopAlphaDetector() == 0
sdk.baSDK_estimateAlphaFrequency.restype = c_int
[docs]def estimate_alpha(): """ Estimates the alpha frequency for the user. Each person has a slightly different alpha brainwave frequency, although it is usually in the range of 8-12Hz. This algorithm works best by firstly estimating the frequency for the current user. When this method is called, user should sit still, with his/her eyes closed for 3 seconds. Returns: ``bool``: True on success, False on error. """ return sdk.baSDK_estimateAlphaFrequency() == 0
sdk.baSDK_predictAlpha.restype = c_double
[docs]def predict(): """ Predicts alpha wave intensity from the latest EEG data. The data used in the previous predictions is reused if needed. If not enough data is available, this function firstly waits for the data and only then predicts. Returns: ``float``: Estimation of alpha wave intensity as a measure between 0 and 1. For small alpha wave activities expect the value to be around 0.05 For strong alpha waves expect the value to be up to 0.5 (larger values are less common). """ return sdk.baSDK_predictAlpha()
sdk.baSDK_predictAlphaFromNow.restype = c_double
[docs]def predict_from_now(): """ Predicts alpha wave intensity from EEG data collected from the moment this function is called. Previously collected data is discarded and the algorithm collects the required number of measurements before predicting. This can be useful if prediction should be made with data collected after some kind of event. Returns: ``float``: The same alpha intensity evaluation as :meth:`brainaccess.sdk.alpha_detector.predict`. """ return sdk.baSDK_predictAlphaFromNow()