Package: uvicmuse
UVic MUSEAn application for streaming from MUSE headsets to MATLAB and other
platforms.Software RequirementsThe code relies onbleak(macOS) andpygatt(Windows & Linux) for BLE communication
andpylslfor LSL streaming. We highly recommend installing on a virtual environment (VE). You can build and manage those VEs usingAnaconda,
the instructions to install and setup a conda environment is describedhere.Compatible with Python 3.8+Note: if you run into any issues, first check out out Common Issues
and then the Issues section ofthisrepositoryHardware Requirements** Compatible with MUSEMU-02andMU-03MacOS:This app uses the built-in bluetooth hardware to communicate with MUSE. No extra hardware is required.Windows & Linux:UVic MUSE requires an USB dongle (useBLED112for the best results) to communicate with MUSE on windows and Linux.Make sure you install the correct version.Getting StartedTo stream from MUSE to MATLAB ro other platforms, aStreamerapplication is required.
Transmitted data fromStreamerside then can be received and used by theReceiverapplication.
Take a look at this chart below:This project has two sections, first,UVic MUSEthat connects to MUSE
over Bluetooth and streams its data over UDP and LSL.
Second, a MATLAB toolbox (andMuseUdp.m) that allows the user to receiveUVic MUSEtransmitted data over UDP protocol.
In the following sections we go through installation and usage ofUVic MUSEand then explain about part two, MuseUdp.UVic MUSE InstallationOn Windows we suggest the user to install Anaconda and run all of the following commands
(including optional commands) in an Anaconda Prompt. You may need to installMicrosoft Visual C++ Build Tools(~1GB) from microsoft website if you don't use Anaconda.On MacOS and linux, install Anaconda (or miniconda),
open a terminal, and follow these commands:If you don't want to use a virtual environment, use Terminal (Linux and OSx)
or Command Prompt (Windows) and skip the optional steps.(optional) Create a new conda environment.conda create --name muse_env python=3.8(optional) Activate conda environmentconda activate muse_envInstall dependenciespip install pylsl pygatt # For Windows and MacOS
pip install pylsl==1.10.5 pygatt # For LinuxInstall UVicMUSE usingpippip install --force-reinstall uvicmuse==3.3.2 # for Windows & Linux (with dongle)
pip install --force-reinstall uvicmuse==5.3.2 # for macOS (built-in bluetooth)Running UVicMUSE:To run and useUVic MUSEopen a Terminal (Linux & OSx) or Command Prompt (Windows)
and type in the commands below:(optional) Activate the virtual environmentconda activate muse_envRun UVicMUSE:uvicmuseIf you manage to install UVicMUSE without conda in Windows, you can run it by opening the start menu
and typing uvicmuseGUI:Streaming Procedure:Follow steps shown below to stream the MUSE sensory data. Remember to correctly specify theRequired Entriesvariables
before moving on to the next step.Search to get a list of available MUSEsConnect to one of the MUSEs.Required Entries= Checkboxes (UDP, LSL, EEG, PPG, ACC, GYRO)Start Streaming over UDP and LSL (if enabled).Required Entries= Filters (Highpass, Lowpass, Notch)Notes:Stopping the stream won't disconnect the MUSE (use this feature for changing filters configurations)Search is required after disconnecting from a MUSEThere is no need to set checkboxes on macOS, all sensors are active by defaultReceiver Toolbox (MuseUdp)In this section we explain the methods available in the MATLAB toolbox. The main responsibility of a receiver
is to connect to UDP socket (same socket as UVic MUSE) and receive data that is being transmitted from MUSE device.MATLAB ToolboxDownloadMuseUdp Toolboxfrom MATLAB file exchange.
Open and install the toolbox on MATLAB. Moreover, you need to installInstrument Control Toolboxto establish UDP connections.To see all of the available methods (functions), create an object from MuseUdp and call methods for it:mu = MuseUdp();
methods(mu);To get a single sample from UVic MUSE use:mu = MuseUdp();
[data, timestamp, success] = mu.get_xxx_sample()Replacexxxwitheeg,ppg,accorgyro. The sampled data may have different size according toxxx,eeghas 5
channels per sample, the rest of the sensors return 3 channels data.To read sampled data in chunks, you need to specify the chunk size and callmu.get_xxx_chunk(###), replacexxxwith sensor type
and###with the chunk size. The output size,size(data), will be[chunk_size, 5]foreegand[chunk_size, 3]for others.*Note: since the buffer size is limited for UDP protocols, each sample ofeegcontains four bytes for timestamp and
4 * 5 = 20 bytes for data (24B total). Since default buffer size in UDP is 1kB, one cannot get a chunk larger that 40 samples.
We suggest using multiple instances ofget_xxx_chunk(), but you can change the buffer size by calling the function below:mu.set_udp_buffer_size(2048) % 2kB bufferPyhton LibraryIf you wan to use MUSE's sensory data in python, you can use uvicmuse as a python library. Here is how it works:First you need to import theMuseWrapperclass into your code. Also, you will going to need theasynciolibrary.from uvicmuse.MuseWrapper import MuseWrapper as MW
import asyncioNow get the event loop using theget_even_loopmethod and pass it to theMuseWrapper.loop = asyncio.get_event_loop()
M_wrapper = MW (loop = loop,
                target_name = None,
                timeout = 10,
                max_buff_len = 500)Let's take a look at all of the entries of theMuseWrapper:Loop: The event loop, use get_event_loop to acquiretarget_name: (optional) Use if you want to connect to a specific device. You can use"Muse-3BEA"or"3BEA". Leave this input empty (orNone) if there is only one device in range. You will get an error if there are more than one devices available and this input is empty.timeout: (optional) The timeout for the search. May need to be increase according to the BT device and/or the BT traffic.max_buff_size: (optional) The maximum number of samples that to be temporary saved in the internal buffer. Default is 512.The next step is to search for the target MUSE and connect to it:M_wrapper.search_and_connect() # returnes True if the connection is successfulFinally you can go ahead and read samples from the MUSE:EEG_data = M_wrapper.pull_eeg()
PPG_data = M_wrapper.pull_ppg() # Not available in MU-02
ACC_data = M_wrapper.pull_acc()
GYRO_data = M_wrapper.pull_gyro()The output is a list of samples each containing 5 (for EEG) or 3 (for others) values followed by a timestamp. The buffers reset automatically when read.To disconnect the MUSE, use:M_wrapper.disconnect()IssuesOn MacOSx: Application crashes after running:pip uninstall serial pyserial
conda uninstall serial pyserial
pip install pyserial esptoolCiting UVicMUSE@misc{UVicMUSE,
  author       = {Bardia Barabadi},
  title        = {uvic-muse},
  month        = March,
  year         = 2020,
}