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


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



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

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, 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.

Join 35,000+ makers on Adafruit’s Discord channels and be part of the community!

Have an amazing project to share? The Electronics Show and Tell is every Wednesday at 7pm ET! To join, head over to YouTube and check out the show’s live chat – we’ll post the link there.

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

Follow Adafruit on Instagram for top secret new products, behinds the scenes and more

CircuitPython – The easiest way to program microcontrollers –

Maker Business — Chip inventories rise as demand falls

Wearables — How to attach a battery to your next wearables project

Electronics — Check out this shorthand shortcut

Python for Microcontrollers — Python on Microcontrollers Newsletter: 400 CircuitPython Libraries, 3m Thanks and much more! #CircuitPython #Python @ThePSF @micropython @Raspberry_Pi

Adafruit IoT Monthly — 2022 in Recap!

Microsoft MakeCode — MakeCode Thank You!

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

New Products – Adafruit Industries – Makers, hackers, artists, designers and engineers! — #NewProducts 1/25/23 Featuring #Adafruit ESP32-S2 Reverse #TFT Feather! @adafruit

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

No Comments

No comments yet.

Sorry, the comment form is closed at this time.