{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Welcome to EEG notebooks for Mac! \n",
"\n",
"These notebooks are slightly different than the PC notebooks due to differences in the Mac operating system. \n",
"\n",
"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:\n",
"\n",
"* 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.\n",
"\n",
"* P300 : Analyze event-related potentials related to the detection of 'oddball' visual stimuli.\n",
"\n",
"* SSVEP : Run an SSVEP (Steady State Visually Evoked Potentials) to analyze visual evoked potentials. Flashing gratings of two different frequencies will be presented\n",
"\n",
"\n",
"## Instructions:\n",
"\n",
"Run the cells below by pressing `Shift` and `Enter` at the same time, or by pressing the `Run` button up above.\n",
"\n",
"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)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Step 0: Import the tools you need"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"inputHidden": false,
"outputHidden": true
},
"outputs": [],
"source": [
"from muselsl import stream, list_muses, view, record\n",
"from multiprocessing import Process\n",
"from mne import Epochs, find_events\n",
"from time import time, strftime, gmtime\n",
"import os\n",
"# from stimulus_presentation import n170\n",
"from utils import utils\n",
"from collections import OrderedDict\n",
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Step 1: Connect to an EEG Device\n",
"*Note: if using Windows 10 and BlueMuse, skip this section and connect using the BlueMuse GUI*\n",
"\n",
"Make sure your device is turned on and run the following code. \n",
"\n",
"It should detect and connect to the device and begin 'Streaming...'\n",
"\n",
"If the device is not found or the connection times out, try running this code again"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Searching for Muses, this may take up to 10 seconds...\n",
"Found device Muse-05AA, MAC Address 00:55:DA:B5:05:AA\n",
"[{'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')}}}]\n"
]
}
],
"source": [
"# Search for available Muse devices\n",
"# muses = list_muses()\n",
"muses = list_muses()\n",
"print(muses)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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.\n",
"\n",
"If the connection is successful, the output will be:\n",
"\n",
"Connected to Muse: [your_muse_id] \n",
"Connected \n",
"Streaming ...\n",
"\n",
"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. \n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Connecting to Muse: 00:55:DA:B5:05:AA...\n",
"Connected.\n",
"Streaming EEG...\n"
]
}
],
"source": [
"# Start a background process that will stream data from the first available Muse\n",
"# if the connection fails, run the list_muses cell above again\n",
"\n",
"my_muse_index = 1\n",
"\n",
"stream_process = Process(target=stream, args=(muses[my_muse_index-1]['address'],))\n",
"stream_process.start()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Step 2: Apply the EEG Device and Wait for Signal Quality to Stabilize\n",
"\n",
"\n",
"Open a new terminal by typing \"command\" + \"T\" at the same time.\n",
"\n",
"Run the following to start the viewer and see the raw EEG data stream.\n",
"\n",
"`conda activate nbmac` \n",
"`muselsl view --version 2`\n",
"\n",
"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."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Step 3: Run the Experiment\n",
"\n",
"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.\n",
"* choose `'n170'` if you are running the N170 experiment\n",
"* choose `'visual_p300_stripes'` if you are running the P300 experiment\n",
"* choose `'ssvep'` if you are running the SSVEP experiment\n",
"\n",
"Once you run the cell below, open a new terminal and run the following:\n",
"\n",
"`cd ~/eeg-notebooks/notebooks` \n",
"`conda activate nbmac`\n",
"\n",
"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. \n",
"\n",
"Here is an example of the experiment command for an N170 experiment that will last 120 seconds, for subject 1 and session 1: \n",
"\n",
"`python mac_run_exp.py --d 120 --s 1 --r 1 --e n170`\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"python mac_run_exp.py --d 120 --s 1 --r 1 --e n170\n"
]
}
],
"source": [
"# Define these parameters \n",
"duration = 120\n",
"subject = 1\n",
"session = 1\n",
"experiment = 'n170'\n",
"\n",
"# paste the output of this cell into the terminal\n",
"cmd2run = 'python mac_run_exp.py --d ' + str(duration) + ' --s ' + str(subject) + ' --r ' + str(session) + ' --e ' + experiment\n",
"print(cmd2run)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Repeat Data Collection 3-6 times \n",
"\n",
"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. \n",
"\n",
"Make sure to take breaks, though! Inattention, fatigue, and distraction will decrease the quality of event-related potentials such as the N170\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Step 4: Analyze your data\n",
"\n",
"You can now open the notebook associated with your experiment (N170, P300, SSVEP). \n",
"Run the first cell that imports all the tools you will need, then skip to Step 4. \n",
"Replace `subject` and `session` with the subject and session you wish to analyze."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernel_info": {
"name": "mne"
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.10"
},
"nteract": {
"version": "0.8.4"
}
},
"nbformat": 4,
"nbformat_minor": 4
}