Muse 101 — How to start Developing with the Muse 2 right now

What is the Muse 2?

Example of a live EEG stream plotting voltages from the Muse 2.

Can you build with the Muse 2?

  • Hands-free slideshows with EEG eyeblink detection
  • Using a web browser with EEG artifacts and focus/concentration
  • Making custom video summaries using EEG
  • Improving accessibility and transparency in Social Media using a P300 Speller and Emotion Detection (*this project was made for Emotiv’s suite of consumer EEGs, but it also supports the Muse 2)

Don’t reinvent the wheel, get help from others

  • Brainflow Slack — Brainflow is a useful python library that provides functions to filter, parse, and analyze EEG data from various headsets.
  • NeurotechX — An international community of 23k fellow neurotech enthusiasts in 30 cities worldwide. This is one of my go-to channels for finding ways to troubleshoot my Muse 2.
  • LabStreamingLayer Slack — You’ll find yourself using the lab streaming layer (LSL) a ton with the Muse 2, so this is definitely a useful channel to join.
  • Brains@play — “Brains@Play is developing an open-source framework for creating brain-responsive applications using modern web technologies.” Brains@play has a super active community and is constantly looking for new and innovative ideas for BCI web apps (if you’re into web dev, you should 100% join).

Signal Acquisition — Getting a data stream going

LSL and OSC

An example of a potential system that uses various data streams to show the potential of LSL.
An example of an OSC use case.

Starting an LSL outlet with the Muse 2

  • (Personal Choice) Bluemuse — An O.G. among the Muse community, Bluemuse provides a super minimalistic and intuitive GUI for making an LSL connection with Muse 2. Bluemuse not only has the functionality to stream EEG data from the Muse 2 but also collect data from its other sensors concurrently, utilizing LSL’s full potential. Requires Windows 10 OS.
Bluemuse UI #1
Bluemuse UI #2
  • uvicMuse — Created by Dr. Krigolson at the University of Victoria, uvicMuse also provides all data types from the Muse 2, and can additionally stream data over UDP as well, adding support to Matlab applications. The app can also apply filters to the data being streamed (Highpass, Lowpass, Notch). Supports Mac, Windows, and Linux systems.
uvicMuse UI
  • (Recommended) Petal Metrics — A relatively newer app in this area, Metrics provides a variety of new features that aren’t found in the other 2 apps described above. Metrics allows you to stream via LSL and OSC, automatically logs streaming sessions into CSVs, and allows support for extra auxiliary electrodes (a huge plus!). Supports Mac, Windows, and Linux systems. This is my recommended app for starting an LSL connection because Metrics is frequently being updated with new features, in comparison to both uvicMuse and Bluemuse which are relatively dated.
Petal Metrics UI

Subscribing to the LSL stream — Creating an Inlet

"""Example program to show how to read a multi-channel time series from LSL."""from pylsl import StreamInlet, resolve_stream # first resolve an EEG # stream on the lab networkprint("looking for an EEG stream...")
streams = resolve_stream('type', 'EEG') # create a new inlet to read # from the stream
inlet = StreamInlet(streams[0])
while True:
# get a new sample (you can also omit the timestamp part if you're
# not interested in it)
sample, timestamp = inlet.pull_sample()
print(timestamp, sample)
  • PyLSL
  • Lab Recorder
  • MuseLSL

Bonus Option for Local Streaming — Brainflow

# Code example for logging data from the Muse 2import time
from brainflow.board_shim import BoardShim, BrainFlowInputParams
from brainflow.data_filter import DataFilter, FilterTypes, AggOperations
def main():
BoardShim.enable_dev_board_logger()
params = BrainFlowInputParams()
params.serial_port = "COM port for BLED112 Dongle"
params.timeout = "timeout for device discovery or connection"
board = BoardShim(22, params)
board.prepare_session()
board.start_stream() # use this for default options
time.sleep(10)
data = board.get_board_data() # get all data and remove it from internal bufferboard.stop_stream()
board.release_session()
print(data)if __name__ == "__main__":
main()

Streaming the Muse 2 for Web Development

  • Node-LSL — Conveniently, you can continue using LSL when you move to web dev with Node-LSL which provides a similar process to connect to the Muse 2 like in python. Additionally, if you were to use this method in an app meant for deployment, you would also have to create an interface where users can instantiate an LSL stream outlet (similar to Bluemuse).
  • TimeFlux — Written in python, TimeFlux provides a graph-based method for going about running closed-loop BCI applications. The beauty of Timeflux is its wide selection of plugins that can be used as part of a graph, essentially eliminating the need for any code for any type of manipulation of the EEG signal after a stream is set. If you wanted to use TimeFlux for web development, you would simply add in a “UI” node that would specify you’re frontend. This application also uses LSL so you would need to use Node-LSL or some other library in parallel to create an LSL stream inlet.
Above is a diagram of a potential neurofeedback app created using TimeFlux. This structure of the application would be simply written in YAML, specifying the nodes (LSL, Rolling Filter, etc.) and edges.
  • Personal Choice: Brains@play — Brains@play provides an awesome framework for developing brain-responsive web apps, using a similar graph-based structure to that of Timeflux, but with a few more bells and whistles. Brains@play handles all of the Web Bluetooth connection work through the data atlas where all user data is stored and can be accessed from the UI when a device connects. Brains@play also has amassed a variety of its own plugins, such as blink detection, which can be used effortlessly with the Muse 2 to map to different controls (e.g. keypresses). Additionally, brains@play also provides multiplayer functionality, which opens the possibility for brain-to-brain apps.
MindPong, a multiplayer game built using brains@play’s code free graph editor.

Streaming data through a Mobile Device

An example of an absolute power plot on Mind Monitor.

What to use for Digital Signal Processing

  1. Preprocessing EEG to eliminate irrelevant noise,
  2. and applying transforms to the data to get relevant information
  • Recommended for analysis: MNE — The industry standard for neurophysiological data processing, MNE provides end-to-end utilities for managing EEG. With MNE, you can find all the analysis methods that you can think of with this package, from time-frequency analysis to source localization. Once you load your raw EEG data into MNE objects (Raw and Epochs objects), it’s only a matter of calling a few methods to get the data you need. I would personally start learning and using this library before moving on to the next ones.
Example of a power spectral density transform and different data types using MNE.
  • Brainflow — Another library specializing in Neurophysiological data, focuses less on post-recording analysis, and more on real-time analysis of EEG, meaning many of the library’s functions take in single epochs of data. Brainflow goes for more of a brain-computer interface supportive approach in comparison to MNE. Brainflow’s filters and transforms are also more beginner-friendly compared to other libraries, as they don’t require the data to be in a certain format, and many of the filter designs have attributes that are predefined. Brainflow also comes with a few pre-trained models that can be used for predicting relaxation and concentration among other things.
  • Scipy — If you’ve done any python programming before, you’ve probably ended up using the Scipy stack one way or another, and conveniently Scipy also provides a few modules that can be used for EEG processing, specifically scipy.signal and scipy.fft. The signal module provides foundational blocks necessary for creating your own filter designs, can create spectrograms and wavelets, and create windows, which are all important parts of an EEG preprocessing pipeline. The fft module on the other hand simply allows you to apply a Fast Fourier Transform on your signal, which is an intermediary step in many analysis methods with EEG. Using SciPy for EEG signal processing definitely requires more technical knowledge, because of how much can be tuned and customized.
  • Antropy — Entropy in a general sense is interpreted as the amount of randomness in a system, and is an important metric in EEG analysis. Spectral entropy, Shannon entropy, sample entropy, and other entropies provide a valuable feature set for various applications, such as emotion detection, and Antropy provides most of them. It’s my go-to library in terms of calculating entropies.
  • PyWavelets — Wavelets are a very valuable asset to a BCI developers tool-kit, and PyWavelets provides an easy way to implement them in your pipeline. The library provides most families of wavelets, continuous wavelets, and functions for both decomposition and recomposition of discrete wavelets.
# takes only 2 lines of code to get wavelet coefficients :)
import
pywt
cA, cD = pywt.dwt(eeg_data, 'db1')
  • Recommended for R-T: Wyrm — To be concise, Wyrm aims to be the MNE for brain-computer interfaces applications. Wyrm is optimized for real-time use and provides a very similar system as MNE, where you first load in your raw EEG into a Wyrm Data object, and from there you’re able to apply a wide variety of filters, transforms, and segmentation techniques. Though this library is less popular compared to its counterpart, I still recommend using this library because of its all-in-one real-time capabilities.

Visualizing Muse 2 data

  • MNE — One can’t discuss EEG visualizations without bringing up MNE! This library provides a ton of methods to plot everything from averaged event-related potentials to scalp topographies, and these can be called on the raw data once they’ve been loaded in MNE’s data objects. MNE also supports real-time plotting, which is a huge plus.
An example of a joint plot (Topo+ERP) created using MNE.
  • Wyrm — Needless to say, being MNE’s real-time counterpart, Wyrm also boasts its own share of visualization techniques. Though less extensive compared to MNE, it still holds up in regards to the classics, like spectrograms and topographic maps. Wyrm can be used for real-time plotting if used alongside MatPlotLib’s animation module.
Example of time-course plots for three selected channels using Wyrm.
  • Visbrain — This library can be a highly valuable tool if you’ve decided to go on the path of avoiding both MNE and Wyrm. Visbrain allows you to directly plug in a NumPy array into one of its various objects to plot data, and provides all of MNE’s plotting functionality (aside from source estimation). Visbrain is split into 3 main modules: the brain module, which utilizes MNI space plots, the sleep module, which visualizes and scores polysomnographic data, and signal, which visualizes multi-dimensional datasets.
Vizbrain structure provided in their documentation.
  • Fastest method for R-T plotting: MuseLSL — Before any recording sessions, I always use MuseLSL to plot raw EEG in real-time to validate that my headset is fitted correctly; it’s a super quick option; all you have to do is run this command in the console once you’ve pip installed the library and have initialized a Muse 2 LSL outlet (using Bluemuse or any other method described in the signal acquisition section) :
muselsl view # this will start a live EEG plot using PyGatt as the backend
Example of a live raw EEG plot using MuseLSL (seems like the AF8 electrode has contact issues, this is how you would be able to adjust your headset)

A Useful Bonus — EEG-Notebooks

A summarization of EEG-Notebooks :) (creds: https://github.com/NeuroTechX/eeg-notebooks)
conda create -n "eeg-notebooks" python=3.7 git pip

conda activate "eeg-notebooks"

git clone https://github.com/NeuroTechX/eeg-notebooks

cd eeg-notebooks

pip install -e
eegnb runexp -ip
  • LSL connections,
  • visual and auditory stimulus presentation,
  • and signal processing, statistical, and machine learning EEG analysis

TL;DR — A 3-Step Process

1. Signal Acquisition

  1. Starting an LSL outlet with the Muse 2

2. Signal Processing

3. Visualization

Final Thoughts

  1. Getting the raw signal
  2. Cleaning the raw signal with filters
  3. Applying transforms on the data to get a meaningful feature set
  4. Predicting something from the data
  5. Mapping the predictions to some action

--

--

anushmutyala.com | neuradao.co | neuronic.ca | BCI, NLP, and Web3

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store