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!

Tuesday, April 22, 2014

Detecting Concentration

A couple of weeks ago, Sparkfun's new product post was all about the Neurosky Mindwave.  What really grabbed my attention was Nick Poole's video of his hack of using the Mindwave to bend a spoon.  That was a really fun and creative way to use EEG to interact with the physical world.  What also grabbed my attention was that it was yet another example of consumer EEG system saying that it detects "concentration", as if it were a well-known and well-defined EEG signature.  Along with terms like "focus" and "relaxation", I always felt that a word like "concentration" was too amorphous for serious consideration.  I mean, what exactly do "concentration" brain waves look like?  What is the signature?  I don't know.  But, given the coolness of Nick's demo, I decided to do some EEG Hacking to find out!

Neurosky Mindwave Electrode Setup:  I don't own a Neurosky Mindwave so I can't use that hardware to explore these "concentration" brain waves.  But, I do have an OpenBCI system, and it's pretty flexible, so I'll try that instead.  The main question is how to setup the electrodes.  Looking at the videos for the Mindwave, and looking at the Sparkfun hack pages, the Mindwave appears to use an electrode on the forehead and then another on an ear clip.  I'm assuming that the one on the ear clip is the reference electrode.  It does not appear to use a bias electrode, probably because they found that it was not needed for this body-mounted, battery-powered system.

OpenBCI Electrode Setup:  To mimic the Mindwave setup, I put a gold cup electrode on my forehead  and another on my left ear lobe.  The one on my forehead was plugged into Channel 1 of my OpenBCI board and the one on my ear lobe was used as the reference.  Because my system is not battery powered, I did use a bias electrode, which was an ear clip electrode placed on my right ear lobe (this is the first time I've tried the ear clip electrodes).  I also chose to stick another gold cup electrode on the back of my head, just to see what happened back there during this experiment.  Oh, and to attach my electrodes, I used standard Ten20 conductive paste.  My impedance check showed about 30 kOhm for each electrode, so not too bad.

Using OpenBCI (V2), 3 gold cup electrodes, and one ear clip.
Oh, and some guy's brain, too.

Procedure:  Watching Nick's video, he says that he is able to trigger the Mindwave's concentration detector by mentally counting backwards by 3, starting from 100.  This sounds pretty straight-forward and he clearly had good success with it.  Frankly, I was a little more skeptical about my own ability to make it happen.  So, in my data, to make it clear to me where I was trying to concentrate, I closed my eyes for a short period before and after my mental counting.  I did this because, by closing my eyes, I would generate strong alpha waves (10 Hz) that would clearly show up in the data.  As a result, after the test, I could look for the data between the two alpha wave recordings...this would be the period when I was concentrating.  Let's see what I got.

My First Look at the Data:  The spectrogram below shows how I typically look at an EEG recording for the first time.  Note that frequency is on the vertical axis and time is on the horizontal axis.  You can definitely see the signature of the alpha waves (that horizontal stripe around 10 Hz) at the beginning and at the end of my recording.  In the middle is the period of time when I was concentrating.  In this plot, I don't see anything interesting during the concentration portion of the test.  I just see some "noise" that looks little different from everything around it.  Bummer.

You can definitely see the alpha waves from my eyes being closed.  Good.
But, is anything happening during concentration?

Higher Frequencies?  But then I remembered reading somewhere (like in one of my own early posts?) that "concentration" was usually seen as increased activity in the higher EEG frequencies -- the so-called Beta waves (13-30 Hz).  So, I replotted the data where, this time, I zoomed way out on the frequency axis.  As you can see below, I'm now showing zero to 100 Hz.  In this new plot, you can clearly see that there is more EEG activity when I was concentrating compared to when I was not.  Now we're getting somewhere!

By zooming out to see the higher frequencies, it does look like there are more activity
in the high frequencies (20-100 Hz) when I am concentrating.  Cool!  (Note: the dark
horizontal stripe in the middle is the effect of my 60 Hz notch filter.)

Comparing the Spectra:  While spectrograms like the one above are helpful for quick qualitative views of both time and frequency, it is difficult to be quantitative with a spectrogram.  So, in the plot below, I show the average spectrum for a period of strong concentration (t = 90-130 sec) and I show the average spectrum for a period where my eyes were closed and my mind was especially quiet (t = 155-178 sec).  As can be seen below, the two spectra are definitely different, especially for frequencies above 22 Hz.

Comparing the average frequency spectrum with my eyes closed (t=90-130 sec)
to the average spectrum while concentrating (t=155-178 sec).  Note that
above 22 Hz, concentration exhibits more signal energy.

Detecting Concentration:  With the knowledge that, in my brain, "concentration" starts to show itself as increased EEG energy above 22 Hz, I can now contemplate building a concentration detector.  The key is to filter my EEG data so that I can assess the intensity of EEG activity in frequencies above 22 Hz.  Then, I'd pick a threshold to which I can compare the EEG intensity level.  If my EEG signals are stronger than my threshold, my detector would say that I am concentrating.  If I'm weaker than the threshold, my detector would say that I am not concentrating.  Sounds pretty easy, right?

Applying to My Recorded Data:  In the figure below, I apply this idea to the data that we've been discussing.  The top plot is the same spectrogram that I showed below.  The bottom plot is what happens when I filter the EEG data to show the intensity just for frequencies between 22 and 100 Hz.  You can see, the trace does indeed move up and down to reflect whether I'm concentrating or not.  Specifically, for the sustained concentration (t = 90-130 sec), my filtered EEG signal is running about 3.4 uVrms.  Then, when I close my eyes and relax (after t = 140 sec), my EEG signals drop down to about 2.0 uVrms.  So, if I were to define a threshold for detecting concentration, I might put it somewhere in the middle...say, around 2,7 uVrms.

Measuring the EEG amplitude in the 22-100 Hz frequency band.  Note how it is low while
my eyes are closed and that it goes higher while concentrating.

Feeling Some Success:  The plot above is making me pretty excited.  It suggests that I have conscious control over my EEG signals.  To date, I've only had strong success with controlling my Alpha waves (by opening and closing my eyes).  I've also had some small success with Mu waves, but they're really hard for me to get.  So, seeing this concentration-induced Beta (13-30 Hz) and Gamma (30-100 Hz) is pretty darned exciting.

Criticism: A critic reading this post might argue that I have not proven any link to concentration.  A critic might say that the increased high frequency EEG energy could just be a natural result of opening my eyes.  Based on the data shown so far, that would be a fair criticism.

Gathering More Eyes-Open Data:  To counter this criticism, the data below is from another test that I performed using the same setup.  In this test, I performed a similar procedure where I started with my eyes closed, had a period with my eyes open, and then finished with my eyes closed.  Unlike the previous test, though, I did not do my concentration exercise during the eyes-open period.  As a result, we should be able to see whether the increased high-frequency EEG activity is due to concentration or due to simply having my eyes open.

A second EEG test where I was NOT purposely concentrating during the eyes-open portion of the test.  Note that the EEG intensity is much less intense than seen during my previous test where I was purposely concentrating.

Not Concentrating:  In the plot above, you can see that there is a trend in my EEG signal strength, but that it is not related to the opening of my eyes.  At the beginning, when my eyes were closed, my high-frequency EEG signals were pretty low at 1.9 uVrms.  Then, when I opened my eyes (t = 210 sec), my EEG intensity increase only slightly to 2.0 uVrms and stayed that way for quite a while.  I think that this is strong evidence that simply opening your eyes does not specifically trigger increased Beta and Gamma activity.

Wandering Mind:  In the second half of my eyes-open period, we do see that my EEG intensity drifts upward.  Eventually, it averages about 2.5 uVrms.  Perhaps this increase reflects that I got bored and started thinking about my next EEG test.  Regardless of the reason, you'll note that even the increase to 2.5 uVrms still does not exceed the 2.7 uVrms threshold that we set a couple of paragraphs ago.  So, this small increase does not meet our criteria for "concentration".

Conclusion:  I think that this second data set is good evidence to declare that intense (>2.7 uVrms) Beta and Gamma activity is not due simply to opening my eyes.  I am feeling pretty confident that the intense high frequency EEG activity seen in the first data set is due to my concentration.  This means that Beta and Gamma activity is under my conscious control, which is the most exciting EEG result that I've had in a long time.

Next Steps:  Being under conscious control means that I could potentially use "concentration" as part of a brain-computer interface for future hacks.  I'm always looking for ways that I can try to control things in the physical world using just my brain waves.  Perhaps with some practice, I could use this technique to compete with Nick Poole in a spoon-bending competition!

Follow-Up:  I recorded my concentration level while eating breakfast, and found some really cool changes!
Follow-Up:  Interested in getting the data from this post?  Try downloading it from my github!

Friday, April 11, 2014

Impedance of Electrodes on my Head

Following from my previous post on figuring out how to get OpenBCI to measure the electrode-to-skin impedance, I figured that now is the time to actually measure the impedance of real electrodes on my actual skin.  I decided to try two types of electrodes: (1) disposable ECG electrodes and (2) re-usable gold cup EEG electrodes.  Here's the story of what I found...

On the left, I'm trying ECG electrodes.  On the right, I'm trying
gold cup EEG electrodes.  In both cases, I'm looking pretty sharp.

Disposable ECG Electrodes:  First, I decided to try some disposable ECG electrodes.  These are cheap and really easy to use.  They're not very good for using in your hair, but they're great for sticking on your forehead.  For the reference and bias connections, I used an ECG electrode on the mastoid bone behind each of my ears.  The picture below shows the pre-gelled, self-adhesive ECG electrodes that I used along with the clip-type ECG electrode wires (see this post for specific recommendations).

ECG Electrodes and Clip Leads That I Used on my Head

Once I stuck three of these electrodes on my head (forehead and behind each ear), I connected the lead wires to my OpenBCI V1 board using my homemade adapter.

Connecting the ECG Leads to my OpenBCI V1 Board.

After getting all connected, I activated the ADS1299's "Lead Off" excitation signal for the channel that was connected to the ECG electrode on my forehead.  As discussed in my previous post, the excitation signal is a 6 nA AC current source that the ADS1299 toggles at 31.2 Hz.  The flow of current through the electrode creates a voltage that can be measured by OpenBCI just like a normal EEG signal.  I configured my OpenBCI board to digitize the data and send it to the PC.  On the PC, I used the OpenBCI GUI to view the data in real time and to record it for post-test analysis.

A zoomed-in plot of the recorded waveform is shown on the left of the figure below.  As you can see, it has a fairly large amplitude of 508 uVrms.  This corresponds to an impedance of 120 kOhm.  That's really big!  Being surprised by that large value, I swapped the wires around so that I was measuring the electrode that I had been using as my reference (or "-") electrode.  As seen in the waveform above on the right, I got a very similar value.  That's not cool.

Example Waveforms Recorded While Using OpenBCI To Measure the
Electrode-to-Skin Impedance of (Left) the ECG Electrode on my
Forehead and (Right) the ECG Electrode behind my Left Ear.

Zooming out so that you can see more of my recording, the figure below shows about a minute's worth of data.  This is the full recording from which I made the excerpts shown above.  The longer view below shows the story of me recording data for one electrode (up to about t = 119), of how the signal goes away as I unplug and swap the electrode connections (from t = 120 to t = 132), and then how the signal returns once I am connected to the other electrode.  Again, you can see that I measured 120K from one electrode and 116K from the other electrode.

Zoomed-Out View of my Recordings Using the "Lead-Off Detection" Excitation
while Using Disposable ECG electrodes.

Gold Cup EEG Electrodes:  Because I found the impedance of the ECG electrodes to be surprisingly high, I tried using some gold cup EEG electrodes.  The picture below shows the electrodes and the conductive electrode paste that I used.  Like with the ECG electrodes, I put one of these on my forehead, one on the bone behind my left ear for the EEG reference and one one the bone behind my right ear as the EEG bias.

Gold Cup EEG Electrodes and Ten20 Brand EEG Paste

After putting on the electrodes, I activated the "Lead Off" excitation, like before.  Some examples waveforms from the data that I recorded are shown below.  As expected, the waveform shape is the same as seen before, but the amplitude is different, which reflects the fact that the impedance of the electrode-to-skin interface is different.

Waveforms Recorded from the Gold Cup Electrodes During the "Lead Off" Excitation.

Notice that the three plots show decreasing amplitude, which means that I was getting better contact and less impedance in each case.  What was happening?

Well, for the first waveform (the one on the left) was shows what I measured when I first attached the electrodes.  It shows an RMS amplitude of 389 uV, which corresponds to an impedance of approximately 92 kOhm.  This was still higher than I wanted, so I fiddled with the electrode and pushed it into my skin to try to make better contact.  That's when I got the middle graph -- 230 uV and 54 kOhm.  Finally, I pulled off the electrode, replaced the conductive paste, and really pressed and twisted the electrode against my skin.  That's when I got the graph on the right -- 64 uV, which corresponds to 15 kOhm.  That is more like the kind of value that I was hoping to see.

Below is a zoomed-out plot of the whole scenario with the gold cup electrode.  Again, this is the full record from which I made the excerpts above.  On the left side of the plot, you can see the 389 uV, 92 kOhm condition that I showed before.  Then, you can see my multiple attempts at re-seating and re-pasting the electrode.  Finally, at the end, I finally got to the 64 uV /  15 kOhm condition.  So, while it does take some effort, it is possible to improve the electrical contact between the electrode and your skin.

Zoomed-Out View of my Recordings Using the "Lead-Off Detection" Excitation
while Using the Gold Cup EEG Electrodes

Why Were the ECG Electrodes So Bad?  This experiment started with the ECG electrodes, which yielded a very high impedance of 120 kOhm.  If I could only use the ECG electrodes, this high impedance value would have prompted me to remove the electrode, to scrub the skin (hard!) with alcohol and a rough pad, and then to attach a new electrode.  Maybe this would have worked to lower the impedance, or maybe not.  If it would not have helped, the problem could be that my ECG electrodes are really old.  If you look really closely at my picture showing the electrodes, you'll see that the ECG packet in the background shows a date of "June 2012".  Yikes!  I have a friend who is developing a hacker-friendly EMG system (go FlexVolt!) who has mentioned to me that he has seen difficulty when using old ECG electrodes.  So, I'm thinking that maybe disposable electrodes have a limited shelf life...and that 2 years is maybe too old.

Next Steps:  With the impedance monitoring working on my OpenBCI board, I'm hoping that it will enable me to make more reliable EEG recordings. Hopefully, getting good low-impedance connections will increase my chances of detecting those low-level signals that have vexed me with their sometimes-I-see-them and sometimes-I-don't behavior.  In particular, I'm thinking about those pesky Mu waves that have been hard for me!  We'll see if this impedance checking can help...

Thanks for reading!

Follow-Up: Want to get the data from this post?  Try downloading it from my github!

Thursday, April 10, 2014

OpenBCI: Measuring Electrode Impedance

An important driver of EEG signal quality is how well the electrodes are electrically connected to the skin.  Common clinical and research guidance often says to use skin cleansing and skin abrasion to get the electrode-to-skin impedance down below 10 kOhm or even 5 kOhm.  If you don't, you can get noisy or unrepeatable measurements.  Most EEG systems allow you to measure the impedance at each electrode.  The OpenBCI system that I have been helping to develop is also capable of doing this (see other's work on using the ADS1299 to measure impedance) but I have not taken the time to figure out how to use it.  Until now...

Measuring Electrode Impedance Using the ADS1299's "Lead Off" 6nA Current Source

Impedance from Voltage and Current:
  The main idea with measuring the impedance of the electrode-to-skin interface is for the EEG system to inject a known current through the electrode and to measure the resulting voltage difference.  Since V = I*R, you can easily compute impedance "R" by taking the measured voltage "V" and dividing by the known current "I".  Pretty easy, right?  Well, how do you inject the current?  And how do you measure the voltage across the electrode-to-skin interface?

Injecting the Known Current:  The core of the OpenBCI board is the ADS1299 integrated circuit from Texas Instruments.  It has a feature called "Lead Off Detection" that does this trick of injecting a known current into each electrode.  As you can see in the figure above, a very small current (shown as 6 nA) is forced into the electrode line by a current source built into the ADS1299.  So, no matter how much resistance or impedance is between the current source and ground (within reason, of course), the system forces 6 nA through the electrode to ground.

What is Ground?  Unless you are sitting in salt water or touching something big and metal, it is unlikely that your body is connected to ground.  To address this, an EEG system often provides an extra connection in addition to the regular electrodes.  This extra connection is usually called something like "bias", or "driven ground", or "driven right leg (DRL)".  The purpose of this connection is to keep your body's DC voltage level within an acceptable range and to keep any common-mode AC signals in your body minimized.  Therefore, the bias line will act to source or sink whatever current as necessary (within reason) to minimize your DC and common-mode AC signals.  As a result, for the 6nA current that we are injecting, "ground" is the bias driver, as shown in the figure above.

Making a Mental Model of Where the Current Goes

Measuring Just the Electrode-to-Skin Voltage:   If the bias driver is our ground, the figure shows one way to model where the current goes.  Note that the current passes through several unknown impedances on its way to ground.   How do we evaluate just the impedance of the "+" electrode's interface to the skin?  The answer is to remember that an EEG system measures the voltage between its "+" input and its reference (or "-") input.  Because of the high-input impedance of the differential amplifier, no current flows into the "-" electrode line, so none of its impedance elements matter (for the purpose of this measurement).  Therefore, we can easily measure just the voltage drop across the first three elements -- the 5K in-series resistor, the electrode-to-skin impedance, and the impedance of a portion of the human body.  Because the series resistor is known, and because the impedance of the body is too small to matter, we have only one unknown remaining -- the impedance of the electrode-to-skin interface.

Calculating the Impedance:  The model above shows the electrode-to-skin interface as a simple resistor.  While this is not quite right (it does have a capacitive component as well), we can use this model to roughly estimate the number we need.  Following from the basic V = I*R, we shuffle the terms to get R = V/I.  We know both "V" (the measured voltage drop) and "I" (the known 6 nA current), so we easily get "R".  The only trick is to make sure that you're using compatible units for voltage and current.  In my case, I'm measuring the voltage as an *RMS* value (not an amplitude value).  My current value (6 nA), however, is an amplitude value, not an rms value.  So, to make the units compatible my calculation must includes a factor of sqrt(2) to convert RMS into amplitude:

R = (Measured Voltage * sqrt(2))/(Known Current) 

Finally, remember that the "R" here is the the series resistance of the electrode-to-skin interface plus the 5K resistor built into the OpenBCI board.  So, to get the impedance of just the electrode-to-skin interface, you need to subtract 5K.

Testing on OpenBCI:  To confirm that this all works in real life and not just on paper (or, um, just on a blog page), I used one of my OpenBCI boards to test it out and confirm that it works.  The simplest test that I could devise was to use clip leads (see picture below) to jump together the electrode connectors.  Specifically, I connected four of the "+" electrode connectors to the single reference (ie,"-") electrode connector, which is then jumped to the bias electrode connector.  This configuration eliminates all of the electrode-to-skin impedances and the human body impedances.  The only impedances remaining are the 5K series resistors.  Hopefully, when I do my voltage measurements and divide by the 6 nA current, I'll get a number close to 5K.

Testing the Impedance Measurements on an OpenBCI V1 Board.
The colored wires are directly connecting  (ie, shorting) the electrodes
to the reference electrode and to the bias electrode.

Configuring for the Test:  Because I only had a few clip leads, I could only jumper four of the eight "+" electrode connectors.  As a result, when I ran OpenBCI, I only activated channels 1-4.  I configured the "Lead-Off Detection" settings to generate a 6 nA current source at a frequency of 31.2 Hz.  I then started to activate the current sources on the "P" side of each EEG channel.  I saw that I could activate and deactivate the signal on any given channel without affecting the signals seen on the other channels.  Excellent.

Screenshot of the OpenBCI GUI when running an impedance test on channels 1-4.  Click to zoom.
Note that ~31 Hz test signal is present in the first four channels
and that the resulting per-channel impedance is 5.4-5.8 kOhm.

Results:  With all four current sources active, I got the results seen in the screenshot above.  As you can see (click to enlarge), a 31 Hz signal is present in the first four channels.  You can see this in the time-domain montage on the right and in the frequency spectrum plot in the bottom-left.  On the time-domain plot, you can see that my labels indicate that the voltage induced on each EEG channel is between 23.0 uVrms and 24.5 uVrms.  Using my equation from a few paragraphs back, this yields impedance estimates of 5.43 to 5.77 kOhm.  Since I'm expecting to see the resistance of each channel's 5 kOhm resistor, this corresponds to an error of 9-15%.  Given that the ADS1299 datasheet says that the "known" current is only known to +/- 20%, I find my result to be very satisfying.  I'm feeling pretty happy right now.

Super-Advanced Topics:  With the method described above, you can measure electrode-to-skin impedance of the electrodes attached to the "P" inputs of this system.  The question remains on how to measure the impedance of the reference electrode (which is attached to the "N" inputs) and of the bias electrode.  The short answer for the reference electrode is that you can use the similar ADS1299 feature for the "N" channel (as long as you do not use SRB1 as a cheater way to mux the REF to all of the "N" inputs, which is what we do in OpenBCI V1).  And the short answer for the bias electrode is that the ADS1299 can detect if it is attached, but it cannot measure its impedance.  Luckily, the impedance of the bias electrode is not as relevant.

Overall Success:  So, I'm feeling pretty good about getting this impedance measuring to work.  The code for implementing this has been pushed to the OpenBCI GitHub.  The next step is do do some impedance measurements using actual electrodes on my actual head.  Look for a follow-up post!

Follow-Up:  I measured the impedance using disposable ECG electrodes as well as re-usable gold cup EEG electrodes.  You can see the results here:

Follow-Up: I linked this post to answer a question on the Texas Instruments user forums (regarding the Texas Instruments ADS1299 chip at the heart of OpenBCI).  This post was recognized by TI for a TI Community Award, Aug 2015.  Thanks, TI!