Summarizing EEG Data from the Command Line

Researching brainwave patterns requires working with large data sets. This post explains how we can quickly review a huge CSV file generated from the MUSE EEG headband using simple command line tools. Muse has recently released a new app for iOS and Windows 10 called Muse Direct which allows for easy recording, graphing and savings of EEG data to the their cloud. Once we have a recording we can download a CSV file and summarize the data.

After launching Muse Direct and doing a brief recording we can see a new file is available on the Muse Direct Cloud website. We can download five different formats, but today we will focus on just downloaded the CSV file as it requires the least amount of tools to work with.  The other formats have many dependencies on python libraries and Matlab (which starts at $150).

We will be using the csvkit to rapidly shape arrays into smaller datasets. This utility can be installed from the command line using:

$ pip install csvkit

Let’s get familiar with the data by checking out the first line of the file which names all the columns.

$ head -1 eeg.meditation.csv

timestamps,eeg_1,eeg_2,eeg_3,eeg_4,eeg_5,eeg_6,acc_1,acc_2,acc_3,gyro_1,gyro_2,gyro_3,batt_1,batt_2,batt_3,batt_4,drlref_1,drlref_2,mag_1,mag_2,mag_3,uv_1,uv_2,uv_3,press,temp,notch_filtered_eeg_1,notch_filtered_eeg_2,notch_filtered_eeg_3,notch_filtered_eeg_4,variance_eeg_1,variance_eeg_2,variance_eeg_3,variance_eeg_4,variance_notch_filtered_eeg_1,variance_notch_filtered_eeg_2,variance_notch_filtered_eeg_3,variance_notch_filtered_eeg_4,delta_absolute_1,delta_absolute_2,delta_absolute_3,delta_absolute_4,theta_absolute_1,theta_absolute_2,theta_absolute_3,theta_absolute_4,alpha_absolute_1,alpha_absolute_2,alpha_absolute_3,alpha_absolute_4,beta_absolute_1,beta_absolute_2,beta_absolute_3,beta_absolute_4,gamma_absolute_1,gamma_absolute_2,gamma_absolute_3,gamma_absolute_4,delta_relative_1,delta_relative_2,delta_relative_3,delta_relative_4,theta_relative_1,theta_relative_2,theta_relative_3,theta_relative_4,alpha_relative_1,alpha_relative_2,alpha_relative_3,alpha_relative_4,beta_relative_1,beta_relative_2,beta_relative_3,beta_relative_4,gamma_relative_1,gamma_relative_2,gamma_relative_3,gamma_relative_4,delta_session_score_1,delta_session_score_2,delta_session_score_3,delta_session_score_4,theta_session_score_1,theta_session_score_2,theta_session_score_3,theta_session_score_4,alpha_session_score_1,alpha_session_score_2,alpha_session_score_3,alpha_session_score_4,beta_session_score_1,beta_session_score_2,beta_session_score_3,beta_session_score_4,gamma_session_score_1,gamma_session_score_2,gamma_session_score_3,gamma_session_score_4,blink,jaw_clench,headband_on,is_good_1,is_good_2,is_good_3,is_good_4,hsi_precision,note,recorder_info,config,recording_notes

The csvstat  included with the csvkit utilities provides a powerful summary for each column complete with# ranges for the values. Since this five minute recording resulted in a 85MB file let’s limit our query to looking at the first 500 lines of the file.

$ head -500 eeg.meditation.csv | csvstat

1. “timestamps”

Type of data:Number

Contains null values:False

Unique values: 106

Smallest value:1,528,057,484.807

Largest value: 1,528,057,486.13

Sum: 762,500,685,266.869

Mean:1,528,057,485.505

Median:1,528,057,485.49

StDev: 0.36

Most common values:1,528,057,485.17 (24x)

1,528,057,485.27 (23x)

1,528,057,485.78 (23x)

1,528,057,485.88 (23x)

1,528,057,484.96 (21x)

2. “eeg_1”

Type of data:Boolean

Contains null values:True (excluded from calculations)

Unique values: 1

Most common values:None (499x)

3. “eeg_2”

Type of data:Boolean

Contains null values:True (excluded from calculations)

Unique values: 1

Most common values:None (499x)

One fun stat that EEGs are good at picking up is eye blinking. We can get a summary of how many times I blinked my eyes during this session by using the following commands. It looks as though I blinked 27x!

$ head -1 eeg.meditation.csv | csvstat | grep -i blink

100. “blink”

$ csvcut -c 100 eeg.meditation.csv | csvstat

1. “blink”

Type of data:Boolean

Contains null values:True (excluded from calculations)

Unique values: 3

Most common values:None (499928x)

False (3446x)

True (27x)

Row count: 503401

Was I clenching my jaw? That would show up too.

$ head -1 eeg.meditation.csv | csvstat | grep -i jaw_clench

101. “jaw_clench”

$ csvcut -c 101 eeg.meditation.csv | csvstat

1. “jaw_clench”

Type of data:Boolean

Contains null values:True (excluded from calculations)

Unique values: 3

Most common values:None (499928x)

False (3384x)

True (89x)

Row count: 503401

The absolute readings for each brainwave {delta, theta, alpha, beta and gamma} on all four electrodes is interesting. We can get a quick summary for every brainwave on each electrode to narrow down what part of our head different brainwaves map to and how strong on average they are.

$ head -1 eeg.meditation.csv | csvstat | grep -i absolute

40. “delta_absolute_1”

41. “delta_absolute_2”

42. “delta_absolute_3”

43. “delta_absolute_4”

44. “theta_absolute_1”

45. “theta_absolute_2”

46. “theta_absolute_3”

47. “theta_absolute_4”

48. “alpha_absolute_1”

49. “alpha_absolute_2”

50. “alpha_absolute_3”

51. “alpha_absolute_4”

52. “beta_absolute_1”

53. “beta_absolute_2”

54. “beta_absolute_3”

55. “beta_absolute_4”

56. “gamma_absolute_1”

57. “gamma_absolute_2”

58. “gamma_absolute_3”

59. “gamma_absolute_4”

It might be easier to work with a seperate file so we can create eeg.absolute.csv which only contains the columns we are interested in examining.

$ csvcut -c 40-59 eeg.meditation.csv > eeg.absolute.csv

$ csvstat –mean eeg.absolute.csv

  1. delta_absolute_1: 0.231

  2. delta_absolute_2: 0.384

  3. delta_absolute_3: 0.175

  4. delta_absolute_4: 0.213

  5. theta_absolute_1: 0.201

  6. theta_absolute_2: 0.028

  7. theta_absolute_3: -0.069

  8. theta_absolute_4: 0.087

  9. alpha_absolute_1: 0.796

10. alpha_absolute_2: 0.075

11. alpha_absolute_3: 0.174

12. alpha_absolute_4: 0.704

13. beta_absolute_1: 0.421

14. beta_absolute_2: -0.235

15. beta_absolute_3: 0.042

16. beta_absolute_4: 0.494

17. gamma_absolute_1: 0.219

18. gamma_absolute_2: -0.568

19. gamma_absolute_3: -0.046

20. gamma_absolute_4: 0.208


Halloween season is here!
Halloween season is here! Check out all the posts, gift guides, and more!

Adafruit publishes a wide range of writing and video content, including interviews and reporting on the maker market and the wider technology world. Our standards page is intended as a guide to best practices that Adafruit uses, as well as an outline of the ethical standards Adafruit aspires to. While Adafruit is not an independent journalistic institution, Adafruit strives to be a fair, informative, and positive voice within the community – check it out here: adafruit.com/editorialstandards

Stop breadboarding and soldering – start making immediately! Adafruit’s Circuit Playground is jam-packed with LEDs, sensors, buttons, alligator clip pads and more. Build projects with Circuit Playground in a few minutes with the drag-and-drop MakeCode programming site, learn computer science using the CS Discoveries class on code.org, jump into CircuitPython to learn Python and hardware together, TinyGO, or even use the Arduino IDE. Circuit Playground Express is the newest and best Circuit Playground board, with support for CircuitPython, MakeCode, and Arduino. It has a powerful processor, 10 NeoPixels, mini speaker, InfraRed receive and transmit, two buttons, a switch, 14 alligator clip pads, and lots of sensors: capacitive touch, IR proximity, temperature, light, motion and sound. A whole wide world of electronics and coding is waiting for you, and it fits in the palm of your hand.

Have an amazing project to share? The Electronics Show and Tell is every Wednesday at 7:30pm ET! To join, head over to YouTube and check out the show’s live chat and our Discord!

Join us every Wednesday night at 8pm ET for Ask an Engineer!

Join over 38,000+ makers on Adafruit’s Discord channels and be part of the community! http://adafru.it/discord

CircuitPython – The easiest way to program microcontrollers – CircuitPython.org


New Products – Adafruit Industries – Makers, hackers, artists, designers and engineers! — JP’s Product Pick of the Week — 4pm Eastern TODAY! 10/8/24 @adafruit #adafruit #newproductpick

Python for Microcontrollers – Adafruit Daily — Python on Microcontrollers Newsletter: New Python Releases, an ESP32+MicroPython IDE and Much More! #CircuitPython #Python #micropython @ThePSF @Raspberry_Pi

EYE on NPI – Adafruit Daily — EYE on NPI Maxim’s Himalaya uSLIC Step-Down Power Module #EyeOnNPI @maximintegrated @digikey

Adafruit IoT Monthly — Garden Lights, Bluetooth 6.0, and more!

Maker Business – Adafruit Daily — A look at Boeing’s supply chain and manufacturing process

Electronics – Adafruit Daily — When do I use X10?

Get the only spam-free daily newsletter about wearables, running a "maker business", electronic tips and more! Subscribe at AdafruitDaily.com !



No Comments

No comments yet.

Sorry, the comment form is closed at this time.