Daily tips and tricks from the experts at Adafruit!
View this email in your browser

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