Showing posts with label Coherence. Show all posts
Showing posts with label Coherence. Show all posts

Tuesday, April 29, 2014

Concentration - Birds Beat the Internet

Now I'm getting serious.  In my last post, I finally saw for myself what "concentration" looks like in my EEG signals.  And now I'm totally hooked.  Now I want to expand my goals.  How?  Well, let's see how my concentration varies during natural activities, not just during my synthetic concentration exercise.  Where to start?  Well, how about at breakfast?  For me, breakfast includes some eating, some Internet, some bird watching...good stuff!  I hoped that my new EEG metric for "concentration" might reveal some interesting trends about my brain while breakfasting.  And, as you'll see, I was not disappointed...

Today's Breakfast Attire...Electrodes on the Forehead and Ear Lobes.

Goal:  My goal was to record some EEG signals to see how my concentration varies with different natural activities.  Today, I recorded EEG while breakfasting.

Setup:  My setup for recording my EEG was similar to the previous post -- a gold electrode on the forehead, a gold electrode on my left ear lobe as reference, and a ear clip electrode on my right ear as bias.  Today, I also added a second gold electrode to my forehead (Chan 1 is my left, Chan 2 is might right).  The picture above shows their locations.  To keep the wires out of my face (important for eating), I looped the electrode wires over my ears.  I connected the electrodes to my OpenBCI V2 board (shown below) and recorded the data using my GUI in Processing.  My electrode impedances measured about 20 kOhm.

My Usual Connection to my OpenBCI Board.  Confusingly, my electrode breakout
is mislabeled..."SRB1" is actually SRB2.

Procedure:  Since I wanted to record natural activities, I did not define a rigid test procedure prior to the test.  Without a scripted procedure, it's really tough to know what you did (and exactly *when* you did it) during a long test such as this.  To address this problem, I setup my camera to record a video of the whole test.  That video is my "truth".  In the movie (some example frames are below), I saw that I spent some time setting up the electrodes, some time eating my food, some time on the Internet (reading and writing), some time gazing out the window at the birds (my favorite part), and some time doing more work on the Internet.  Finally, at the end, I did my regular EEG concentration test -- counting backwards by 3 from 100.  I've got all this as one long EEG record.

I used my camera to record a movie of me eating breakfast.  I used this
as a record of "truth" to see what activity caused what EEG signal.

Data, The Quick Overview:  The EEG spectrogram below is the whole data record as seen my the electrode on the left side of my forehead.  As you can see, there's a block of activity at the beginning (up to 240-300 sec).  This is what was recorded while I was attaching the electrodes to my head.  After that, there's a block of activity from 300-650 sec with some really crazy signals, followed by a long block with more typical EEG signals.  What was happening during that crazy time?

The Complete EEG Record During Breakfast.  Chewing is clearly a very
intense signal that masks all true EEG activity.

Chewing Destroys EEG Signals:  By aligning the EEG data with the movie, it is clear that this period from 300-650 seconds is when I was eating my breakfast.  That morning, breakfast was some wheat Chex and grapefruit juice.  Pretty exciting?  No?  Well, the EEG signals sure are exciting.  See all that strong broadband red activity?  That's the effect that chewing has on EEG.  Dramatic!  I don't know if the cause is muscle artifact or if it is the jiggling of the electrode wires (or both), but the signals are huge!  If you zoom in (not shown), you can see each individual chew.  So, if you wanted a "CCI" (a Chew-Computer Interface) in addition to a "BCI" (Brain-Computer Interface), an EEG system would be a great way to do it.  But, if you wanted to see brainwaves while eating (like I was hoping to see), the act of chewing will basically destroy your data.

The Rest of My Data:  After eating, I still had another 20 minutes (1200 sec) of EEG data, so it wasn't too sad that chewing destroyed the early part of my data.  The spectrogram below zooms in on just the data after my chewing.  This looks like a more normal EEG recording.  Below the spectrogram, I show some processed results.  Specifically, I show the magnitude of the EEG signal in just the 22-100 Hz band, which was chosen based on the "count backwards by 3" experiment in my previous post.  So, if "counting backwards by 3" is considered "concentration", then this blue line is a measure of concentration.  At least, it is a measure of one type of concentration.  In the figure, note that my concentration level does seem to change in response to my different activities.  I find this to be very cool.

Zooming in on the activity after my chewing.  The top plot is the spectrogram of the data.
The bottom plot shows the magnitude of the portion of the EEG in the 22-100 Hz band.

Birds are Better than the Internet:  Looking at the graph above, you can see that my concentration level starts pretty low while I'm working on the Internet.  Surprisingly, the movie shows that I'm not passively reading.  No, it shows that I am actively engaged (mostly typing a reply regarding a theremin).  Given this engagement, I would have expected my concentration to be strong.  Nope.  Compare this to the next section of time, where I'm simply gazing out the window at the birds and trees.  My apparent concentration level (or, at least, my EEG activity in the 22-100 Hz band) gets noticeably higher.  Wow!  Then, when I return to my Internet work, it drops strongly.  I guess that birds are more stimulating than the Internet!  Go birds!

Stronger Concentration Today:  At the end of this test, I closed my eyes and relaxed, which caused my the EEG signal level to drop, as expected.  Then, I opened my eyes and did my concentration exercise where I count backwards by 3.  This portion of my test repeats what I did in my previous post.  In today's recording, however, my signal levels were much higher.  As shown in the plot below, today's data shows 2.8 uV with my eyes closed and 7.6 uV while counting backwards.  Compare this to the previous post where I showed only 2.0 uV and 3.4 uV, respectively.  So, I was 3.4 uV and now I'm 7.6 uV.  This means that my "concentration" intensity is nearly twice as strong!  Why?  Was it because this data was from the morning, when I was fresher and could maybe concentrate "stronger"?  I don't know.  I do find it interesting, though.

Quantifying the EEG Signal Level During the Different Periods.

Summary So Far:  Even with just this simplistic analysis, the data has been way more surprising than I would have guessed.  I would have thought that breakfast would have been a little boring...I mean, I'm just sitting there.  But this data has been surprisingly rich.  Three things have surprised me:
  1. Chewing makes huge signals as seen by an EEG system
  2. Birds and trees stimulate my brain* more than the Internet
  3. My peak concentration level* can change a lot day-to-day
(* In both cases, "my brain" and "concentration level" really just mean "my EEG signals in the 22-100 Hz band".  But it sounds a lot less exciting when said that way.)

One More Thing...:  At this point, I figured that I was done.  I mean, three new findings is certainly enough excitement for me.  But then I remembered that I had data from the 2nd electrode that was on my forehead.  We already looked at the data from the left electrode (spectrogram repeated below).  What did the data from the right electrode show?  Its data as shown as the 2nd spectrogram below, though it's not particularly exciting by itself...it shares many of the signatures seen in the first electrode.  The excitement comes when I examine the "coherence" of the signals between these two electrodes.  The coherence as a function of time and frequency is shown in the third plot.  It looks pretty boring, except right there at the end.  What is happening there?

Measuring the Coherence Between the Left and Right Electrodes on my Forehead.
For the "concentration" signals prior to counting backwards, the signals are
not coherent.  For the counting backwards, they are coherent.  Why?!?
What is Coherence?:  Coherence is a measure of how two signals move together -- if one signal gets stronger, does the other get stronger, too?  If one gets weaker, does the other get weaker at the same time?  Signals that move together have a high coherence (ie, a value near 1.0).  Signals that do not move together have low coherence (near 0.0).  I've analyzed the coherence a couple of times before, such as in this earlier post.

Today's Coherence Data:  For today's data, the coherence plot above shows a few interesting features.  First, in the lower frequencies (10 Hz and below), this plot shows that the signals from the two electrodes on my forehead exhibit high coherence (the plot has a lot of red).  OK.  Above 10 Hz, though, the signals from these two electrodes are not coherent (blue).  Fine.  At then end, though, while I'm counting backwards, these higher frequency EEG signals suddenly become coherent (red). Whoa!  What happened?!?

Counting Backward Must be Different:  If "concentration" is reflected as activity in the 22-100 Hz band, this coherence plot suggests that my "concentration" is different at the end compared to the rest of the test. It appears that the Internet and the gazing outdoors both induce independent (ie, not coherent) activity in the left and right sides of my forehead.  Then, at the end, it appears that my counting exercise causes synchronized (ie, coherent) activity on both sides of my forehead.  Counting backwards must require different brain activity than the concentration associated with the Interent and birds.  While this sounds obvious, these objectively-recorded EEG signals are saying the same thing.  I think that's amazing.

Next Steps:  I've discovered many features in this single recording that get me really excited.  Before I get too excited, I should repeat the experiment.  If these phenomena appear again (especially the finding regarding the coherence), I would feel a lot more confident that it is true.  At that point, I would be really interested in seeing if something similar happens in other people.  If so, perhaps its a known phenomenon discussed in the literature.  Perhaps there is a known cause and a description of the brain mechanism(s) in action.  I'm interested to know!

Follow-Up:  Interested in getting the EEG data from this post?  Try downloading it from my github!

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!

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.