Implementation

OpenBCI headset

What is OpenBCI?

OpenBCI stands for Open Source Brain-Computer Interface. It is a company that builds open source biosensing boards that can record EEG, EMG, and accelerometer activity. Along with developing the software necessary to interact and record data from the BCI, they also release the schematics for the headset that physically holds the boards. We 3D printed the headsets, assembled the headset, and purchased the wiring and dry electrodes for the board's inputs.

OpenBCI Ganglion Board

Ganglion Board

We purchased the cheapest OpenBCI board, the Ganglion Board. This board has 4 channels and streams via Bluetooth Low Energy at 200Hz. At first we thought that 4 channels may not be enough, however we ended up being constrained by our Android phone's processing power anyways.

Implementation

We wrote the code in Kotlin for Android.

  1. Decompress and process data from Bluetooth stream, converting it to volts
  2. Perform a Fast-Fourier Transformation on each channel
  3. Average the FFT outputs
  4. Perform smoothing on the FFT average. This reduces noise
  5. Calculate the amplitudes of the brain waves by frequencies:
    • Delta: 0.5-4.0Hz
    • Theta: 4.0-8.0Hz
    • Alpha: 8.0-13.0HZ
    • Beta: 13.0-30.0Hz
  6. Calculate drowsyVal = (α + θ) / β. We tested a lot of ratios before we concluded on this one. For example, when we wrote our proposal, based on our research we initially thought that (θ + γ) / (α + β) would yield the best result. However, based on testing we concluded that (α + θ) / β would best suit our needs.
  7. If drowsyVal > 0.8 AND drowsyVal < (value from sensitivity bar) THEN drowsy = true. The 0.8 is a constant that we coded based on our initial testing with users. We noticed that the majority of people's drowsyVal would drop to around that value. However we needed a lower bound because there were testers whose drowsyVal would drop as soon as they go from a relaxed state to an excited state. The upper bound is determined by a sensitivity bar value. We initially used a machine learning decision tree, however users were upset with the many tests needed for the algorithm to learn the user's brain waves, so we decided to give the user the control.
  8. Once the consecutive count threshold has been reached for drowsy = true, THEN alert the user
FFT Plot
Output from participant

Testing Data from Participant 1

Brain Awake Data Brain Drowsy Data

Testing Data from Participant 2

Brain Awake Data Brain Drowsy Data
Output from participant