Mind Control 3_ EEG Monitor _ 7 Steps (With Pictures) - Instructables
Mind Control 3_ EEG Monitor _ 7 Steps (With Pictures) - Instructables
By lingib in CircuitsArduino
EEG Monitor
An electroencephalogram (EEG) is a test used to evaluate electrical activity in the brain.
This instructables explains how to build an EEG waveform monitor using an Arduino UNO R3, a TFT graphics shield, and a modified AD8232
heart monitor.
Due to its small size the TFT display can only show 4 out of the 32 possible channels at any one time ... but the choice of channels is yours.
Processing software is included for displaying all 32 EEG channels simultaneously on your PC screen.
Arduino EEG software covering each of the following frequency ranges is also presented [1]:
DC .. 32Hz
DC .. 64Hz
DC .. 128Hz
DC .. 256Hz
DC .. 512Hz
DC .. 1024Hz
DC .. 2048Hz
DC .. 3200Hz
The estimated cost of parts for this project is less than $30.
Photos
Notes
[1]
breadboard
stranded copper wire
solder
Construction details for the matching shield (photo 2) are given in my instructable https://www.instructables.com/id/Arduino-TFT-Grap...
When used as a heart monitor the ECG leads are connected as follows:
This diagram was created by matching the component values in the Sparkfun “Heart Monitor” schematic [1] to the AD8232 “Functional Block
Diagram” [2]
When used as a heart monitor, both inputs to the AD8232 instrumentation amplifier are tied to the 3.3 volt supply rail via 10M resistors. The
instrumentation amplifier, however, can’t operate unless the two input leads are around mid-rail potential.
Mid-rail potential is obtained by injecting a tiny (10uA) current from the RLD (right leg drive) lead into your leg. We have effectively created a
voltage divider using your body as one of the resistors.
The actual purpose of the RLD lead is explained in the AD8232 data sheet ... I’m just looking at it from a different viewpoint.
Instead of looking for heart beats, the EEG Monitor is looking for differences in electrical potential. As such it needs to be fully operational at all
times ... both inputs of the instrumentation amplifier must be tied to a mid-rail potential such as Vref (1.5 volts)
This is achieved by cutting the track that connects both 10M resistors to the 3.3 volt supply and joining the cut end to Vref by means of a small
wire link. Both inputs of the instrumentation amplifier are now at mid-rail potential which means the AD8232 output hovers about 1.5 volts DC.
We also don’t need the RLD lead ... let’s use this lead to improve the CMRR (common mode rejection ratio) of the system by raising your body to
midrail potential. This is achieved by cutting the track to the AD8232 RLD pin and joining the cut end to Vref.
The AD8232 data sheet recommends that the RLD and RLDF (right leg drive feedback) pins be shorted when using a two-lead circuit. This is
achieved by shorting the capacitor joining these two pins.
References
[1]
https://cdn.sparkfun.com/datasheets/Sensors/Biomet...
[2]
https://www.analog.com/media/en/technical-document...
Step 4: Theory
Complex waveforms comprise many sinewaves each with a different frequency, amplitude. and phase. These frequencies may be identified
using a fast fourier transform (FFT).
Spectrum analysers, such as my instructable https://www.instructables.com/id/Mind-Control-2-S...and this EEG monitor both use FFT ... the
difference is in how they display the FFT output data,
Spectrum analysers display the signal amplitudes against frequency whereas EEG monitors display frequency and amplitude against time.
fix_FFT output
The fix_FFT software used in this EEG Monitor outputs numbers. A large number indicates the presence of a frequency. [1]
Photo 1 shows the numbers for a 6Hz sinewave ... there is only one large number
Photo 2 shows the numbers for a 6Hz squarewave ... there are three bins with a large number.
Note that the 3rd harmonic at 18Hz has 1/3rd of the fundamental amplitude, and that the fifth harmonic at 30Hz has 1/5th of the fundamental
amplitude.
Frequency Bins
The number of frequencies that are assigned to a bin depends on the sampling-frequency and the number of samples.
If the sampling frequency is 64Hz and the number of samples is also 64 then each bin will be 1Hz wide.
If we increase the sampling frequency by a factor of 4 then each bin will be 4Hz wide. For example the number in bin[6] would represent 24Hz,
25Hz, 26Hz, and 27Hz.
The examples shown in the above photos have a bin-width of 1Hz for ease of explanation.
Sampling theory (Nyquist) says that we only need look at the first 32 bins if the number of samples is 64.
Notes
[1]
Bias
The waveform peaks to your Arduino analog-to-digital (A/D) converters must not go below zero volts or exceed +5volts.
Assuming a 2 volt peak-peak input waveform, then a DC bias of at least 1volt is required.
a resistive voltage-divider and a coupling capacitor. The down-side to coupling capacitors is they limit the low frequency response
op-amp offset voltages connected to the A/D.
This EEG Monitor uses the 1.5 volt reference voltage from the AD8232 breakout board. Since coupling-capacitors are not required bin[0] of the
EEG monitor will respond to changes in DC.
Numbers
The A/D convertor outputs 1023 for a +5 volt input, and 0 for zero volts.
“For a 16 MHz Arduino the ADC clock is set to 16 MHz/128 = 125 KHz. Each conversion in AVR takes 13 ADC clocks so 125 KHz /13 = 9615 Hz.
That is the maximum possible sampling rate, but the actual sampling rate in your application depends on the interval between successive
conversions calls.” [1]
In practice I have found the maximum sample rate to be 8192Hz when sending FFT (fast fourier transform) data to my PC
DC Offset
The DC offset from the input voltage divider only affects bin[0].
My code automatically subtracts the startup reading from all subsequent readings which allows me to track any changes.
Notes
[1]
https://arduino.stackexchange.com/questions/699/ho...
Step 6: Software
Arduino Software:
fix_FFT_EEG_DC_32Hz.ino
fix_FFT_EEG_DC_64Hz.ino
fix_FFT_EEG_DC_128Hz.ino
fix_FFT_EEG_DC_256Hz.ino
fix_FFT_EEG_DC_512Hz.ino
fix_FFT_EEG_DC_1024Hz.ino
fix_FFT_EEG_DC_2048Hz.ino
fix_FFT_EEG_DC_3200Hz.ino
Copy the contents of your chosen package into a fresh arduino sketch, save it using the same name but without the .ino extension, then upload
it to your Arduino.
The bin-widths in Hz may be found by dividing the maximum package frequency by 32.
For example:
Processing Software:
In addition to the above software I have included two Processing sketches for displaying all 32 frequency bins (photo 1) against time:
fix_FFT_EEG.pde
fix_FFT_EEG_2.pde
There is, however, a slight difference ... fix_FFT_EEG.pde automatically removes any DC offset regardless of whether the DC offset has already
removed.
Note
[1]
You will get a run-time error message if Processing can't find your Arduino. Follow the instructions in the fix_FFT_EEG.pde header if this should
happen.
Step 7: Summary
This instructable explains how to make a EEG analyser.
The operation has also been explained with the aid of design notes, videos and photos.