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!


Thursday, December 12, 2013

OpenBCI on Kickstarter

My friends at OpenBCI have launched their Kickstarter!  If you are interested in a low-cost, hacker-friendly, EEG system, you might want to check it out.  I'm really excited for them.

Tuesday, December 3, 2013

Self-Noise of OpenBCI with More Data

After posting about my short-duration measurement of the self-noise of the OpenBCI board, there was a comment that discussed EEG applications where very low frequency signals were being used.  To understand the self-noise of the OpenBCI board at these low frequencies, I repeated my self-noise measurements, but used a much longer recording...one hour instead of ten seconds.  I also to the opportunity to measure the noise on five channels, not just one like before.  Here are my results.

Measuring Self-Noise of Five Channels of OpenBCI by
Jumpering Them All to Analog Ground
Setup:  The setup that I used was the same as before except that I jumpered the first five inputs to analog ground, instead of jumpering just the first channel.  Also, yesterday, I de-activated all of the channels except for the first one.  Since today's test used five channels, I kept the first five channels and only de-activated the last three.

Data Collected:  I recorded about an hour of data.  Near the end of the data, there was a spike that I could see in the graphs...I must of bumped the setup with my hand while I was doing other things.  So, I trimmed the data to remove the spike.  Overall, I was left with 3180 seconds of data.  The lowest possible frequency that could be represented in this data is about 1/3180 = 0.00031 Hz.  That is a very slow signal.

Results for One Channel:  After removing the DC offset (ie, the mean) of the entire 3180 second recording, and after lowpass filtering the data with a cutoff at 65 Hz, I get the histogram shown below.  This is for Channel 1.  As can be seen, it is a nice Gaussian shape, which is very smooth because of the huge number of data points in my 3180 second recording.  The standard deviation is 0.15 uV.  Since the standard deviation is the same as the RMS value (when the mean is removed), the RMS noise value for this channel for this recording was 0.15 uVrms.  This is very close to the 0.16 uVrms value that I recorded yesterday for the shorter 10 second recording.  This agreement makes me feel very good.

Histogram of 3180 Seconds of Noise Recorded from
OpenBCI with its Inputs Jumpered to Analog Ground.

Noise Spectrum:  To see how the noise level varies with frequency, we can plot the spectrum of the signal.  Since the recording is so long, the spectrum reaches down to very low frequencies.  For channel 1, I got the spectrum shown below.  As can be seen, it has two regimes: (A) a flat "white noise" region above 0.07 Hz and (B) a sloped "1/f Noise" region where the noise density increases as the frequency gets lower and lower.  This "1/f" behavior (the "f" is for "frequency") is very commonly seen when evaluating the low-frequency noise of analog amplifiers.  It is impressive that the 1/f noise doesn't begin until about 0.05 Hz.  As a result, even at a frequency of 0.001 Hz, the noise level is only about 0.3 uV/sqrt(Hz).  That seems pretty good to me.

Spectrum of Self-Noise Recorded from OpenBCI
with its Inputs Jumpered to Analog Ground.

60 Hz Noise:  What is a bit surprising in this spectrum is the sudden appearance of the 60 Hz noise (there was none seen in my data yesterday) and of a spike at 0.080 Hz.  I'm thinking that, because I now have 5 channels active instead of one, and because the 5 channels share the single SRB2 input as the reference for the differential amplifier, that the common-mode rejection capability of the differential amplifier is degraded because of the 5x leakage current through the common SRB2 components.  Any imbalance on the two legs of a differential input will degrade the common-mode rejection, and the datasheet for the ADS1299 warns of this behavior.  It looks like we're seeing it.  While it is unfortunate, the level of the 60 hz (and 0.080 Hz) is still quite low...it reads about 0.3 uV/sqrt(Hz).  Since the "sqrt(Hz)" part is confusing for sinewave-like signals, I zoomed in on the graph around 60 Hz and I saw that the bandwidth of the 60 Hz signal is about 0.01 Hz.  From this, I estimate that the RMS value of the 60 Hz signal is 0.3 uV/sqrt(Hz) * sqrt(0.01Hz) = 0.03 uVrms.  So, it is a very small signal and probably not much to be concerned about.

Comparison Across Five Channels:  Unlike yesterday, where I measured just one EEG channel, today I measured five.  I would have done all eight, but I didn't have enough jumper wires.  For the five channels of data, I made the same plots.  They are very similar to each other.  The white noise is flat and the 1/f noise is similarly sloped.  They all contain the 0.080 Hz and the 60 Hz spikes.  The only real difference is that the amplitude of the two spikes varies a bit from channel to channel.  That does not change my overall conclusion that the five channels are sufficiently similar.  For the 3180 sec recording, I've tabulated the RMS noise (up to 65 Hz) below:

  • Chan 1: Noise = 0.15 uVrms
  • Chan 2: Noise = 0.16 uVrms
  • Chan 3: Noise = 0.17 uVrms
  • Chan 4: Noise = 0.18 uVrms
  • Chan 5: Noise = 0.15 uVrms

Conclusion:  This longer, multi-channel recording that I performed today confirms the noise levels that I recorded yesterday.  Today's longer recording is also able to reveal the low-frequency noise behavior of the system, which transitions from white noise to 1/f Noise around 0.07 Hz.  At 0.001 Hz, the noise density is about 0.03 uV/sqrt(Hz).

Other EEG Systems:  While I think that these noise levels are pretty low, I still do not have any comparison data from other systems.  Does anyone know how they perform?

Monday, December 2, 2013

Self-Noise of OpenBCI

An important quality of any EEG system is its noise floor.  If an EEG system has a noise floor that is too high, the noise might mask the small EEG signals that you're trying to measure.  So, when working with an EEG system, it is important know that its noise floor is low enough.  I've been working with the OpenBCI system, but I don't know what it has for a self-noise level.  So, I decided to measure it.

Measuring the Self-Noise of the OpenBCI Board by
Shorting the Inputs to Analog Ground

Expected Noise Level:  The heart of the OpenBCI board is the Texas Instruments ADS1299, which is a "low-noise, 8-channel, 24-bit analog front-end for biopotential measurements". Its datasheet says that it has a self-noise of 1 uV over a bandwidth of 0.01 Hz to 70 Hz.  That 0.01 Hz value is a very low frequency and would require at least 100 seconds of data, if not several hundred seconds of data (to get a good average) to properly evaluate.  Since I don't care about signals down to 0.01 Hz, and since I want a faster test, I looked at the datasheet for other statements regarding its noise level.  The best value that I found was in the Table 4 in the data sheet, which I copied below for convenience.  A footnote on the table says the values are based on a recording of 1000 data points.  When running at 250 Hz, this means that their sample had 4 seconds of data and not the 100s of seconds of data needed to recreate the value reported for 0.01 Hz.  This is a shorter test.  Great.

Table 4 from the ADS1299 Data Sheet Showing Self-Noise for a Gain of 24.
For a sample rate of 250 Hz, the noise level is 0.14 uVrms for a 65 Hz bandwidth.
We run the ADS1299 at a sample rate of 250 Hz, so looking near the bottom of the table, we see that we should expect a noise level of 0.14 uVrms for a bandwidth of 65 Hz (presumably 0.25 Hz up to about 65 Hz).  To make sure that I'm interpretting this table correctly, I found Figure 3 in the datasheet (copied below), which shows a sample of noise recorded with a gain of 24 and a sample rate of 250 Hz.  Based on the amplitude of the noisy signal, I would say that this graph is consistent with the 0.14 uVrms value that we took from the table above.  That's good.  Now, let's do our own experiment to see if the self-noise of the OpenBCI board is at this low level.

Figure 3 from the ADS1299 Data Sheet Showing a Sample of Self Noise.
This picture is consistent with the 0.14 uVrms level given in the table.

How to Measure "Self Noise":  When evaluating the self-noise of a sensing device, what you want to measure is the amplitude of the signal that the device thinks that it sees, even when there is not "real" signal present.  If there is no real signal present, then anything that is present is noise.  One easy way to ensure that no real signal is present is to simply short the inputs to ground.  That's what we'll do.

Shorting the Input to Ground:  For the OpenBCI board, each input is actually a differential measurement between the input and the common reference labeled "SRB2".  So, as you can see in the picture above, I shorted "input 1" to "SRB2" with the yellow jumper wire, and then I shorted SRB2 to analog ground with the white jumper wire.

Other Hardware:  The OpenBCI board was mounted on an Arduino Uno.  It was plugged into a PC via USB.  The Arduino (and, therefore, the OpenBCI board) were being powered from USB.

Software Setup:  I configured the OpenBCI board for normal EEG data collection.  This means that it was using a sample rate of 250 Hz with a gain of 24.  All channels except for channel 1 were turned off.

Results:  I recorded 10 seconds of the digital values that were output by OpenBCI board via the Arduino.  After scaling the raw counts into volts (1 count = 0.022 uV), and after filtering the noise to a bandwidth of 0.1-65 Hz, I made the time-domain plot below, which mimics the plot above from the ADS1299 datasheet.  As can be seen, it looks very similar.  The RMS value is 0.16 uV, which is very close to the 0.14 uV reported in the data sheet.  Given that datasheet values are usually very hard to achieve in practice, I find the 0.16 uVrms value to be a remarkable result.

Noise Recorded from OpenBCI with its
Inputs Jumpered to Analog Ground.

Characteristics of the Noise:  In addition to the RMS value, it can also interesting to look at the histogram and spectral properties of the noise.  The histogram below is for the same sample of OpenBCI data shown above.  It appears to be Gaussian shaped, which is good because that is what is expected.  The spectrum shown below  is also good because the spectrum is generally flat all the way up to the Nyquist frequency for this sample rate (Nyquist = half the sample rate = 250 Hz / 2 = 125 Hz).  Looking in detail, the magnitude of the noise density appears to average about 0.02 uV/sqrt(Hz) for frequencies up to 65 Hz, which is also good because it is consistent with our RMS value being 0.16 uV (this is consistent because 0.16 uV / sqrt(65 Hz)  = 0.02 uV/sqrt(Hz)).  Good news all-around!

Histogram of 10 Seconds of Noise Recorded from OpenBCI with its
Inputs Jumpered to Analog Ground.
Spectrum of Self-Noise Recorded from OpenBCI with its
Inputs Jumpered to Analog Ground.
Conclusion:  Based on this single 10 second recording, the self-noise of channel 1 of my OpenBCI board is 0.16 uVrms over the bandwidth of 0.1 to 65 Hz.  This is consistent with the value reported in the datasheet for the ADS1299 (which was 0.14 uVrms), so I have confidence in the value that I measured.

Other EEG Systems:  This 0.16 uVrms value sounds pretty good to me, but I do not have much experience with other EEG systems.  How about you?  Do you know the noise level for other systems?  Can you share the values?  I'd love to build a table comparing the different systems!

Follow-UP:  Based on reader's comments, I've extended my measurements to go lower in frequency and to look across multiple channels.  Check out the results here!

Monday, November 18, 2013

OpenBCI Alpha Wave Detector

Part of what excites me so much about EEG hacking is the idea that maybe I can control things with just my mind.  Once you gain any experience at all with EEG signals, however, you realize just how hard a task that can be.  So, start simple.  Start with what's easy.  Build from there.  With EEG, "easy" are Alpha waves.  Alpha waves is nice a simple EEG waveform that shows up fairly strongly around 10 Hz.  It is a great target for making one's first brain controlled hack.  And I just did it myself...check it out!  It's completely computer-free and feels like magic!


Electronics Setup

For this hack, I used the parts shown in the picture below.  It's an OpenBCI board sitting on an Arduino Uno (the Uno is completely hidden in this photo under the white OpenBCI board), a cheap peizo buzzer, and a basic red LED.  I put a 330 ohm resistor in series with the LED and in series with the buzzer to limit the current (a practice recommended in all of the Arduino learning examples).  Because I wanted to be completely computer-free, the whole thing is powered by a 9V battery adapter.

OpenBCI plus Arduino Uno plus LED, Piezo Buzzer, and 9V Battery.

EEG Setup

This hack uses two off-the-shelf reusable EEG electrodes.  I plug them into my Open BCI board using the adapter cable that I made.  I placed the first electrode (the reference) on the top of my head, a little towards the front ("Fz").  I placed the second electrode on the back of my head, just above the bump on the back of the head (the "inion") and a little to my left (aka "O1").  I worked the electrodes under my hair and stuck them in place using ten20 conductive paste.  This time, I used the small jar of it instead of the tube...the jar is much easier to work with.

My setup, including the colorful homemade adapter cable for
attaching my two EEG electrodes.
Arduino Processing Software

Unlike all of my previous experience with EEG hacking, where a PC was involved for doing the signal processing, today I will be doing all of the EEG processing on the Arduino itself.  The Arduino is not a computational power house, so we have to be reasonable in our expectations when doing signal processing on the Arduino.

To detect Alpha waves in EEG signals, there are several things that you need to do:

  1. Filter to remove strong interfering signals (60 Hz and DC drift)
  2. Filter to focus on the frequencies of interest (in this case, Alpha are ~10 Hz)
  3. Decide if there is enough Alpha (and just Alpha) to activate the LED and buzzer

The full details of my signal processing chain is a long story that will get its own post.  The Arduino's limited bit depth (32-bits is the maximum data type) and limited speed with floating point operations means that you cannot use sharp filters.  Instead, you have to use relatively gentle filters such as "biquad" filters (which are a form of 2nd order IIR filter).  To generate the filter coefficients, I used code that I found here.

After doing my filtering, I then compute the RMS power of the signal.  I simply square the single, apply a low-pass filter (another biquad from the code above), and take the square root.  This gives you a running RMS estimate of the signal amplitude.  Because of my filtering, this gives me a running estimate of the Alpha amplitude.  I then light my LED and sound my buzzer based on the amount of Alpha energy.

Thinking Things to Action

So, with this setup, you've got yourself a self-contained device that responds to your brain waves.  It doesn't have to be just an LED or buzzer, either.  It could be a robotic arm swinging a sword (to fight off pirates, of course), or a cool flashing hat for dance parties, or an animatronic flower that blooms with your thoughts.  Or maybe you like the idea of getting this kind of neurofeedback to see what is happening when you meditate (change the filter from 10 Hz Alpha up to 20 Hz Beta).  Or, maybe you could use it simply for weirding-out your friends and co-workers...what with the strange wires coming out of your head and all.  There are so many possibilities.

To me, controlling things with your brain in this way seems a bit magical...but I made this thing myself, so I know that it's not magic...it's hacking!

Follow-Up: A long time has passed, but I think that I found the code for this hack.  This was prompted by folks on the OpenBCI forum trying to do it themselves!  Cool!

Follow-Up:  I extended this work to control a six-legged robot with my brain waves!

Tuesday, November 12, 2013

Measuring EOG with my EEG Setup

In a previous post, I discussed how you can use your EEG electronics to measure ECG to see the changing electrical potential in your body due to your heart beats.  In this post, I'm going to use my EEG electronics to measure EOG to see the changing electrical potential in your head due to eye motion.  "Eye artifact" is a commonly-seen type of corruption seen in EEG, so it is important to have a feeling for the effect of the eye when trying to study the brain.

Electrodes on my face to measure my EOG due to eye motion.
Setup

As you can see in the picture above, I used three electrodes: one above my eye, one below my eye, and one to the side of my eye.  I have no experience recording EOG, so I don't know what standard practice is.  This is just what I happened to try.

In my setup, the primary electrodes were the ones above and below my eye.  The electrode on the side was used only as my driven ground (or "bias" if that is your preferred language).  It turns out that this connection wasn't really necessary (EOG signals are very strong), so you might be able to omit it.

The electrodes themselves are reusable gold-plated electrodes commonly used in EEG.  Mine are similar to these.  I stuck them to my skin using standard Ten20 EEG paste.

I plugged these electrodes into my OpenBCI electronics using my new, homemade adapter cable.  My OpenBCI board was mounted to an Arduino Uno, which was pumping the data to my PC for logging and post-test analysis.


Results

Once I turned everything on and started collecting data, I found some really interesting things.  Again, I have no experience doing this, so I had no idea what to expect.  Below is a graph of the voltage recorded during a period of time where I was looking forward, I then turned my eyes to look upward (keeping my head itself fixed), and then returned my eyes to looking forward.  As you can see, the voltage clearly tracks the motion of my eye.  When my eye was "up", the voltage was up.  While that seems so sensible, it was not what I expected at all.

Voltage recorded between an electrode above my eye and an electrode below my eye.

What was I expecting?  Well, I do have some experience seeing muscle artfiact in EEG signals due to clenching my jaw.  Muscle artifact shows itself as a hashy, noisy, high-frequency signal.  Since it takes muscles to move your eye, I assumed that "eye artifact" would also be hashy and noisy.  I was wrong.   It is a low frequency signal that reflects the actual position of the eye...not the changing position of the eye.  Even a quick jump over to read about EOG on Wikipedia would have told me that.

To paraphrase Wiki, EOG measures the local effect of the electrical potential that always exists between the front and back of your retina.  So, changing the orientation of your eye changes the how much each electrode "sees" the positive side of the retina versus how much it sees the negative side of the retina.  Cool!

Zooming out on my data, let's look at a longer time span with more eye motion.  The plot below shows the EOG data recorded for a variety of eye positions...looking forward, looking up, and looking down.  As you can see, there is a clear relationship between the measured voltage and the eye position.  Clearly, this system could be used as an eye tracker to tell (roughly) where your eyes are looking.  I find this very exciting.

EOG data recorded for multiple eye positions.
Effect of Filtering

The signals shown above were plotted after filtering.  Whenever I present EEG/ECG/EOG data, I filter it to get rid of very high frequency noise and to get rid of drifting of the DC component of the signal.  For EEG, I often filter away the signal energy that is below 0.5 Hz.  Since I do not care about EEG signals this low, removing these low-frequency components makes the plots much easier to follow.  But, if you use these filter settings for EOG, you get a completely different type of EOG plot than the nice ones shown above.

My previous EOG plots were bandpass filtered to only include energy between 0.02 Hz and 50 Hz.  Below is a plot of the same EOG data, but using my typical EEG passband (0.5 Hz to 50 Hz).  Notice that the plot looks very different.

Same EOG data but filtered to remove low-frequency energy below 0.5 Hz.
In this plot, you basically only seen the moment of change from one eye position to the next.  So, if all you cared about whether the eye is *moving*, this filter setting is good.  But, if you want to know where the eye is pointing, this is the wrong filter setting...you really need to lower that low-frequency cutoff from the 0.5 Hz value down to something like the 0.02 Hz value that I showed in the previous graphs.

To be truthful, the graph above is what I first saw when looking at my EOG data.  This is the graph I saw because I was viewing the data using my usual EEG filters (0.5-50 Hz).  As a result, I thought EOG was only good for measuring eye motion.  It wasn't until I started exploring the data in greater detail (changing one's normal filter settings is a great way to explore the data) that I discovered the plots that I show at the top.  When I lowered my low-frequency cutoff to 0.02 Hz and got those plots, that's when I discovered that  EOG is really about measuring the change in DC potentials due to your eye position.  What a fun discovery!

Next Steps

So, that's my story of recording EOG with my EEG setup.  It was really fun.  My next step is to put electrodes to the sides of my eyes so measure side-to-side motion in addition to up-and-down motion.  Also, I might try my homemade electrodes to see how well they do.

The real challenge with EOG is to keep the electrodes stuck on your face as you move your head around.  One thing that I did try was to use my self-adhesive ECG electrodes.  These stuck great!  But, they sure did look silly...

ECG electrodes stick better, but look much more silly.
I think that I'll just stick with the small EEG electrodes.

Follow-Up: Want to get the data used in this post?  Try my github!

Making an EEG Electrode Adapter

My earlier post on making my own EEG electrodes was surprisingly popular.  Thanks, all!  But, for some folks, it might just be easier to purchase EEG electrodes off the shelf.  If you buy your electrodes, they're likely to come with connectors on the ends.  In order to use these electrodes with an OpenBCI board, you'll need to either cut the connectors off, or you'll need to make an adapter cable.  Since I tend to play with a variety of electrodes (both EEG and ECG) and since many types of electrodes use this same connector, I thought that it would be good to make an adapter.  This post is about how I made my adapter cable.  Here's what it looks like when I was done.



Parts

To make the adapter cable, you need the connectors that mate to the EEG electrode, you need some wires, and you need some connectors that mate to the OpenBCI board.

The OpenBCI board simply uses pin headers with a 0.1" spacing.  Therefore, for "connectors", you can use any of the inexpensive jumper wires that are used throughout the hobby world for connecting to Arduino.  For this adapter cable, you need female pin headers.  Adafruit sells a fine pack of 40 female/female jumper wires (P/N 266) for $6.95.  The 40 wires come with the connectors already attached.  The wires also come attached to each other as a ribbon cable, which is very convenient for keeping the cables in order.

Female/Female Jumper Wires from Adafruit
For the EEG electrodes, they usually use "touchproof" connectors.  This are simple singe-conductor connectors where the metal part is completely shrouded in plastic.  They are fairly standardized, though the diameter of the connection can vary between 1mm and 2mm.  All of my electrodes are 1.5mm.  The jacks that mate to these electrodes can be purchased from Plastics One.  Specially, I chose to buy the panel mount, front-loaded, threaded connectors (P/N 36145) shown in the pictures below.  When bought in small numbers, they're $3.14 each.  That's pricey!

Jacks for Touchproof Connectors.  From Plastics One.
Assembly

The OpenBCI board has 11 connections that I might want to use.  So, I took the ribbon of 40 jumper wires and peeled off a single strip that contained 11 wires.  I then cut it in half to that one end had the female pin headers and the other end was just wire.


Then, I peeled apart the ends of the wire and stripped the ends.  As I prepared to solder on the touchproof jack, I slipped a piece of shrink tube over the end of the wire so that I could make it look nice when I was done.  I'm proud of myself for remembering to do the shrink tube.  I nearly always forget.  Not this time!

Preparing to solder the first jack.

After I soldered it on, I pulled the shrink tube up over the joint, applied some heat, and got a nice looking connection.

First jack is attached.  Nice use of shrink tube!
I then repeated the process for all the other wires that I was going to use.  Here's a picture of me soldering on the second jack.

Preparing to solder the second jack.
Completion

For my immediate testing, I did not need all 11 connections...I only needed four.  So, I only soldered on four jacks.  You can see my "completed" adapter cable assembly below.

My adapter cable with 4 connections.  I'll add the others when I need them.
Note that I added a piece of electrical tape around the ribbon cable to help keep it together.  I had overly separated one of the individual wires and it was threatening to come loose.  I little electrical tape saved the day!  And it makes it look fancy.

Using It

As you can tell by the photo at the top of this post, the adapter cable works great for interfacing OpenBCI to off-the-shelf electrodes.  I've used it with my EEG electrodes for follow-on measurements of my Mu-waves and with my ECG electrodes for checking my heart signals.  It's a great adapter cable to have in my EEG Hacker toolbox!


Wednesday, November 6, 2013

Waveforms from Homemade Electrodes

As follow-up to my surprisingly popular post on my homemade electrodes, ERPOLOGY asked to see the EEG traces.  Well, since making graphs is one of my most favorite things to do (NERD ALERT!), I'm happy to oblige.

First, as a reminder of what I did, I built some EEG electrodes out of really cheap materials.  To see how well they worked, I stuck them to my head using Ten20 conductive paste in locations approximating Cz (top of head) and C3 (side of head).  The spectrogram above shows the data that I recorded.  As you can see, the test contains several test conditions:
  1. Closed Eyes (to see Alpha Waves)
  2. Open Eyes and Relaxed (to see Mu Waves)
  3. Open Eyes While Moving Hand (to suppress my Mu Waves)
Time-Domain Plots

OK, now let's make the new plots.  First, I've chosen short excerpts from each of the three periods.  I've plotted them below.  Note that these plots are zoomed way in so that you can count the period of the Alpha waves and of the Mu waves.

First, below, I show a trace from when my eyes were closed and I was generating Alpha Waves due to my Posterior Dominant Rhythm (PDR).  Remember, my electrodes were not on the back of my head -- they were on the side of my head.  So the PDR Alpha waves are not as pure looking as you might expect.  If you count the peaks, though, you'll see that there are about 9-10 cycles per second (ie, 9-10 Hz), which is what we saw in the spectrogram at the top.


Next, below, I show a trace from when my eyes were open and I was trying very hard to be relaxed (an oxymoron).  I was successful in generating some Mu waves.  They're shown below.  If you could the peaks, you'll get 10-12 waves per second (depending on how you count).  Based on the spectrogram, the frequency of my Mu waves is a little bit higher than my PDR Alpha waves.  This is probably confirmed by the peak-counting in the plot below.


The last time-domain plot, below, is for when I open and close my hand.  This should suppress my Mu waves.  In the spectrogram, they do appear to be absent.  In the plot below, they appear to be absent as well.  Good.



Frequency-Domain Plot

Before we finish, let's go back to the frequency domain...but let's plot a regular spectrum and not a spectrogram.  While the spectrogram is great for getting a sense of what is happening throughout the test, it is not the best tool for being quantitative.  Sometimes a simple spectrum plot is better.  

For the spectrum plot below, I took a long sample of each activity (10s of seconds, several thousand data points), I performed a series of 512-point FFTs and I averaged the FFT results together to get a nice, smooth spectrum for each condition.  By plotting the averaged spectrum for each condition all on the same graph, I can quantify the differences between the three conditions.  Here are the results:


As you can see, the Alpha waves were definitely at a lower frequency (9.3-9.8 Hz using my data reading cursor) than my Mu waves (11.7 Hz).  As I mentioned during the discussion of the time-domain plots, the spectrogram showed this fairly well.  But, a basic spectrum plot like this one makes it much easier to see and quantify the difference between the two.

Also, this graph implies that the Mu waves were about half the amplitude of the Alpha waves.  While it is true that Alpha are clearer in the spectrogram, which suggests that the Alpha were stronger, the primary reason that the Alpha were clearer is because I was able to sustain the Alpha waves more steadily than the Mu waves.  Detailed examination of the data shows that my Mu waves came and went every few seconds.  Therefore, in the averaged FFT plot, the apparent amplitude of the Mu waves will appear to be smaller simply because it includes all those short periods where the Mu waves temporarily went away.  That's a risk with using a heavily-averaged spectrum plot.  You gotta know your tool.

Finally, this spectrum plot nicely shows how clenching my hand (the red trace) suppresses the Mu waves completely.  Again, that was clear in the spectrogram, but this plot shows it very nicely as well.

Implications

With this extra detailed view of the data, you can start to see how you could design a signal processing chain to detect Mu waves.  Looking at the frequency plot, it is clear that you would need a really tight filter...maybe about 1 Hz wide.  For me, the filter would need to be centered on 11.7 Hz.  You might have your own special frequency.  Finally, because this plot shows that the energy in my PDR Alpha overlap with my Mu, you might want to sense the frequencies on either side of your Mu waves.  If there is energy on either side of Mu, then it's likely that the energy inside your Mu frequency band is from something else...such as PDR Alpha.

Without a graph like this, designing the signal processing would be much harder.  With this graph, I get all sorts of ideas.  This is why I like graphs so much...they can give quick insight into complex data.

If you've made it this far...thanks for reading!  You're awesome!

Follow-Up: Want to see my data from this experiment?  Check out my github!

Tuesday, November 5, 2013

Homemade Passive Electrodes

After the challenge of getting oneself some decent EEG electronics, the next hardest part is getting some decent EEG electrodes.  Sure, there are lots out there that can be bought, but some folks have no interest in paying $8-$20 per electrode (plus shipping) because they know that they need to buy 6-10 of these electrodes and, well, that becomes a lot of money.  So, I decided to try to build my own homemade EEG electrodes.  Here's my story...(and for you impatient folks...yes, there's a fairly happy ending)

Wearing my homemade passive EEG electrodes.
(Beware of cheap cameras and flourescent lights)

The Idea: Use Cheap Bits from the Hardware Drawer

When I look at passive EEG electrodes, I just see a piece of flat metal with a wire attached.  Sure, I see the use of fancy metals (gold, silver / silver-chloride), but is that really necessary?  For EEG research or EEG medicine, the quality and repeatability provided by the fancy metals is necessary.  For EEG Hacking?  I'm not so sure.  So, if an electrode is just a piece of flat metal with a wire attached, it seems like I should be able to build one myself.

I started by searching through my hardware drawer to find a suitable piece of metal that is small and flat.  I found some lock washers with a solder tab (see picture below-left).  It is a very basic and inexpensive component.  I'm pretty sure that mine are from Mouser and cost $0.24 each.  You can probably get them cheaper.



I then grabbed a piece of wire, stripped the end, and inserted it into the tab on the washer.  Looks like it'll do nicely (see picture above-right).  To soldered the wire to washer, I simply placed it in my plastic-gripped vice and applied heat and solder (pics below).  If you don't have a vice, a traditional "3rd hand" soldering fixture would have worked fine, too.  This is not fancy work that we're doing here.


Once the wire was soldered to the washer, I realized that I should have added a piece of shrink tube over the wire to cover the solder joint.  But, once it was soldered together, it was too late to add the shrink tube (the other end of my wire already had a connector on it).  Dang!  When I made a second electrode, I remembered to add the shrink tube on that one.  As you can see below, the black shrink tube makes the second electrode look much nicer than the first one.

My First and Second Homemade Passive Electrodes.  On the second one, I remembered to add a piece of shrink tube to cover the solder joint.  It looks much better.
With the working end of the electrode complete, I could consider the other end of the wire...the end where normally on would add a connector for plugging into the EEG electronics.  Since I stole my wire from an old ECG lead wire, I have the "touchproof" connectors on the end of my electrodes.  But, you don't need anything that fancy if you want to spend less money.

The least expensive approach for "connectors" would be to solder on a male or female pin header, which are only about $0.04 per connection.  This kind of connection is perfect for connecting to OpenBCI, which is built around traditional 0.1" spaced pin headers.  So, if you put the mating gender of pin header on your homemade electrodes, they could plug right into the OpenBCI board.  Great!  Alternatively, if you use OpenEEG, you will want to terminate your electrode's wire with a 3.5 mm stereo phono plug.   That is what the OpenEEG is built around.  These pieces about $0.50 each.

So, overall, I estimate that cost of each one of these electrodes is: $0.24 for the washer, about $0.36 for a meter of stranded wire (it's more flexible than solid wire), and $0.50 for a 3.5mm connector.  That's $1.10 in parts, which is a nice reduction compared to commercially available electrodes linked at the top of this post.

But do my homemade electrodes work?

Homemade Electrodes for ECG

As discussed in my previous post, I always like to start my testing by doing ECG measurements.  Because the heart signals are so strong, it is an easy way to confirm that your EEG system (and EEG electrodes) are working to some degree.  So, I got out my tube of Ten20 conductive paste and stuck my electrode to my wrist.  I attached one electrode to my left wrist and the other electrode to my right wrist.

Attaching my homemade electrodes to my wrists to measure my ECG.
The shiny stuff on my skin is Ten20 conductive paste

 How well did they stick?  Well, not nearly as well as the self-adhesive disposable ECG electrodes.  But, the surface area on those sticky ECG electrodes is HUGE, so of course my little electrodes won't stick as well.  Given how small my electrodes were, though, I think that they adhered adequately well.  I think that the big hole in the middle of the washer is not helpful.  If it were solid, I think that these electrodes would stick better.  I'll remember that when I go to make my next set of homemade electrodes.

Once I got the electrodes attached to my wrists, I connected plugged them into my OpenBCI board and had the Arduino pipe the data to my computer, as usual.  Example ECG data from these electrodes is shown below.  I'm showing 6 heart beats.  As you can see, the sharp R-waves and the broad T-waves are both very clear.  The amplitude of the ECG is similar to what I showed in my post yesterday when I used real ECG electrodes.  So, while my signal trace does look a bit noisier than yesterday, I'd say that this is a successful test!

My ECG As Recorded through OpenBCI Using my Homemade Electrodes

Homemade Electrodes for EEG

Since I was successful with the ECG, I made the next step and used my homemade electrodes to acquire some EEG signals.  I am still pretty fixated on my Mu waves, so I decided to use my electrodes to see if I could pick up my Mu waves.

Following a simplified version of my previous procedure, I put one electrode near the top of my head near Cz and one the left side of my head near C3.  As you can see in the photo, it is very tricky to accurately place electrodes on one's own head.  In retrospect, it looks like the one on the top of my head was a bit too far forward for Cz and the one on the side of my head was a bit too far back and a bit too low for C3.  Regardless, they should be good enough to record *something*, so let's see what I got.


Placing my homemade electrodes near
Cz (top of head) and near C3 (side of head).

Using my OpenBCI electronics, I started recording data from my brain.  I spent some time with my eyes closed to generate Alpha waves (Posterior Dominant Rhythm), I spent some time with my eyes open and my right arm and hand relaxed (to hopefully generate Mu waves), and I spent some time with my eyes open and my right hand clenching and un-clenching.  The results are plotted below as a spectrogram.  Unfortunately, it is not very clear where the boundaries were between these different activities, so it is not clear what we *should* be seeing.  We do clearly see the Alpha waves caused by my eyes being closed.  In the middle of the plot, we might also see some Mu waves, but they are very weak.  I would say that these results are fine for Alpha and bad for Mu.


To try to get better results, I moved the homemade electrode that was on the side of my head.  I moved it a little higher to be closer to where C3 is supposed to be.  Then, I repeated my recordings.  This time, I pressed a button on my computer to mark the boundary between each activities to make my post-test analysis easier.  It turns out that the simple act of pressing the button caused my EEG wires to jiggle, which shows up as artifacts within the data.  It makes it clear when I shifted my activity.  See the results below.


As before, the Alpha waves are quite clear.  This time, though, I do think that I see Mu waves during those periods when my eyes were open and my hand and arm were relaxed.  Then, when I moved my hand, I think that I see that the Mu waves go away.  That's exactly what should happen!  At the end, when I relax again, I think that it is interesting that it takes a while for my Mu waves to come back.  Clearly, I am not very good at relaxing.  That's not much of a surprise to me.  I can be quite excitable...especially when I'm EEG HACKING!

Homemade Electrodes Seem to be Good!

So, with this second test, I'm quite pleased with my homemade electrodes.  The signals that I recorded were pretty good.  There was a lot of 60 Hz noise (not shown in these graphs) but that could be due to me not using the traditional 3rd electrode connection (variously named the "bias" or "driven ground" or "driven right leg") for these recordings.  I also felt that these electrodes did not stick to my head as securely as the gold electrodes that I used previously.  I think that the stickiness can be improved by using a piece of metal with more surface area...maybe a regular flat washer instead of the skinny lock washer.  Still, for about a dollar per electrode, I think that the results are pretty darned good.  I'm pleased.

How about you...have you made your own electrodes before?  How did you do it?  Did they work?


Follow-Up: More graphs and discussion of the data is in this post
Follow-Up: Want to see my data from this experiment?  Check out my github!