The concentration of each wave can also tell more specific things about your thought patterns depending on where you measure them from. For example, alpha concentrations on the left motor cortex increase when you think about moving your right hand. Regardless of where you're taking measurements, looking at the concentrations of waves in real time - a process called biofeedback - can give you much greater control over them.
This tutorial is an in-depth guide on how to make your own simple EEG circuit. Along with monitoring brain wave concentration, the final circuit can also be used as an ECG, as a way to see your heartbeat trace. The circuit will use 3 electrodes - 2 to measure a voltage difference across your scalp, and one as a reference to ground. Depending on how many parts you already have, the circuit could only set you back around $10.
The aim for this project is to be easily available and understood by people of every technology background. For those electronically savvy, I will include up front a finalized schematic so you can jump right into making it yourself. For those that want more guidance, I will include a detailed description / explanation of every section of the circuit, showing you what it does and why you need it.
Then, I'll move onto the software (Processing based), which is a very important piece in actually interpreting the raw data you receive.
So - let's start!
Step 1: Parts
- 1x Instrumentation Amplifier - AD620AN - This is the most expensive, and most important part. While technically you can make your own instrumentation amplifier from 3 op-amps, I could never get my own to give me good results. Precision cut resistors in this ensure that it'll do its job.
- 2x Quad Op-Amp - TL084CN - Any Op-Amp will do. You need 5 single amps, this one just includes 4 in each chip.
I would strongly suggest buying a capacitor bundle from ebay or the like, espcecially if you plan on ever doing some other sort of electronic project. One bundle and you're basically set for life. Regardless, whether you buy them in a pack or individually, make sure to include these capacitors :
- 1x 10 nF, ceramic
- 1x 20 nF, ceramic
- 1x 100nF, tantalum
- 5x 220nF, tantalum
- 1x 1uF, electrolytic
- 2x 10uF, electrolytic
Same as capacitors, I suggest a bundle. This is a very good one, has all the values you need (minus the potentiometer). The individual values you'll need, though, are:
- 1x 1kΩ Potentiometer - via Digikey - very useful to adjust your gain on the fly.
- 2x 12Ω
- 1x 220Ω
- 1x 560Ω
- 2x 22kΩ
- 1x 47kΩ
- 2x 100kΩ
- 2x 180kΩ
- 1x 220kΩ
- 2x 270kΩ
- 1x 1MΩ
- A breadboard to wire everything on. This one is large enough, and comes with useful jumper wires. I suggest saving the jumper wires specifically for connecting the various stages of the design. This will make it very modular, and easy to reorganize/reorder if you end up needing to.
- Wires for everything else. I like that pack, since it's pre-cut and keeps your board tidy. You can also get plain wire and cut it yourself.
- 3.5mm audio cable.
- 2x 9V batteries for power.
- Ambu Neuroline Cups seem to be the most cost-effective method, found here. Thanks to user jonencar for the link in the comments.
- electrode gel
Step 2: Complete Design
Regarding power: the easiest way to power the circuit is with 2 9V batteries. To feed your op-amps -9V to 9V of power, connect one battery the correct way, and one backwards. That is, connect the positive lead of one battery to your positive power supply line and its negative lead to GND (ground). With the other battery, connect its positive lead to GND, and its negative lead to the negative power supply line. To "set" GND, you will eventually connect an electrode from your leg directly to the GND line. This will ensure that "0V" is your leg's voltage (unaffected by any head activity), and that all readings will vary from there.
The biggest design goal for this circuit is to obtain the data, then reduce noise by enough to get a good signal into the computer, where we will process the data a bit more. As we will be using our computer's sound card to get the data in, we have to cut noise enough that the signal with noise does not spike above or below +1V and -1V, as this is the point where the sound card clips the data off. As we will be using +-9V through batteries to power the circuit, we also have to make sure that as our data is going through the circuit, it never peaks above or below this value.
I've also included an example of how to lay out the components on a breadboard, one with notes on it and one without. It isn't exactly how I did it, but should give you a general idea if you haven't worked with breadboards before. Still, I do NOT suggest using that picture as a strict guide on how to wire everything. Follow the actual schematic -- the breadboard layout looks like a pretty jarbled mess (it gets really hard to avoid that when you try to fit everything on a 30-column board). The program also didn't always layer the components correctly, and since there's no way to test the "breadboard schematic", there's a possibility that it's not perfect. Use it as a general guideline, if you need it.
To clarify some specific colors used on the breadboard view -- all red wires are power lines, and all black are basic interconnections between circuit pieces (most are connections to ground). The green wire is the output of the first notch filter, the yellow is the output of the 8 Hz HPF, the blue is the output of the 30 Hz LPF, and the white wire is the output of the gain stage. The box at the bottom represents the audio cable going to the sound card.
In general, things to remember are that in breadboards the power lines (top and bottom rows) are connected horizontally, and the rest is connected vertically, with breaks in connections across the middle gap. When looking at the schematic, take care not to connect wires together unless a black circle is there with the connections - a cross without a dot doesn't indicate a connection.
Step 3: Stage 1 - Instrumentation Amplifier
Using an instrumentation amplifier chip, the gain is changed by altering the value of the resistor between pin 1 and 8.
The datasheet for the AD620AN (our instrumentation amplifier) is here. From it, you can see that the formula for gain using this chip is G = 1 + 49,400 / Rg, which equates to a gain of 89.2 with a 560 ohm resistor. This is a good number to get the data into a not-miniscule range; we'll add a way to adjust gain on the fly a bit later. You should also see on this datasheet that on your actual circuit, your active electrodes (ones that are not the ground electrode) will be connected to pin 2 and 3 (-IN and +IN).
Step 4: Stage 2 - 60 Hz Notch Filter
The notch filter is most sensitive to changes in the 12 ohm resistor. To ensure the notch is centered at 60Hz, take a reading (detailed on the last stage) at the end of the instrumentation amplifier, then do so again once the signal has gone through the notch filter. You should see a significant reduction in the amplitude of the 60Hz (light grey) frequency band. If it is not centered at 60Hz, try a 10 ohm resistor, or even a different 12ohm one, as at that resistance it can easily vary by a considerable amount.
Step 5: Stage 3 - 7Hz High Pass Filter
This filter is a 2-pole HPF with a cutoff frequency of 7.23Hz. A cutoff frequency of 7.23Hz means that at this frequency, the circuit outputs data that is reduced to about 71% of its original value. As it is a high pass filter, frequencies above this cutoff will approach a gain of 1, while frequencies below will be continually reduced. The filter having 2 poles means that in the region below the cutoff frequency, the gain falls off much faster than a simpler resistor/capacitor circuit. More specifically, in this circuit, our double pole design reduces data by a factor of about 56 by the time it gets to 1Hz, while a single pole would only reduce it by a factor of about 7.5.
Along with the circuit design, I've also included the frequency response of this particular section.
Step 6: Stage 4 - 31Hz Low Pass Filter
Again, I've included the frequency response of this section here.
Step 7: Stage 5 - 1 Hz HPF and Gain of 83-455
The main purpose of this section, however, lies below this, with the 220Ω resistor and potentiometer (pot for short). This op-amp is a non-inverting amplifier, and so has a gain of G = 1 + R12/(R13+R14), (ignoring the 10nF capacitor, as it's a small value and won't contribute much to the gain). The potentiometer is a variable resistor - when the input is connected to the first pin and the output to the second, turning the wiper changes its resistance linearly between 0 and 1000 ohms. This means that when the pot is turned all the way to the left, the gain of this circuit is G = 1 + R12/(R13 + 0) = 1 + 100k/(220 + 0) = 455. When it is turned all the way to the right, the gain is G = 1 + R12/(R13 + 1000) = 1 + 100k/(220 + 1k) = 83.
Remember, this 83-455 gain is on top of the 89.2x gain from the instrumentation amplifier. Alpha wave amplitude varies from person to person, from about 10 to 30 uV. Using a middle value of 20 uV, this means the ending voltage reading could range from 83*89.2*20e-6 = .148V to 455*89.2*20e-6 = .81172V. Once you've started taking readings, adjust the potentiometer such that when you're not moving at all, voltages don't fluctuate offscreen (over 1V). It doesn't have to be maximized such that the amplitude is the highest possible without clipping - just know that if you make it too small, you'll increase the error incurred from digitally reading the data into the computer.
Step 8: Stage 6 - Another 60Hz Notch Filter (and Into the Computer!)
To get the data into the computer, we will be using a 3.5mm male-to-male cable (this is the same size ending as any headphone jack). On the cable, the first 2 notches are the right and left channels, and the one furthest down is GND. As shown in the picture, you should connect the end of the cable between the 22k resistor and 220nF capacitor (the yellow alligator clip), and the base of the cable to the GND line of your circuit -- the same line you connected your GND electrode to (the red alligator clip in the image). I suggest connecting the other end of these alligator clips to jumper wires, inserting these into their appropriate place in the circuit. Connect the other end of the cable into the microphone port of your computer, and you're good to go!
Now, onto the electrode setup and code.
Step 9: Getting Electrodes, and Proper Placement
There are many possible electrode placements - which one you choose will depend on a mix of convenience and what you wish to measure. For a trial demonstration, we will measure alpha waves originating from the occipital lobe. This is because these waves are the easiest to produce, are quite large in amplitude, and only require 1 electrode on a section of the scalp with hair.
Parts of your head you'll need to know for this are the mastoid, nasion, and inion. The mastoid is the bone behind your ear: you can easily feel it by rubbing that area. The nasion is the ridge between your nose and forehead, just between your eyebrows. The inion is the point where your skull ends at the back of your head.
For this setup, you'll need a bandana and some tape (I used electrical tape, but scotch tape or even a band-aid would probably work). First, find your left mastoid. Clear away any hair, and tape the ground electrode to the skin there. Next, tie the bandana tight around your head, such that it is above both the nasion and inion. The bandana will be used to secure in place the remaining 2 electrodes. Put one electrode about 1 inch above and 1 inch to the right of your nasion, and the second the same distance from your inion. Using this top down view, your electrodes should be roughly in the area of Fp2 and O2.
As mentioned, we will be primarily measuring alpha waves with this setup. Alpha waves are around 8-12 Hz waves, and in general increase in amplitude when you are relaxed or in a more meditative state. Because one electrode lays on your occipital lobe (the part of your brain used for visual processing), whenever you close your eyes there should be a distinct increase in alpha wave concentration. The increase should be even more apparent if you relax and try to clear your mind while your eyes are closed.
Step 10: "Processing" the Data
First thing to do is to download Processing, available at http://processing.org. It doesn't require any installation; just unzip the download, open the folder, and run it. Download the sketch (what programs are called in processing), and open it up. The program should be good to go as is, and while there should be enough documentation to understand what's going on in the sketch, I want to make a few notes and give a general outline of what it does here.
I encourage you to tinker with the program - change things, make your own, etc. Don't be afraid to break it, since a working version can always be found here. If you're new to programming, the guys that made processing have some really great basic tutorials here. One thing to note is that Processing is case sensitive - if at some point you type in FFTHeight instead of FFTheight, the program will give you an error and take you to the line where you typed in the former. I didn't document every single function that I used - if you're unsure about what a part of code does, you should look up the function being used at processing.org, so that you can see what its meant to do, as well as exactly what it takes as inputs and produces as outputs. Audio classes won't be found as easily there (minim, FFT, AudioInput, etc). To find documentation for those pieces, look here, specifically at the manuals under the tools tab at the top.
Also, a little background on the FFT. Data can be represented in many ways, two common ways being in time and frequency. Representing information into frequency domain usually amounts to showing data as the combination of a lot of sine waves with various frequencies and amplitudes. If you have a pure sine wave, say oscillating at 1 Hz, you would see the sine wave we all know and love in the time domain, but in the frequency domain would just see one line at f = 1. If in time you had a wave that was made by adding one sine wave at 1 Hz, and one that was half the amplitude the first but at 2 Hz, in frequency you would see two lines - one at 1 Hz with a height of 1, and one at 2 Hz with a height of 0.5.
From this, you can represent very complicated signals (any signal!) as a combination of a number (sometimes an infinite number) of sine waves. The most common way to convert signals from the time domain to frequency is with the FFT (Fast Fourier Transform). It does exactly what I just described -- it takes as input a section of time domain signal, and outputs bands corresponding to the concentration of certain ranges of frequencies in that signal. This data can easily be visualized by displaying each band as a bar with a certain height, as I did in the code.
This program is really just a data acquisition / visualization one. There are a LOT of things you can do with this circuit -- I encourage you to really play around with it and make something of your own! The next step is an optional one detailing something a little more fun that I made with the type of data acquired in this program.
Code available here.
Step 11: Playing Pong With Your EEG
The associated code is much neater than the data-reading one. Because the game code incorporates object oriented programming, experienced programmers will likely find it easier to follow along, while those that have not worked with object oriented code before may have a harder time. If you fall into the latter category, I highly suggest reading this tutorial to get familiar with the basics.
The circuit used for this one is exactly the same, except you need two, since you have two players. To get it in via the audio cable, connect one of the circuits the usual way (outlined in the previous steps), and the other circuit to the other audio channel (the middle section of the audio cable). You can use one set of batteries for both circuits, so they should share the same ground.
Code available here.
Quick video demo of me using it against a wall here.