Sunday, January 19, 2014

Blinky Lights - Visual Entrainment

In talking up my EEG hacking with some friends, I found a buddy who was really interested.  In particular, he was interested these smartphone apps that claim to affect your sleep state.  My friend wanted to know if these apps actually did anything to the brain.  That's a pretty cool question, and very similar to the question that I had about meditators (see their results here and here).  To figure out if his sleep-modifying apps were doing anything to his brain wave, he volunteered to be my guinea pig.  What a guy!

A Willing Guinea Pig Meets the Red EEG Cap


This post shows some of the data that I collected...though not yet when subject to the sleep app.  I decided to start simple and record how his particular brain responds to sensory entrainment.  Entrainment is how these sleep apps work, so if we understand how he responds to entrainment in general, we'll be well-positioned to understand his response to the sleep apps.  So

Background:  It is my understanding that the sleep apps work by playing specially-constructed sounds into your ears via headphones.  They're trying to induce certain brain rhythms (Delta, Theta, Alpha, Beta, etc) by playing audio into your ears at the same frequency as the desired brain rhythm.  Put most simply, they play a 10 Hz tone into your ears and hope to get brain waves at 10 Hz (ie, Alpha rhythm).  This is called entrainment and is a long-known phenomenon in EEG.  Personally, I'm not too familiar with this type of auditory entrainment, but I do know that visual entrainment, so I'm going to start there.

Setup:  I'm using the same setup as I used for my recordings of meditators.  I used an EEG electrode cap (this is the first time using the red-colored cap, though...exciting!) with the EEG electrode gel that came with the electrode cap kit (ECI Electro-Gel).  We used the same electrode montage (see figures below), the same reference electrode (near FPz/AFz) and the same ground/bias electrode (right mastoid).  For electronics, I used an OpenBCI V1 board with an Arduino streaming data to my PC running our full GUI that was written in Processing.

Baseline, Eyes-Closed Alpha:  Since I had never recorded my friend's EEG before, I decided to start with the most basic recording -- I had him close his eyes so that we could see his Alpha-wave posterior dominant rhythm (PDR).  The spectrograms in the montage below show his response...it is very normal.  Note the energy in the Alpha band (~10 Hz) that shows up most strongly in the back of his head and not at all in the front of his head.  As I said, very normal.

Spectrograms of EEG Signals Recorded With the Eyes Closed.
Notice the Strong (and typical) Energy in the Alpha Frequencies.
Click to Zoom.

In the figure below, I summarize this PDR Alpha response across the eight electrodes.  It shows that his Alpha peaks at about 10.25 Hz.  His Alpha are a bit stronger on the left side of his head (channel 7, green) than on the right (channel 8, blue).  That's also what happens with me.  I've always wondered if this asymmetric Alpha response is related to handedness.  I'm right handed.  I don't know handedness my friend is.  It would be interesting to record a lefty and see what happens!

Average EEG Amplitude Recorded With Eyes Closed and Relaxing.
Notice the Strong Peak in the Alpha Band (~10 Hz).
Finally, the last thing that I'd like to examine with his eyes-closed Alpha data is the spectral coherence of the EEG signals from neighboring electrodes.  This is a quantity that I first analyzed in this post on my second meditator.  It shows how strongly related (how correlated) are the signals between two electrodes.  I use this type of analysis to estimate whether the different physical areas of the brain are working together or independently.

Below are the cross-channel coherence plots for my friend sitting with his eyes closed.  Like with my meditating friend, he shows very little coherence in the front of they head (those areas must be acting independently relative to each other) and more coherence towards the back of the head.  Looking specifically at the Alpha band, it looks like the Alpha seen between electrodes 5 and 7 (ie, back left) are strongly related to each other.  Same with the Alpha seen between electrodes 6 and 8 (ie, back right).  In the very back of the head (7 and 8), the 10 Hz energy is not very coherent between the two hemispheres, even though they are physically closer together that 5/7 or 6/8.  This is so interesting to me.  It is also the same result that we saw with my meditator friend when he was not meditating.

Spectral Coherence Between Neighboring Electrodes.   Strong coherence (red) implies coordinated
EEG activity whereas low coherence (blue) implies independent EEG activity.
Click to Zoom.

Visual Entrainment:  Now we start to do something new.  To see how entrainment works, I started with the easiest sensory entrainment that I know about -- visual entrainment.  The idea here is that you blink a light at a certain speed and you look for brain rhythms at that same frequency.  Truth-be-told, I wasn't actually planning on doing this test, so I didn't have a good light prepared.  But I do have a nice new, really-bright hiking headlamp that has a blink setting.  I don't know exactly what speed it is, but I counted blinks and it's less than 5 Hz.  Sadly, it's blinking rate isn't as steady as I might like.  But, when you're EEG hacking, sometimes you gotta be quick and dirty.

[WARNING!  Be careful doing this kind of test at home!  Blinking lights like this can induce seizures!  Proceed at your own risk!]

To do my visual entrainment test, I darkened the room and had my friend sit in a chair, like before.  I held the blinking light about a foot and a half from his face (see picture below).  We did part of a recording where his eyes were open and looking at the blinking light (so bright!), then he closed his eyes while the blinking continued, then he opened his eyes again.  It turns out that only the eyes-closed portion gave decent results, so that data is what I'm going to focus on.

Attempting Visual Entrainment Using a Blinking LED Hiking Headlamp

If we start with the spectrograms (below, you might want to click on the figure to see it bigger), you'll see that we got a nice line of energy down at the low frequencies (~4 Hz).  The line only appears when both the light was blinking and when his eyes were closed.  Note that it shows up in all EEG channels, but it appears to be a bit stronger on the right side of his head.  These lines in the spectrograms mean that his brain waves were indeed being induced to oscillate at the same rate as the blinking light.  It's a well known effect, but I still think that's kinda cool.

Spectrograms of EEG Signals Recording With Eyes Closed with a Bright Blinking Light.
Click to Zoom.

These spectrograms are summarized in the single spectrum plot below.  It shows a peak at 3.9 Hz, which is most likely the blinking rate of my head lamp.  The amplitude of the entrained waves is quite strong --  note that it is similar in amplitude as the eyes-closed baseline Alpha waves that we recorded earlier.  This graph also confirms that the entrained waves are a bit stronger on the right side (channel 8, blue) versus the left (channel 7, green).  If you remember from above, his baseline eyes-closed alpha waves were the opposite -- they were stronger on the left.  Finally, perhaps most surprising of all is that there are no Alpha waves at all.  Remember, his eyes are closed just like before.  Yet, there are no Alpha waves.  The presence of the blinking light apparently suppresses his natural rhythms (the Alpha) and entrains a rhythm at its own blink rate (the 3.9 Hz signal).

Average EEG Amplitude Recorded With Eyes Closed and A Bright Light Blinking
Notice the Strong Peak at 3.9 Hz (the Blink Rate) and the Absence of Alpha Waves.

Finally, let's look at the spectral coherence across neighboring EEG channels.  The plot below shows strong coherence at these low frequencies (3.9 Hz) across all pairs of channels except for the 1/3 pair (front left) and the 2./4 pair (front right).  Why are these not coherent yet the others are?  I don't know.  The 1/3 pair and the 2/4 pair do have the largest physical spacing of any of the pairs, but I still find it surprising.  I mean, even the cross-hemisphere pairs of electrodes (the 1/2 pair in front and the 7/8 pair in back) show good coherence, but not these 1/3 and 2/4 pairs.  I'm not sure what it means (the front's response is independent of the whole rest of the brain?) but I'll be sure to keep an eye on the 1/3 and 2/4 coherence in the future to see if there is a trend.

Spectral Coherence Between Neighboring Electrodes During the Eyes-Closed Blinking Light Test.
Click to Zoom.

Conclusion:  OK, what have we learned?  We learned that my buddy looks pretty cool in that red EEG cap.  And we learned that his brain is a mysterious place that emanates lots of cool signals.  His willingness to be my guinea pig gave me lots of data from which I have made lots of nerdy graphs.    Here's what I learned from the graphs:

  • His eyes-closed alpha waves are similar to the others that I've measured
    • Similar frequency (~10 Hz)
    • Similar amplitude (~4 uV RMS)
    • Similar spatial distribution across the head (strongest in the back)
    • Similar coherence pattern (back-left and back-right, but not cross-hemisphere)
  • We successfully induced visual entrainment with the blinking light (3.9 Hz)
    • Similar amplitude as the eyes-closed Alpha waves (~4 uV RMS)
    • Entrained brain waves appear all over the head
    • Entrained brain waves are coherent everywhere except front-left and front-right
    • The blinking light suppressed the PDR Alpha response

But what does it all mean?  Does it mean that the sleep-modification app on his smartphone will do anything?  No, this data and analysis does not speak to that question at all.  The goal here was just to help me (us?) learn about sensory EEG entrainment in general, and about my friend's individual EEG response in particular.  Now, that we've done the easy thing and gotten a bit smarter, we can maybe move on toward the harder thing (auditory entrainment) to try to answer the question as to whether the sleep-modification brainwave app is doing anything.  Now I have a better idea of what to look for.

So, thanks for reading.  This is so fun!  (for me at least...)

Next Steps:  In this follow-on post, I use a computer screen instead of a blinky light.  I show that I can entrain brain waves at a variety of speeds.  This is the first step in making an entrainment-based BCI!

Follow-Up:  I used visual entrainment to control a six-legged walker...with my brain waves!

Saturday, January 18, 2014

EEG Electrode Adapter - Version 2

As many people are aware, many commercially-available EEG electrodes use an unusual connector called a "touch-proof" connector.  If your EEG system does not use these connectors, you need to either replace the connectors on the electrodes, or you need to make an adapter.  While it is a sensible choice to cut up your electrodes, I prefer to make an adapter.  My previous version of such an adapter worked really well, but it was a bit fragile.  So, I decided to try again.  I also decided to work with a friend of mine who's a little smarter about these kinds of things.  Here's what we came up with.

My Revised EEG Electrode Adapter ("V2") attached to an OpenBCI Board

Problems with the Previous Version:  The picture below shows my previous version of the adapter.  The good part was that the adapter was really small.  I liked that.  The bad part of this adapter (in addition to the fact that I never finished all of the connections) was that it was quite fragile. Specifically, the soldering of the wire to the female connector had no strain relief, which meant that mating the connector always threatened to break the wiring.  Another problem was that I was always confusing which electrode I had plugged into which input on the OpenBCI board.  I really needed to remake the adapter so that it was easier to see which were the "special" connections (SRB, Bias, and 8P) versus all of the "normal" connections (1N-8N).  These are the deficiencies that I focused on in this revision.

My First Attempt at an EEG Electrode Adapter ("V1")
Revised Approach:  With this iteration, my friend and I decided that it would be best if the female touch-proof connectors were mounted to some sort of rigid frame instead of merely being attached to the ends of the wires.  This would give the strain relief that we needed when mating and de-mating the connectors.  To address my other issue -- getting the connections confused -- I decided to use color-coded connectors, instead of just the black connectors in my first build.  Easy.  Ok, let's go!

Parts:  The parts are all the same as in the first build.  The female touch proof connectors are P/N 36145 from Plastics One.  The ribbon cable is just a set of female-female jumper wires from Adafruit (P/N 266).  This time, we also used a piece of scrap plastic channel that we had lying around, probably originally from McMaster-Carr.  And, as you'll see, I used a thin scrap piece of plastic sheet and a wide piece of shink tube, both from our generally pile of "goodies for a future project".  None of these pieces (except for the female touch-proof connectors) are particularly critical, so use what you have.

Assembly:  My buddy who came up with the idea of using the plastic U-channel as a mounting plate did all of the of the assembly.  He started with drilling a bunch of holes in the U-channel into which he pressed in the female connectors.

Touch-Proof Connectors Mated to the U-Channel -- For Strength!

He then took the purchased wires, pulled off (as a group) the number of wires that we needed and cut the existing connectors off one end.

Inexpensive Jumper Wires Used for My Wire Bundle

To keep the individual wires from splitting themselves off the ribbon, he reinforced the ribbon with a flat piece of plastic and a big piece of shrink tube.  Here's him preparing the items.  The red thing is the big shrink tube and the yellow-ish thing is the scrap bit of flat plastic that he'll use for the reinforcement.


Preparing the Shrink Tube (Red) and Scrap Plastic (Yellow)
to Reinforce the Wire Bundle

With the wire bundle prepared, he soldered the individual wires to the back of the touch proof connectors.  He used some normal size shrink tube to protect the individual solder joints on the back of the connectors.  Very nice.

Connecting the Individual Wires to the Back of the
Touch-Proof Connectors.

And that's all there is to it.  A picture of the completed unit is below.  You can also see it attached to an OpenBCI board at the top.  In the picture below, you can see how reinforcing the ribbon cable was an important feature for keeping the wire bundle from falling apart.

The Finished Adapter.

Pin-Out:  For anyone wondering why I used the unusual color scheme for the connectors, the idea is to clearly indicate that some of the electrodes have different functions.  So, if you use this adapter to connect to the OpenBCI V2 board as shown in the zoom'd picture below, or like the one at the top of this post, the order of the connections is this, from left to right:

   Red: Bias  (aka. driven ground)
   Blue: 8N  (the regular input for channel 8)
   Red: 8P  (the reference input for channel 8, if selected in software)
   Blue: 
       7N  (the regular input for channel 7)
       ...
       1N  (the regular input for channel 1)
   Red: SRB2  (the reference input for all channels)

Further Revisions:  After working with this revised piece for a bit, I found that there is still room for improvement.  For example, in connecting the adapter to the OpenBCI board, it is important to connect the wires in the right order.  The right order is shown below.  At first, I thought it was a good idea that I kept the individual female pin connectors on each wire of the adapter.  I thought that I'd like the freedom and fllexibility that this might provide.  I was wrong.  I should have swapped out the individual female pin connectors for a ganged female connector that would have kept them all in the right order all of the time.  I was wrong.  (So, to the EEG hacker that I'm handing this adapter off to, sorry for the annoyance!).

The Correct Order for the Individual Wires.

So that's the story of the hacking of this electrode adapter.  The real solution, of course, would be to have the connectors on the electrodes and on the EEG system (OpenBCI, in my case) be the same.   The easiest thing would be to put female touch proof connectors on the OpenBCI board.  But, the PCB-mount version are almost $2/each, even in quantity!  This is completely incompatible with the price of the OpenBCI board.  So, the next option would be to buy electrodes with a connector system that we could afford.  That would be a really nice solution to this problem of making kludge-y adapters.

Sunday, January 5, 2014

OpenBCI Driver in BrainBay

Recently, I got an email from Chris, the primary developer behind BrainBay.  He had seen my earlier post, where I'd found a way to get OpenBCI to send data to BrainBay for live visualization and processing.  I was able to make it work by forcing OpenBCI to mimic the data format used by OpenEEG.  Since OpenBCI is more capable than OpenEEG (OpenBCI has more channels and higher bit depth), fitting myself into the OpenEEG format was not an optimal solution.  Well, Chris saw an opportunity to remedy the situation, so he wrote an OpenBCI-specific driver for BrainBay.  Now, OpenBCI can send all 8 channels of data in full resolution to BrainBay!  Thanks, Chris!

Recording my ECG into BrainBay Using  the new OpenBCI-Specific Driver.
I'm holding the electrodes between my fingers.

Below is a screen shot of the BrainBay hardware setup screen using the new OpenBCI driver.  It's pretty straight-forward...select the COM port and select the baud rate for the communication and you're done.

Setup Screen in BrainBay for the New OpenBCI Driver
 Right now the driver assumes that you are using a 250 Hz sample rate (which is what OpenBCI's Arduino software defaults to), but if you tell OpenBCI to run faster, BrainBay lets you change that.  Simply go to BrainBay's "Options" menu and select "Application Settings".  There, you can change the sample rate to however you've configured your OpenBCI board.

Once Chris made this OpenBCI driver, we had to test it out to make sure that it worked.  Since Chris didn't have an OpenBCI board, he couldn't test it himself.  So, he'd point me to his GitHub, I'd download his latest version of BrainBay, and I'd test it for him.  An important part of testing is doing things repeatably.  So, I added a mode to the OpenBCI software where it would output simple test waveforms instead of the real EEG data. (It is true that the ADS1299 has a bunch of test signals built-in, but none let you do different waveforms per channel.  That's what I coded up for OpenBCI.)

Below is a screen shot of BrainBay after we got the OpenBCI driver all debugged.  The synthetic test waveforms that were being output by OpenBCI are the simple ramp waves shown below.  Once we finally got it to look like this, I was so happy!

Confirming Correct Operation in BrainBay via Synthetically Generated Data from My OpenBCI Board.

With basic operation confirmed, I wanted to test it with real biosignals.  So, I did what I always do as my first test...ECG.  As seen in the picture at the beginning of this post, I used a couple of really basic electrodes connected to an OpenBCI V1 board.  To get my ECG, I simply held those basic between by finger tips (I licked my finger tips to increase their conductivity).  Generally, this is a really bad way to do an ECG...the muscle artifact from actively holding the electrodes can swamp your signal.  But, with a very light tough, it can be good enough to prove that that the system is working.  And it was working.  A screen shot of my ECG is shown below.  This is a pretty decent looking ECG trace...it's got a nice little P-wave, a sharp R-wave, and a nice rounded T-wave.  Very fine.

Recording my ECG From OpenBCI Using the New Driver in BrainBay.  Looks good!

So, unlike my previous time posting about BrainBay, this latest recording is all at OpenBCI's native capabilities.  There was no dumbing it down to fit within OpenEEG's data format.  With Chris' latest version of BrainBay, you can now use all 8-channels that OpenBCI generates at OpenBCI's full 24-bit resolution.

Latest BrainBay on GitHub: https://github.com/ChrisVeigl/BrainBay

Thanks, Chris!

Thursday, January 2, 2014

Breathing Meditation - Alpha Coherence

In my previous post, I recorded EEG from a meditator and I saw that meditation seemed to lower the amplitude of his Alpha waves.  I think that it is interesting that I'm continuing to see objectively measurable changes in EEG in (apparent) response to meditating.  I'd like to dig in a little deeper, though.  In this post, I'd like to see how the Alpha waves in different parts of the head/brain relate to each other.  Are the Alpha waves synchronized ("coherent") across the head, or are they generated independently ("incoherent") in the different brain regions?  Also, does meditation have any effect on their synchronization or independence?  That's what I'm analyzing today.

Measuring Coherence:  I'm going to measure  the spectral coherence of the EEG signals to see which signals are synchronized with each other (if any).  Coherence is a comparison of two signals, so I'll be comparing pairs of EEG signals around the head.

Coherence Compares Amplitude and Phase:  Coherence looks at any changes in amplitude and in phase between the two signals.  For two signals whose amplitudes and phases change together, the coherence could reach up to a value of 1.0 (perfect coherence).  Or, if the amplitude and phase changes are completely independent, it is possible for the coherence to reach down to 0.0 (no coherence).

Coherence vs Frequency:  Coherence is computed in the frequency domain, which means that we can see which frequencies are coherent and which are not.  I'm most interested in what happens to this meditator's Alpha waves (which we saw were centered on 11.7 Hz), so I'll be mainly looking at the coherence around that frequency.

Baseline Coherence:  Let's start by looking at the coherence during the meditator's baseline recording.  This is when he was sitting with his eyes closed and relaxing -- but not meditating.  The figure below shows the coherence for different pairs of EEG electrodes around his head.  Blue is low coherence (0.0) and red is high coherence (1.0).  Again, I'm looking at the figures mostly around the Alpha waves (10-12 Hz).

Mean-Squared Coherence For EEG Signals Recorded with Eyes-Closed But Not Meditating.
Click to Enlarge.

Looking at his Alpha wave frequencies, I see that his Alpha are coherent on back-left side of his brain (between electrodes 5 and 7) and on the back-right side of his brain (between electrodes 6 and 8).  I think that it is interesting that the Alpha waves are not coherent between the left and right sides (between electrodes 7 and 8).  These three findings suggest that the back-left region of his brain is working as a unit (at these frequencies), that the back-right region of his brain is working as a unit, but that the left and right Alpha waves are being generated independently.  Again, this is when he is simply relaxing with his eyes closed.

Coherence While Meditating:  Below is a figure showing the results during meditation.  The color scale is the same as for the plots above for the baseline recording.  In this new figure, note the Alpha coherence on the back-right (electrodes 6 and 8) is still present but that the Alpha coherence on the back-left (electrodes 5 and 7) is now gone!  This suggests to me that the meditation has somehow decoupled the brain centers on the back-left of his brain.  Whoa.  Cool.

Mean-Squared Coherence For EEG Signals Recorded During Eyes-Closed Meditation.
Click to Enlarge.

Quantifying the Change in Coherence:  To make this change in coherence more clear, I collapsed these complicated spectrogram-like plots into a simple plot of coherence versus frequency.  The simpler plots are shown below.  This plot only includes data during the eyes-closed portion of each test.  Because we should really only look at the coherence at frequencies where there is appreciable signal energy (and we should ignore other frequencies), I've highlighted the region of the Alpha waves (the only signal that is consistently present during these recordings) by using thicker lines.

Comparing the Average Coherence Just When the Eyes Are Closed.
The thicker lines highlight the Alpha wave frequencies.
On the left, you see the average coherence when he was relaxing but not meditating.  On the right you see the average coherence when he was meditating.  Note that the red trace (the back-left of the head), clearly drops from a coherence of about 0.9 to a coherence of about 0.7.  Very clear.  Also, unnoticed before, the blue trace shows that the coherence between the left and right (electrodes 8 and 7) drops from about 0,7 down to about 0.5.  This plot clearly suggests that the back-left of the brain was acting more independently during meditation.

Discussion:  In the previous post, we saw Alpha waves throughout the back half of his head.  It would be easy to assume that we were seeing the same Alpha wave throughout the back of his head.  Today's analysis has shown that this is not the case.  When merely relaxing, the coherence measurement suggests that the back-left and the back-right parts of his brain are generating their own Alpha rhythms independently of each other.  When meditating, it looks like the back-left part of his brain further subdivides.  Why?  I don't know.  To what effect?  I don't know.  Is it a good thing or bad thing?  I don't know.  All I know is that it is really cool to be able to objectively measure changes in brain activity due to conscious control.

Next Steps:  I'm thinking that I now want to go back and measure the coherence of the signals that we recorded from the meditator at Maker Faire.  I'm pretty sure that my two meditators were using different meditative techniques, so it would be interesting to see if the changes in coherence are the same or different between the two meditators.  It would also be interesting to repeat these recordings to see if the changes are consistent between meditation sessions.  Finally, these coherence results simply show that the signals became more independent.  It doesn't actually tell me which specific properties of the signals (amplitude?  phase?) became different.  It would be cool to see which aspects of the signals changed due to meditation.  The brain sure is a dark and mysterious place!

Follow-Up: The coherence pattern seen above when not meditating has been confirmed in data from another non-meditating friend.

Monday, December 30, 2013

Breathing Meditation - Alpha Amplitude

It turns out that my previous post on EEG and meditation was surprisingly popular.  The post even got one of my friends interested enough that he, too, wanted to see what happened to his EEG signals while he was meditating.  So, we hooked him up to one of my OpenBCI boards and took some measurements!  Here's the story of what we found together.

My second willing meditator.
(And the blue cap returns!)

Goal:  My goal with these recordings is simply to see if meditation has a measurable effect (any effect) on one's EEG signals.  I'm trying understand if a particular form of mental activity (ie, meditation) can be measured objectively.

Setup:  For this set of recordings, we decided to go the Full Monty and bring out the blue EEG cap (see photo above).  This was the same cap as used with the previous meditator.  We got the cap as part of a kit that we bought from Biopac.  Our cap has lots of electrodes.  We chose to use the eight electrode locations shown below.  Our reference electrode was towards the front of the head along the centerline (near FPz/AFz) and our driven ground (aka "bias") was attached behind the right ear (right mastoid).  We used the electrode gel that came with the kit from Biopac.  For data logging software, we used the OpenBCI GUI that was written in Processing.

Electrode locations used for these recordings.
Fp1, Fp2, C3, C4, P7, P8, O1, O2.
Reference electrode was near Fpz.
Driven ground ("bias") was the right mastoid.

Two Test Scenarios:  My meditating friend performed two sets of recordings: one while meditating and one while simply relaxing.  The non-meditating data will act as a baseline against which we compare the meditating data.  Note that the two recordings were done in back-to-back sessions without removing the electrode cap.

Test Procedure:  Both session started with an initial period with his eyes opened followed a long period with his eyes closed.  It is during this eyes-closed period where he was either meditating, or he was simply relaxing but not meditating.  When he is meditating, my friend's meditation style is breathing meditation, where he focuses solely on his breathing and on his body's response to his breathing.

Example Results:  Example data from his baseline recording session is shown in the spectrogram below.  This data is from an electrode on the back of his head (channel 7, which is at O1).  In this figure, you can see that once he closes his eyes, he exhibits a strong EEG signal around 10-12 Hz, which is in the Alpha band.  This eyes-closed Alpha rhythm is a very typical EEG pattern.  In this recording, there is also a faint signal between 20-25 Hz, which is simply a harmonic of the fundamental 10-12 Hz Alpha wave.  Overall, this Alpha-dominated signal seems to be very consistent with most other eyes-closed data that we've recorded from other individuals (including myself).

Example EEG data recorded during the baseline (ie, not meditating) session.  This is from the back of his head.  The horizontal stripe of signal energy is around 10-12 Hz, which is in the Alpha band.  Alpha waves are indeed commonly seen when one's eyes are closed.

Full Baseline Results:  The plot above shows data from just from one location on the head.  The figure below, by contrast, shows all eight channels of EEG data that we recorded.  It gives a fuller picture of what is happening during the baseline (non-meditating) recording session.  Like in the single example above, the plot below shows that many of the electrodes pick up the steady Alpha rhythm when he closes his eyes.  You can see, though, that the Alpha rhythm is much stronger in the back of the head than in the front.  Since this eyes-closed "posterior dominant rhythm" originates in the now-idled visual cortex (which is the back of the brain), the fact that the Alpha waves are strongest in the back of the head and weakest in the front is exactly what we would expect to see.

EEG data recorded while relaxing but not meditating.  Notice that the Alpha waves (the horizontal stripe of energy in each plot) are strongest towards the back of the head.  Click on the figure to enlarge.

EEG Data While Meditating:  Now we get to the good stuff.  Now we turn our attention to the data recorded while my friend was meditating.  The figure below shows the data recorded while he was meditating.  The meditating began when he closed his eyes, so I've limited my examination just to the eyes-closed data.  Clearly, the dominant feature is that horizontal stripe of energy in the 10-12 Hz band representing the eyes-closed Alpha rhythm.  This is the same kind of signal that we saw when he was not meditating.  So, to first glance, meditating does not have an obvious effect on his brain waves.  For example, it did not make the Alpha waves disappear nor did it make any new signals appear.  If there are any changes due to meditating, the changes must be subtle.

EEG Data recorded while meditating by focusing on his breathing.  Alpha waves still dominate.  Click on the figure to enlarge.

Change in Alpha Amplitude:  Comparing these two figures more closely, one change that I do see is that the intensity of the Alpha waves appears to decrease when he is meditating.  Because this change in amplitude is difficult to see quantitatively in the spectrograms, I replotted the data as basic spectrum plots, as shown below.  In these new plots, I've included just the eyes-closed data.  These new plots clearly show that the dominant EEG energy is between 10-13 Hz, which are the Alpha waves.  We see that the Alpha waves in both the baseline and meditating recordings are centered around 11.72 Hz, so meditating did not change the speed of his Alpha waves.  We do see, however, that the amplitude of these Alpha waves are smaller when meditating.  In fact, we see that the amplitude is cut nearly in half (6.1 uVrms down to 3.6 uVrms).  That's a pretty big change!  While we cannot yet be sure that change was caused by the meditation (repeated tests would be necessary to confirm a cause and effect relationship), this data is highly intriguing and begs for additional recordings.  This is cool.

Amplitude of the EEG signals recorded  when his eyes were closed during the baseline test (left figure) and during the meditation test (right figure).  As can be seen, the strongest signals are between 10-13 Hz, which are Alpha waves.  His Alpha are centered on 11.72 Hz.  You can see that the amplitude of his Alpha decreases while he is meditating.

Comparison of Alpha to the Meditator at Maker Faire:  Looking at my previous post for the meditator at Maker Faire, we saw that the previous mediator had very different brain patterns than seen above.  First, the meditator at Maker Faire showed no Alpha waves at all.  None.  While most people do exhibit Alpha when the eyes are closed, eyes-closed Alpha is not universal.  So, it is possible that the meditator at Maker Faire is simply one of those individuals who does not exhibit eyes-closed Alpha.  Or, as an alternate conjecture, perhaps the act of meditation suppresses Alpha waves.  Perhaps our highly-experienced meditator at Maker Faire completely suppressed his Alpha response, whereas the novice meditator shown above only showed moderate suppression of his Alpha response.  Again, we have insufficient data to make any real conclusions, but this is very intriguing.

Comparison of Beta Waves to Meditator at Maker Faire:  Another key finding from the meditator at Maker Faire was that his meditation seemed to generate EEG activity in the 15-20 Hz band, which are the low-end Beta frequency range.  His generation of Beta waves is in contrast to the novice meditator shown here, who showed no change in Beta activity.  Perhaps the lack of Beta activity is due to his inexperience, or perhaps it is due to a difference in the type of meditation.  As discussed in the Travis paper linked previosuly, different types of meditation are known to correlate with different EEG responses just as different types of mental activity can generate activity in different EEG frequency bands.  So, perhaps the Maker Faire meditator was performing a "focused attention" style of meditation (which is associated with increased Beta) whereas today's meditator was more of an "open awareness" style  of meditation (which is not associated with Beta).  I am not properly educated in the different styles of meditation, so I really should not comment on this further.  Perhaps it would be best to get the individual meditators themselves to describe their own meditation style relative to the criteria defined in the Travis paper.  That would probably be the best approach.

Conclusions:  With only a single pair of recordings from a single individual from a single sitting, we cannot draw any solid conclusions.  What we can say is that we happened to see a decrease in the amplitude of the alpha waves in the back of the head during meditation.  If this change is actually due to the meditation, it shows that the meditation is indeed having measurable changes on brain activity.  I have no idea whether changing the amplitude of the Alpha rhythm is a good or bad thing...I just think that it is interesting that we can measure any change at all.  I would love to be able to confirm this finding or to see it in other people.

Next Steps:  This has been a very basic analysis of the EEG data that we recorded.  For example, in quantifying the amplitude of the Alpha waves, I simply looked at each EEG channel in isolation from the others.  Sure, I noted that the Alpha were strongest in the back, but I did not look at any more subtle changes with how the different channels correlate with each other.  It is possible that the act of meditation brings different regions of the brain into concert with each other.  Or, maybe meditation does the opposite and causes different regions of the brain to become decoupled from each other.  Either way, some sort of quantitative analysis of the correlation between the different EEG channels might expose additional changes in brain patterns due to meditation.  I would find this kind of change to be very interesting.   I don't know what it would mean, but I would find it interesting.  So, I guess that I'm saying that I am not yet done with this particular set of EEG data.  I will pursue some kind of cross-channel analysis in my next post.

Until then, thanks for reading!

Follow-Up: Here is the analysis of the cross-channel coherence.  Cool!
Follow-Up: The raw data is available as part of the OpenBCI repository on GitHub

Sunday, December 22, 2013

Live Spectrograms in Processing!

For any regular readers of this blog, you know that I really like to visualize EEG data using spectrograms.  Unfortunately, when using OpenBCI, none of our software has a spectrogram display.  As a result, all my spectrograms are made after the tests are done.  While this is OK, it's not as good as having a real-time spectrogram.  So, I finally took the time to modify the OpenBCI GUI to include a live spectrogram.

As an example of how useful a spectrogram can be, look at the data below.  The picture is a screenshot from my newly-modified OpenBCI Processing GUI.  It shows EEG data recorded from the back of my head (O1-Fz).  My eyes were closed for the entire recording.  The screenshot was taken live (in the OpenBCI GUIs, press "m" to take a screenshot)...this is what the GUI was showing while the data was actually being recorded.

Screenshot from the OpenBCI "Simpler" Processing GUI.
Note the newly-added spectrogram plot.
I was recording Alpha waves from the back of my head (O1-Fz).

What does this screenshot show?  It shows alpha waves.  Specifically, because my eyes were closed and because the electrode was on the back of my head, it is showing my posterior dominant rhythm.  Based on the traditional spectrum plot on the left, it appears that my alpha waves are ~9 Hz in this recording.  Looks fine.

Now look at the spectrogram on the right.  it shows the same alpha wave signal, but now you can also see that the amplitude of my alpha increases and decreases through time (the color oscillates between red and light blue).  It is not a steady signal.  I find this very interesting.  The ability to see in both time and in frequency *at the same time* is the beauty of a spectrogram.

As another example, the screenshot below shows some Mu waves.  Here, I put an electrode on the left side of my head (C3) and tried to relax enough to make some Mu waves.  Mu waves are really difficult for me. I cannot get long sustained Mu waves like I can do for Alpha waves.  Instead, I can only seem to get 2-3 second long bits of Mu wave (as seen below).

A short segment of Mu waves recorded from the side of my head (C3-Fz)

With the regular spectrum plot on the left, it is hard to tell how long my Mu waves are sustained.  Now that I have the spectrogram, I can better see how long I'm sustaining my Mu waves, which means that I have better feedback for practicing making Mu waves.  In this way, you could say that it's a tool for neurofeedback.

Since I think that spectrograms are so useful, I've pushed this modified version of the "Simpler" Processing GUI up to the OpenBCI GitHub (link below).  Note that the spectrogram is only in the "Simpler" version of the Processing GUI.  The "Simpler" Processing GUI is designed to visualize just one or two channels of EEG data instead of all 8 channels that OpenBCI allows.

OpenBCI Processing GitHub: https://github.com/OpenBCI/OpenBCI/tree/master/Processing_GUI

Being limited to one or two channels means that this GUI might also be useful for OpenEEG (which is a two channel device).  All I have to do is alter the routine that interprets the data from the OpenBCI board so that it instead knows how to interpret the data format used by OpenEEG.  That should be pretty easy.  Look for a future update!

Tuesday, December 17, 2013

EEG While Meditating

Way back in September, I was with the OpenBCI folks at Maker Faire NYC showing off our very first OpenBCI prototype.  I was there wearing my bright blue EEG cap doing live demos of my brain waves.  It was fun.  On day 2, however, there was a guy who came up and demanded (politely) that he wear the EEG cap.  Given how long it takes to setup the cap correctly (with all the EEG gel and whatnot), I tried to decline his request.  But he persisted.  He told me that he was a meditator and that he needed to know if anything was actually happening in his brain when he was meditating.  Wow, you got me hooked me.  Let's do it!

Non-Meditating:  First, just so we all recognize what a normal, messy EEG recording looks like, check out the graphs below.  These are spectrograms of EEG signals recorded from my head using OpenBCI V1 and an EEG cap with tin electrodes.  The top plot is from the front of my head (Fp1-Fz) and the bottom plot is from the back-left area of my head (I think that its actually T5-Fz).  Note that both signals are highly corrupted by low-frequency artifacts from blinking my eyes.  Otherwise note that, when my eyes are closed, I show a nice signal ~10 Hz in the back of my head.  This is the classic posterior dominant rhythm that occurs in the Alpha band.  Notice that, besides the alpha and besides the eye blink, there is not much structure anywhere else in plots...it mostly just looks like messy noise.  Fine.

My EEG With My Eyes Open and Closed (No Meditating).
The arrows point to alpha waves that are commonly seen when one's eyes are closed.

Meditating:  So, now we turn to the data from my meditating friend.  The spectrograms below show data that we recorded from him using the same OpenBCI board and the same blue EEG cap.  In these plots, my friend was already meditating by the time I started to record the data.  So, to the left of the vertical line, this is data when his eyes were closed and he was meditating.  To the right of the line, he was not meditating and his eyes were open and closed at various times.  I find this data to be quite impressive.  Notice that there is clearly a band of signal energy between 15-20 Hz while he is meditating.  In the second half of the data, where his eyes are closed, there is maybe some of that 15-20 Hz signal, but it isn't nearly as strong as during the meditation.  I think that it is very cool that we appear to be seeing a physical (well, electrical) effect in his brain due to meditation.  Additionally, note also that he shows no alpha waves (nothing around 10 Hz) when his eyes are closed.   Is the meditation suppressing his posterior dominant rhythm, or does he just not exhibit one?  I don't know, but it's cool.

EEG recorded from a meditator.  Left of the line, he is meditating.  Right of the line, he is not.
Notice the signal energy between 15-20 Hz (and the absence of alpha waves) when he is meditating.

What Does It All Mean?  I make no claims regarding meditation being good or bad.  I make no claims regarding EEG signal energy in the 15-20 Hz band being good or bad.  All I know is that we can measure changes in his brain waves and that they appear to be due to him meditating.  That's really cool to me.

More Learning:  Via email, I showed this data to with my meditating friend.  He sent me back an outstanding link that was a survey of different schools of meditation and their relationship to changes in measured EEG. If you're into that kind of thing, it makes for fascinating reading:

Travis, F., & Shear, J. "Focused attention, open monitoring and automatic self-transcending: Categories to organize meditations from Vedic, Buddhist and Chinese traditions." Consciousness and Cognition (2010)
http://www.koepnick.de/Three%20Typs%20of%20Meditation.pdf

Have any of you recorded your brain waves while meditating?  What did you find?  Let me know!

Follow-Up: I recorded another meditator.  Check out his data here!