The EEG Magic Cat Ears

Kang Li(kl694) and Zhenxuan Qiu(zq39)

For our ECE 4760 final projec, we built a pair of toy “cat ears” using electroencephalography (EEG) with the AVR microcontroller. The basic function of it is that it can change the gesture of the “Ears” based on the participant’s emotion. The user doesn’t need to do anything except for thinking.

Introduction

Magic Cat Ears is a next generation toy. It reads user’s excitement degree and controls the ears to show different gestures. To make it work, one just need to put it on the head and connect the system properly. It will then do all the work automatically.
The design is built with Atmel microcontroller ATmega 1284P, a pair of EEG electrodes, step motors and a series of analog signal processing circuits.
We use EEG technique to capture how relax or exciting the user is. EEG (electroencephalogram) is able to show a wide range of electromagnetic radiation from human brain. Here we only capture α wave to find out what we want. Basically, the magnitude of α wave goes down when people is exciting, and goes up when people is relaxing. So the excitement detection with α wave is possible. However, the key point, which makes it hard to implement the technique, are the noise and the narrow bandwidth of α wave. Since α wave is only a part of electromagnetic radiation from our brain, there will much interference from other waves. Also, electromagnetic radiation from the working environment will count as noise. The bandwidth of α wave is only 4 to 5 Hz, which makes it very hard to distinguish.
The EEG sensor we build is composed of two amplifiers, a high-pass filter, and a low-pass filter. The key components to solve the above problem are the filters. The second order high-pass filter alleviates the interference from θ wave, δ wave and other low frequency noise. The eighth order low-pass filter bans the interference from β wave and high frequency noise. Two amplifiers ensure that the output of the signal processing circuits large enough so the ADC of the microcontroller can recognize with relatively quantization error.
To show the level of excitement, several gestures are set according to the signal from the sensor system. Some random gestures will fulfill the time when the status of the user is relatively stable so you never feel the device is dead.
Nowadays, EEG is not only attracting attention from the medical device manufactures. It is also highly valued in other fields like psychology study, smart control. Our device is an example to show how it could be combined with toys and our daily life. And in the future, when the technique becomes mature enough, more interesting devices will be built with it for sure.

High-Level Design

Inspiration of the project

We got the idea from the toy “Necomimi” designed by NeuroSky company. http://www.necomimi.com/ . We like this idea very much. So we want to build one of our own.

Schematic of the logic of the project


Hardware Design

The MCU chip we use to develop this project is ATmega 1284P. And we have five basic parts of the analog signal processing board: the amplifier circuit, the low-pass filter circuit, the high-pass filter circuit, another amplifier circuit after low-pass filter, and the motor control circuit.
For the electrodes, we select premium reusable silver patch electrodes. We use two electrodes in our design. The positive electrode is connected to the forehead of the user and the negative electrode is connected to one of the ears.
For the safety concern, we only use AA batteries to provide power to ATmega 1284P and the analog signal processing board.

1. Analog signal processing board

The AD620 amplifier circuit
We use AD620 as our main amplifier chip. The reason for selecting AD620 is that it has very high input impedance, which is required for EEG detecting. We connect the PIN1 and PIN8 of AD620 with a 1 k ohms resister to get the gain of around 50. The gain of AD620 can be calculated by the fomula



Figure 1. Amplifier Circuit of AD620


The high-pass filter circuit
We use CA3140 to build our second order high pass filter. CA3140 is integrated circuit operational amplifier with Very High Input Impedance.


Figure 2. High-pass Filter Circuit using CA3140


Because the resistor and capacitor values are the same, the cut-off frequency


And the gain

 
The low-pass filter circuit
We use MAX294 as the chip of our low-pass filter circuit. MAX294 is an 8-order low pass elliptic filter, with the corner frequency of 13Hz in our design. The clock to corner frequency ratio is 100:1, which means the external clock we are using is 1300Hz. The external clock generated by the MCU is connected to the PIN 1 of MAX294.
Because the range of the input of the MAX294 is 1~4V, we have to add DC offset as shown in the circuit diagram.


Figure 3. Low-pass filter Circuit using MAX294


The LF353N amplifier circuit
We found that the signal after the low-pass filter circuit is still too small for the MCU to recognize. So we add another amplifier circuit. The reason we don’t amplify the signal more in the AD620 circuit is that we might amplify the noise and then cause the distortion. We add a 2.5V DC offset circuit to make the signal positive all the time. We also add an extra low pass filter to smooth the waveform of the input of MCU, which is PINA0 in this case.


Figure 4. Amplifier Circuit using LF353N


The gain of the amplifier circuit is


The whole circuit diagram is as follows:


Figure 5. The whole circuit diagram of analog signal processing board


The motor control circuit
The motor control circuit is pretty straightforward since we use the motor driver test module board with the chip ULN2003. For the right motor, we connect the PINC0~3 of the MCU to the PIN1~4 of the driver board. And for the left motor, we connect the PINC 4~7 of the MCU to the PIN1~4 of the other driver board. And we use separate power supply for the two motors.
This is the connection schematic of Motor control board and the MCU.

 

2. Electrodes

We use two electrodes in our design. We use an audio cable to connect the electrodes and the MCU. As described in the first part of hardware design, the positive electrode is connected to the forehead of the user and the negative electrode is connected to one of the ears.


Figure 7. The photo of the electrodes and batteries

3. Power supply

We use 6 AA batteries to provide power to the ATmeag 1284P and the analog signal processing board. The voltage range is from -3 V to +6 V.
And we use another 4 pack AA batteries as the motors’ power supply (6 V). So there is no connection between our project and the 110V AC.


Figure 8. The photo of the complete hardware setup


Figure 9. The photo of Kang doing the test


Software Design


The logic of our software design has 4 parts: 1300Hz clock generation, ADC function, Sample collection and mode selection, and Motor control. We read the voltage of EEG signal through PINA0 of ATmega1284P using the internal ADC function. We select the highest value and the lowest value every one second. We subtract these two values and then get the variable “delta”, which is the peak-peak value of the input EEG signal and our standard for mode selection. If “delta” reaches some thresholds we set before, we control the motors/cat ears to spin in some gesture we designed.


1300Hz clock
We need to generate 1300Hz clock for MAX294.We use Clear Match on Compare Match Mode of Timer 2 to generate the 1300Hz clock for MAX294. In Clear Timer on Compare or CTC mode (WGM22:0 = 2), the OCR2A Register is used to manipulate the counter resolution. For generating a waveform output in CTC mode, the OC2A output can be set to toggle its logical level on each compare match by setting the Compare Output mode bits to toggle mode (COM2A1:0 = 1). The waveform frequency is defined by the following equation:


The N variable represents the prescale factor, which is 32 in our design. The OCR2A is set to 191. Because of the frequency of crystal on the board is 16MHz, the output frequency is around 1302Hz which is the exact frequency we want. The code is as follows:


// set up timer 2 for square wave with NO ISR
//the frequency of the squarewave is 1300Hz
OCR2A = 191 ;    
TCCR2B =  3;      
// set to toggle OC2A, clear on match,
TCCR2A = (1<<COM2A0) | (1<<WGM21) ;
// PORT D.7 is the output of OC2A
DDRD = (1<<PIND7) ;   


ADC function
We use the internal ADC function of Atmega1284P. First, we put a DC offset circuit after the amplifier circuit using LF353N as described in the hardware design part. Then we read the voltage value of the output signal of LF353N after the 2.5V DC offset through PINA0 by setting the resister as follows:


ADCSRA = (1<<ADEN) | (1<<ADSC) +7;
ADMUX = (1<<REFS0) | (1<<ADLAR) + 0b00000;


Sample collection and mode selection
We use Timer 0 to generate 0.05mSec time base as follows:


//set up timer 0 for 0.05 mSec timebase
TIMSK0= (1<<OCIE0A); //turn on timer 0 cmp match ISR
OCR0A = 99;                  //set the compare reg to 100 time ticks
//set prescalar to divide the clock frequency by 8
TCCR0B= 2;        
// turn on clear-on-match
TCCR0A= (1<<WGM01) ;


We take the Peak-Peak value of the detected EEG signal every 40 mSec. And we add the continuous 25 Peak-Peak values together and then average it to get the value of the variable “delta”, which is the standard for the mode selection. So we can get the new value of delta every one second.
Because the magnitude of the alpha wave decreases when people get excited, we create 3 modes HIGH, MEDIUM, LOW with the value of delta 15~30, 30~60, 60~160, respectively. In each mode, we control the motor to spin in different gesture.


Motor control
We generate 4 square waves with MCU for controlling each motor and every square wave has different phase.
We use 4 different functions motor_synchronizm, motor_asynchronizm, motor_left, motor_right to control the motor gestures. Every function has two input variables: direction and the spin angle.
The function motor_synchronizm controls the two motors to spin in the same direction. The function motor_asynchronizm controls the two motors to spin in the opposite direction. The function motor_left and motor_right only controls the left motor or the right motor. So by combining these four functions, we can control the two motors to perform different gestures.
Safety
Because we need to connect the project directly to people’s head, the safety is always our first concern. The microcontroller and the whole analog circuit are only ever powered by six 1.5V AA batteries and the 2 motors are powered by another four 1.5V AA batteries. So they are all using low voltage. And we don’t use the USART to connect to the computer, either. So there is no 110V AC power connection with the whole project directly or indirectly.


Results


We can control the motor based on the EEG signal.


Figure 10. Output of AD620


The output of AD620 increases when we connect both the electrodes to people. Figure 10 illustrates that we can get signal with the electrodes. But it contains a huge amount of noise which is mostly the high frequency interference. We need to isolate alpha wave from this noisy signal. As mentioned before, an 8-th order low-pass filter is adopted to fulfill this job.   



Figure 11. The Output EEG Signal after LF353N amplifier circuit when we connect two electrodes to the skin


The output of filter and amplifier system is the filtered EEG signal which is mostly alpha wave. The peak-peak amplitude of the signal fluctuates with the change of relax level of the user. Comparing the lower figure in Figure 11 with the standard alpha wave which is shown in Figure 12, we can say that what we get is surly EEG signal. And in the upper figure in Figure 11, the amplitude change from low to high, which indicates the status of the user change from high to low.

brainwaves
( Source: http://www.scientificamerican.com/article.cfm?id=what-is-the-function-of-t-1997-12-22   )
Figure 12. The EEG Signal

 


Figure 13. The Output Noises (when two electrodes are connected together)


Comparing the noise with the working output signal as shown in Figure 13, we can see that the amplitude of the noise is relatively low but still can cause interference. So it will impact the accuracy of the system. But we can still get some information about the status of people up to a point because some parts of useful signal with higher amplitude are easy to recognize.
Accuracy
The noise is a very big problem for us. If we don’t connect the electrode to the skin, there are noises which are comparable to the EEG signal and then can make the motor spin sometimes. To eliminate this noise, we should connect the two electrodes together when we take off the hat or stop testing.
And also, the thresholds we set in the program are still some relative values. It’s really hard to tell if a person is in an excited mode or not. Furthermore, the magnitude of EEG signal is different from different persons. So all we can do is to tell the relative emotion of a particular person in some time period.
User Friendliness
Our project is very easy to use. All the user needs to do is to connect the two electrodes to the skin. It will then do all the work automatically. And the gesture of the cat ears can demonstrates the level of excitement of the user.

Conclusion

Expectations Met

We build a pair of EEG Magic Cat Ears. It can change the guesture of the ears based on the user's level of excitement. The analog circuit can filter the alpha band of brain wave and the microcontroller can control the two motors based on the magnitude of the EEG signal. But the project is really hard to test because the magnitude of EEG signal is different from different persons and the noise may influnce the EEG signal. We cannot do the calibrations everytime the user puts on the hat. So this project can only test the relative change of EEG signal and cannot be used as accurate equipment of testing the level of excitement.

Intellectual Property Considerations

Our idea came from the toy “Necomimi” as mentioned before. And the part of our circuits is inspired by the final project of Spring 2012: Brain-Computer Interface designed by Charles Moyes (cwm55) and Mengxiang Jiang (mj294). Additionally, we used the uart.h and uart.c in our design. These two files are provided by the course ECE 4760.

Legal Consideration

According to all hardware and software design, there are no known legal considerations regarding the EEG Magic Ears, because our project is not being used for any commercial means.

Reference

Cornell University ECE 4760 final project Spring 2012: Brain-Computer Interface designed by Charles Moyes (cwm55) and Mengxiang Jiang (mj294)

http://people.ece.cornell.edu/land/courses/ece4760/FinalProjects/s2012/cwm55/cwm55_mj294/index.html#intro

Cornell University ECE 4760 webpage

http://people.ece.cornell.edu/land/courses/ece4760/

Acknowledgements

We would like to thank Bruce Land and all the ECE 4760 TAs for their time and instructions. Our project is only use for course requirements. We are not intend to make profits out of it. And also, this project is built by ECE students and cannot be used in medical conditions.

Appendix


Part List

Name
Digikey Part Number
Quantity
Cost(USD)
AD620
AD620ANZ-ND
1
7.94
CA3140
CA3140EZ-ND 
1
1.89
MAX294
MAX294CPA+-ND
1
10.21
LF353N
LF353NFS-ND
1
0.55
Mega1284
1
5
Custom PC board
1
4
DIP socket
4
0.5*4=2
Resistors and capacitors
0
Small solder board (2 inch)
1
1
Audio cable
1
2.78
DC 5V Stepper Step Motor + Driver Test Module Board ULN2003
2
2.5*2=5
Premium Silver Tens Electrodes Pads 4 Square Highly Adheresive Tens Pads
1
5.08
Hat
1
3
AA batteries
10
13.99

total

60.44

Code

Main module: MCE.c

Comunication module: uart.h uart.c

Datasheets

ATmega 1284P http://people.ece.cornell.edu/land/courses/ece4760/AtmelStuff/mega1284full.pdf

AD620 http://www.analog.com/static/imported-files/data_sheets/AD620.pdf

MAX294 http://datasheets.maximintegrated.com/en/ds/MAX293-MAX297.pdf

CA3140 http://www.intersil.com/content/dam/Intersil/documents/fn95/fn957.pdf

LF353N http://www.fairchildsemi.com/ds/LF/LF353.pdf