Screen Shot 2019-11-07 at 10.35.04 AM.png

Brainwave Meditation Journal

Screen Shot 2019-11-07 at 10.35.04 AM.png

About

The Brainwave Meditation Journal is an extension of my thesis project at Hunter College, “Entheogen”. A description of this project can be found here.

The Muse 2016 headset connects to the Muse Direct App via Bluetooth Low Energy. Once the headset is turned on and connected to Muse Direct, live data from all four sensors on the EEG is streamed and analyzed by the app. Muse Direct allows users to record EEG sessions or meditation sessions which are stored on the cloud and can be accessed by logging into Muse Direct Cloud. Users upload EEG meditation sessions that were recorded in the Muse Direct app and these files are analyzed on the backend. 

Features

Users can login or create an account using auth, jwt, and bcrypt. Once logged in, they edit their profile and are free to create, read, update, and delete posts. When a user creates a post, they are required to upload a thumbnail image and an EEG JSON file that they downloaded from Muse Direct Cloud. On submission, these files are stored in firebase and their new urls are stored in the database. When a user views a post, the frontend renders the images from firebase and makes a GET request to the backend to retrieve the analyzed EEG data for the p5.js visualizations.

Motivation

The motivation behind this application was to use recorded EEG data to generate visuals rather than use live EEG data. I wanted to work on another iteration of my thesis, one that visualized meditation sessions from different days and settings, and that required the use of recorded data. I was also interested in using recorded data instead of live because it is more useful for testing and scalability.

The biggest challenges I had working on this project were documentation, file size and parsing errors. As of early 2019, the developer docs for the Muse headset are no longer online. I used the wayback machine on archive.org to view some of the docs. These files are unimaginably massive and whenever I tried parsing them, regardless of filetype, I kept running into errors. With some help I was able to find the source of the problem and work around it.

The source of the problem - the sensors on the Muse headset are very sensitive and when they are not picking up a strong enough signal the value for the brainwave data on that signal is NaN. NaN is not part of the JSON specification and the JSON parser of JavaScript or Ruby cannot handle NaN. The solution was to parse the file as a string and use regex to change NaN to null (or whatever you want it to be) and then turn that string into a JSON and parse/manipulate it.