EEG AD8232 Phase 1

by msuzuki777 in Circuits > Arduino

5789 Views, 26 Favorites, 0 Comments

EEG AD8232 Phase 1

EEG_AD8232.jpg

So I’ve been wanting to build an EEG, electroencephalogram, for a long time. This is mostly to study my sleep brainwaves:

https://www.instructables.com/id/Better-Sleep-1/

This was one of my earlier attempts:

https://www.instructables.com/id/Jedi-Force/

This was followed by several, so far unsuccessful MindFlex hacks, like this:

http://www.frontiernerds.com/brain-hack

Well, with the help of this Instructable and it’s author, lingib:

https://www.instructables.com/id/Wink-Detector/

I’ve built an EEG that seems to work.

Like the Wink Detector, it is built on the AD8232 ECG which is actually designed to monitor the heart. I bought my AD8232 from AliExpress. I modified my AD8232 like the Instructable.

Data

FirstOscope.jpg
PSD.jpg

Well, I kludged up a headband put some power to it and got some raw data. See picture.

And using some AD8232 software was able to get similar data to plot on the PC screen. Well, for most people, myself included, this waveform is not very useful.

So further research suggests that it would be more useful to display the brainwave frequencies.

Here is a good explanation of this:

https://choosemuse.com/blog/a-deep-dive-into-brain...

While researching this, I found my favorite article about EEGs a “Pocket Guide to EEG”:

https://imotions.com/blog/eeg/

To be able to look at brainwave frequencies, most people use FFT, Fast Fourier Transform. Now I won’t go into this because I don’t understand it that well but it basically converts the raw data (voltage) into frequencies or specifically which frequencies are the most prominent. Arduino has FFT libraries and I was able to get serial data like this:

Hz FFT

0.00 52552.75

0.78 22631.70

1.56 80.54

2.34 52.87

3.13 44.13

3.91 8.81

4.69 38.29

5.47 26.83

6.25 43.53

7.03 23.29

7.81 28.69

etc.

Well, again with my OLD brain, this serial streaming data isn’t very useful.

(You can plot the FFTs which will show you the peaks but it doesn’t indicate at which frequency they occur)

What I decided would be most useful is something like the next picture. This shows the peaks divided into the brainwave bands. Instead of trying to display it on a computer, I decided to display it on a TFT screen.

My EEG Hardware

M4_TFT.jpg
EEGAD8232Schematic.png
Adapter.jpg
Adapter1.jpg

AD8232 ECG (modified)

Custom Headband

Adafruit M4Express

https://www.adafruit.com/product/3857

Adafruit TFT FeatherWing 3.5” Touchscreen

https://www.adafruit.com/product/3651

I selected the M4 Express and TFT FeatherWing because I already had them setup for another project including an 18650 battery. But I think my software should work on any standard Arduino.

The schematic is basically three wires connecting the AD8232 to the M4 Express. The TFT FeatherWing has a place to plug in the M4 and there are two sets of female headers that connect to the M4 headers. So I built a little right angle header adapter to plug in to the associated pins, the other end connected to a cable for the AD8232.

By using a plug-in adapter, it's easier to use the FeatherWing for other projects.

Custom Headband

Headband2c.jpg
AD8232Connector.jpg
EarClips.jpg
Headband2.jpg
Headband2a.jpg
HeadbandClips1.jpg
HeadbandClips2.jpg
Headband2b.jpg

The AD8232 is modified per the above Wink Detector Instructable. I also unsoldered the six pin header and resoldered it on the top. This makes the bottom of the AD8232 fairly flat to attach to the headband.

TIP: The way I do this is to slide off the plastic insulator. Unsolder each pin separately and use a solder sucker to clean the hole. If the hole is hard to clear, I will re-drill it with a #8 drill bit.

The headband was made from a long strip of velcro(soft side), a piece of elastic (this came from a hacked Mindflex, a couple of pieces of heavy wire, the modified AD8232, an ear clip from the Mindflex and two silver ear clip bases purchases from AliExpress:

https://www.aliexpress.com/item/4000755978939.html...

Electrical: Solder a (red) wire to one of the ear clip bases, solder the other end to RA on the AD8232. Solder a (yellow)wire to the other ear clip base, solder the other end to LA on the AD8232. Solder the Mindflex ear clip to RL on the AD8232. The reason why I did not use one of the silver ear clips was that they are pretty hard for me to put on and take off.

The elastic strip already had loops on the end, plus I can adjust the length. I folded the ends of the velcro over to make loops and sewed them. For me the velcro length was 13”. I took some heavy gauge house wiring and bent into U shapes. These were stuck into the loops on the velcro and the elastic to make a headband.

The silver ear clips were clipped to the velcro so the flat base was inside(against the forehead). These were placed above the eyebrows. These ear clips don’t close very tightly so I put a piece of ‘hook’ velcro over each ear clip to hold in place (but can be repositioned).

I stuck a piece of adhesive hook velcro onto the back of the AD8232 and stuck it to the headband velcro.

The orange cable I’m using is too stiff and unwieldy but it does work. I have some ‘hopefully’ more flexible cable on order.

My EEG Sketch

Arduino-Logo.jpg
PSD.jpg
EEG_AD8232.jpg

Arduino Sketch is attached.

The sketch is based on Arduino FFT example FFT_03 using:

samples = 128

samplingFrequency = 100

This gives an FFT bin size of 0.78125Hz from 0 to 50Hz.

I tried to model my display based on this:

https://still-breathing.net/introducing-physiology...

The output is Power Spectral Density(PSD). I found this great article about PSD:

https://community.sw.siemens.com/s/article/what-is...

So I think my display is in ‘normalized’ PSD on a log scale.

As per lingib’s suggesting and this video

I modified this line of code:

vReal[i] = analogRead(CHANNEL);

to this:

vReal[i] = analogRead(CHANNEL)-512.0; //modified for zero balance

to help get rid of the large FFTs on the first few bins.

The display does not show that the frequency range is 0-50Hz. But the bands are color coded, Delta(0-4Hz), Theta(4-8Hz), Alpha(8-12Hz), Beta(12-30Hz) and Gamma(30Hz+ mine goes to 50Hz).

The vertical scale is from -2 to 8 (log10).

Downloads

Conclusions

EyesClosed.jpg
EyesOpen.jpg
40HzSpike.jpg

ProofOfConcept: I took two pictures, one with my eyes close and one with my eyes open. (First two pictures) The difference shows that it’s apparently reading brainwaves.

Finding: In the third picture you can see a big spike in the Gamma range. This happens to be at 40Hz. I discovered that if I disconnect the USB to the PC and run it on battery, this usually goes away.

CONCERNS:

I am still concerned about the usually present spike on the first few bins of Delta. I suspect they’re not real.

The AD8232 uses an Instrument amp to basically look at the difference between the RA and LA signals. I’m not sure this is the best way to do this.

I’ll probably try moving the ear clips around a bit to see if I can pick up a better signal.

I plan on doing some testing with binaural beats to see if I can see “brainwave entrainment”

https://en.wikipedia.org/wiki/Brainwave_entrainmen...

Eventually, may try to record my brainwaves during sleep. The TFT shield has a built in micro SD card reader (but no RTC).