These notebooks are slightly different than the PC notebooks due to differences in the Mac operating system.
You can use this notebook to run N170, P300, or SSVEP experiments (these are the experiments that currently have a corresponding PC notebook, as you can see in the ~/eeg-notebooks/notebooks
directory. Here is a brief description of each of the experiments:
N170 : The N170 was first described by Shlomo Bentin and colleagues in 1996,[5] who measured ERPs from participants viewing faces and other objects. They found that human faces and face parts (such as eyes) elicited different responses than other stimuli, including animal faces, body parts, and cars.
P300 : Analyze event-related potentials related to the detection of 'oddball' visual stimuli.
SSVEP : Run an SSVEP (Steady State Visually Evoked Potentials) to analyze visual evoked potentials. Flashing gratings of two different frequencies will be presented
Run the cells below by pressing Shift
and Enter
at the same time, or by pressing the Run
button up above.
You can find more detailed descriptions of each experiment in their respective notebooks. Note that for SSVEP, you will need an extra electrode (see SSVEP.ipynb for details).
from muselsl import stream, list_muses, view, record
from multiprocessing import Process
from mne import Epochs, find_events
from time import time, strftime, gmtime
import os
# from stimulus_presentation import n170
from utils import utils
from collections import OrderedDict
import warnings
warnings.filterwarnings('ignore')
Note: if using Windows 10 and BlueMuse, skip this section and connect using the BlueMuse GUI
Make sure your device is turned on and run the following code.
It should detect and connect to the device and begin 'Streaming...'
If the device is not found or the connection times out, try running this code again
# Search for available Muse devices
# muses = list_muses()
muses = list_muses()
print(muses)
Searching for Muses, this may take up to 10 seconds... Found device Muse-05AA, MAC Address 00:55:DA:B5:05:AA [{'address': '00:55:DA:B5:05:AA', 'name': 'Muse-05AA', 'rssi': -59, 'packet_data': {'connectable_advertisement_packet': {'flags': bytearray(b'\x06'), 'complete_local_name': 'Muse-05AA', 'incomplete_list_16-bit_service_class_uuids': bytearray(b'\x8d\xfe'), 'slave_connection_interval_range': bytearray(b'\x18\x00\x18\x00'), 'tx_power_level': bytearray(b'\x02')}, 'scan_response_packet': {'manufacturer_specific_data': bytearray(b'0\x00\x01\x04000\x01\x00\x10')}}}]
Now, choose the Muse you want to connect to. Check the ID on the side of your Muse device, and find the matching device in the list above and define the appropriate index in the my_muse_index
variable. That is, if your Muse device is the first device listed above, the index is 1, if it is third in the list, the index is 3, etc.
If the connection is successful, the output will be:
Connected to Muse: [your_muse_id]
Connected
Streaming ...
If this doesn't work, try re-running the cell. You might also need to re-run the cell above. Just keep trying- it will work eventually! Sometimes it just takes time for the connection to be established.
# Start a background process that will stream data from the first available Muse
# if the connection fails, run the list_muses cell above again
my_muse_index = 1
stream_process = Process(target=stream, args=(muses[my_muse_index-1]['address'],))
stream_process.start()
Connecting to Muse: 00:55:DA:B5:05:AA... Connected. Streaming EEG...
Open a new terminal by typing "command" + "T" at the same time.
Run the following to start the viewer and see the raw EEG data stream.
conda activate nbmac
muselsl view --version 2
The numbers on the side of the graph indicate the variance of the signal. Wait until this decreases below 10 for all electrodes before proceeding.
Modify the variables in the following code chunk to define how long you want to run the experiment (# of seconds) and the name of the subject and session you are running. Also choose the appropriate stimulus set for the experiment
variable. Make sure you type this in single quotes.
'n170'
if you are running the N170 experiment'visual_p300_stripes'
if you are running the P300 experiment'ssvep'
if you are running the SSVEP experimentOnce you run the cell below, open a new terminal and run the following:
cd ~/eeg-notebooks/notebooks
conda activate nbmac
Then, paste the output from the cell below into the terminal and press Enter
. This is the command to start the experiment, so make sure that the participant is seated in front of the computer at this point. Then have them quietly view the screen until the experiment is completed.
Here is an example of the experiment command for an N170 experiment that will last 120 seconds, for subject 1 and session 1:
python mac_run_exp.py --d 120 --s 1 --r 1 --e n170
# Define these parameters
duration = 120
subject = 1
session = 1
experiment = 'n170'
# paste the output of this cell into the terminal
cmd2run = 'python mac_run_exp.py --d ' + str(duration) + ' --s ' + str(subject) + ' --r ' + str(session) + ' --e ' + experiment
print(cmd2run)
python mac_run_exp.py --d 120 --s 1 --r 1 --e n170
Visualizing ERPs requires averaging the EEG response over many different rounds of stimulus presentation. Depending on experimental conditions, this may require as little as one two minute trial or as many as 6. We recommend repeating the above experiment 3-6 times before proceeding.
Make sure to take breaks, though! Inattention, fatigue, and distraction will decrease the quality of event-related potentials such as the N170
You can now open the notebook associated with your experiment (N170, P300, SSVEP).
Run the first cell that imports all the tools you will need, then skip to Step 4.
Replace subject
and session
with the subject and session you wish to analyze.