Maker Pro
Maker Pro

EEG circuit - need help please!

eboaylag

Jan 7, 2016
46
Joined
Jan 7, 2016
Messages
46
Keep in mind the Arduino is directly coupled to the output of your device.
The Arduino will not like a negative input on that signal input so you should either cut the wave-form in half... or put a decoupling capacitor in-between, reduce the output to maybe about 2V p-p and add a DC offset so that the Arduino ADC reads roughly 50% when there is no output.

Thanks for bringing this up. This is pretty important to know.
Could you explain a bit further what you mean by the options of either cutting the wave in half, or using a decoupling cap and DC offset? These are new terms to me.

As far as I can tell (doing quick research), you mean to read in only the positive peaks of the waves for cutting the wave in half?
And for the DC offset, you mean to keep the wave normal but offset it above the 0V threshold so that I can read in the whole wave (basically shifting the whole wave above the 0V threshold so that it's all positive)?
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
Thanks for bringing this up. This is pretty important to know.
Could you explain a bit further what you mean by the options of either cutting the wave in half, or using a decoupling cap and DC offset? These are new terms to me.

As far as I can tell (doing quick research), you mean to read in only the positive peaks of the waves for cutting the wave in half?
And for the DC offset, you mean to keep the wave normal but offset it above the 0V threshold so that I can read in the whole wave (basically shifting the whole wave above the 0V threshold so that it's all positive)?
Absolutely!
I'm glad you are one of the members on here that isn't afraid of Google ;)
Yessir, either using a diode to chop the negative side of the output off, or raise the entire output up above the 0V threshold. In order to change the offset of the wave-form, you would use a decoupling capacitor. DC is blocked by a capacitor, so one side would normally be at maybe 2 - 2.5VDC, and the signal would be injected on the otherside. Signal would pass across the capacitor and end up imposed on top of the DC voltage raising it up above the 0V threshold.
Unfortunately, I'm brain-farting and cant recall what size capacitor should be used for decoupling... :s
 

eboaylag

Jan 7, 2016
46
Joined
Jan 7, 2016
Messages
46
Absolutely!
I'm glad you are one of the members on here that isn't afraid of Google ;)
Yessir, either using a diode to chop the negative side of the output off, or raise the entire output up above the 0V threshold. In order to change the offset of the wave-form, you would use a decoupling capacitor. DC is blocked by a capacitor, so one side would normally be at maybe 2 - 2.5VDC, and the signal would be injected on the otherside. Signal would pass across the capacitor and end up imposed on top of the DC voltage raising it up above the 0V threshold.
Unfortunately, I'm brain-farting and cant recall what size capacitor should be used for decoupling... :s

Haha yeah, it's best that I do research! It helps me understand and makes it easier to communicate with everyone else on here when I have base knowledge of how things are working.

Alright, so I'd prefer to go the offset route to keep as much data coming in as possible. Would this offset be applied only at the final output of the circuit (after the amplifier right before it feeds into the Arduino), or would it have to exist in multiple portions of the circuit? It seems like it's only on the final output.
For that, would something like this be sufficient (adapted from http://www.edaboard.com/thread32594.html )?

Sample_Offset.png


(where R1 == R2)

Basically, using a resistor to impede the +9V power from my battery to the voltage I want to offset by. Arduino reads 0V to 5V, so offsetting the 0V threshold up to 2.5V would probably be good.
Another example I think is here: http://electronics.stackexchange.com/questions/14404/dc-biasing-audio-signal on the first answer. This one also linked to a nice simulator for how it works!
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
Haha yeah, it's best that I do research! It helps me understand and makes it easier to communicate with everyone else on here when I have base knowledge of how things are working.

Alright, so I'd prefer to go the offset route to keep as much data coming in as possible. Would this offset be applied only at the final output of the circuit (after the amplifier right before it feeds into the Arduino), or would it have to exist in multiple portions of the circuit? It seems like it's only on the final output.
For that, would something like this be sufficient (adapted from http://www.edaboard.com/thread32594.html )?

Sample_Offset.png


(where R1 == R2)

Basically, using a resistor to impede the +9V power from my battery to the voltage I want to offset by. Arduino reads 0V to 5V, so offsetting the 0V threshold up to 2.5V would probably be good.
Another example I think is here: http://electronics.stackexchange.com/questions/14404/dc-biasing-audio-signal on the first answer. This one also linked to a nice simulator for how it works!
Exactly!
You need two things to be done though. The 2.5V offset is perfect and only needs to be done at the output of the very last stage.
You need to ensure that the 2.5V + or - your signal does not exceed 5V or drop below 0V. You can play with the gain of the last stage for this.
Of course, you can always put protection in place, that way if you hit the limits the signal will clip instead of damaging anything.
Protection would take the place of a diode to protect against reverse voltage, and a zener diode that can be used to 'clamp' the voltage to no more than 5V.
Protection is optional as long as your final output does not exceed the limitations of the Arduino.
 

eboaylag

Jan 7, 2016
46
Joined
Jan 7, 2016
Messages
46
Exactly!
You need two things to be done though. The 2.5V offset is perfect and only needs to be done at the output of the very last stage.
You need to ensure that the 2.5V + or - your signal does not exceed 5V or drop below 0V. You can play with the gain of the last stage for this.
Of course, you can always put protection in place, that way if you hit the limits the signal will clip instead of damaging anything.
Protection would take the place of a diode to protect against reverse voltage, and a zener diode that can be used to 'clamp' the voltage to no more than 5V.
Protection is optional as long as your final output does not exceed the limitations of the Arduino.

I calculated expected signal ranges (based on alpha and beta waves ranging from 10-60uV):
Diff_Voltage_Calc_White.png

The values are workable, as long as I keep the potentiometer on the final amplifier turned low (towards the gain of 83). I'm looking into buying a higher value resistor to put in the beginning to make the gain of the Instrumentation Amp lower and make the values more workable toward the end in order to avoid going over the limit/needing a diode.

In calculating the capacitor and resistor values for the voltage divider, I'm just using a voltage divider calculator to get 9V down to 2.5V. I'm a little confused as to how to find the value for the capacitor. though. This site seems like the best bet for calculating, but how do I find S for the formula V+ / (1+R1/R2 + R1*C*S)? Someone on that site said that a higher capacitance would be best, but I don't know how to calculate how high it should be.
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
They are absolutely right in a higher capacity being best, but in order to calculate the value you need to know the input impedance of the Arduino or other device you are using... That is why I am drawing a brain-fart giving you a value.. :s
 

eboaylag

Jan 7, 2016
46
Joined
Jan 7, 2016
Messages
46
They are absolutely right in a higher capacity being best, but in order to calculate the value you need to know the input impedance of the Arduino or other device you are using...

As per the ATmega328P datasheet (page 310) the analog input/ADC resistance is 100MOhms.
Someone from this site says that it's recommended that whatever's connected to the analog pins has an output impedance of 10k or less. I'm not sure if that helps, but it's what I've found after searching so far.
 

eboaylag

Jan 7, 2016
46
Joined
Jan 7, 2016
Messages
46
@Gryd3 , would this be the way to calculate this? (page 2) I'm finding it pretty difficult to find information about finding this value.
Also, would higher values for the voltage divider resistors be better? I already have 270kOhm and 100kOhm resistors to give an offset of around 2.4. I also have 3.9kOhm and 1.5kOhm resistors which would give an offset of 5.
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
@Gryd3 , would this be the way to calculate this? (page 2) I'm finding it pretty difficult to find information about finding this value.
Also, would higher values for the voltage divider resistors be better? I already have 270kOhm and 100kOhm resistors to give an offset of around 2.4. I also have 3.9kOhm and 1.5kOhm resistors which would give an offset of 5.
I would keep the values for the voltage divider high. The paper you found appears to be for power supply noise, and not for coupling an AC signal to DC offset.
I've thought about it again, and we can oversize the capacitor. (We don't want to accidentally make a low-pass filter that clips your signal... but the decoupling capacitor *will* form a low-pass. We just need a higher cutoff frequency than what you expect to see.) As an alternative, if you have a free op-amp, you can also build a voltage summer which will add 2.5V to the signal and buffer it's output so you could theoretically output to different devices.
 

eboaylag

Jan 7, 2016
46
Joined
Jan 7, 2016
Messages
46
Alright, so with the op-amp would it be like this?
op_amp_sum_add.gif

Where before R2 could be a simple voltage divider to bring 9V down to 2.5V, and the op-amp would be flipped so it's non-inverting?

As for keeping with the voltage divider with cap, when I input capacitance on this calculator at 10uF (which I think is a pretty high value for film caps) and resistances varying from low to high, the low pass is very low with higher resistance values and high for low resistance values. But we want both resistance and capacitance high for the voltage follower, correct? Am I doing something wrong?
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
Alright, so with the op-amp would it be like this?
op_amp_sum_add.gif

Where before R2 could be a simple voltage divider to bring 9V down to 2.5V, and the op-amp would be flipped so it's non-inverting?

As for keeping with the voltage divider with cap, when I input capacitance on this calculator at 10uF (which I think is a pretty high value for film caps) and resistances varying from low to high, the low pass is very low with higher resistance values and high for low resistance values. But we want both resistance and capacitance high for the voltage follower, correct? Am I doing something wrong?
You want high resistance for the voltage divider, the capacitor simply needs to be large enough that when connected to common input devices, their impedance does not cause the 'high-pass' filter to drop your signal.. that may be hard to do because of your frequency range though, so I would forget the decoupling capacitor and use an opamp summing circuit only to add the offset.
At the same time, I'm using theory with my current understanding and would like @AnalogKid to take a quick peak and suggest an ideal solution for interfacing a low-frequency AC signal to an Arduino.
 

eboaylag

Jan 7, 2016
46
Joined
Jan 7, 2016
Messages
46
If I did the op amp circuit, would it be like this: http://masteringelectronicsdesign.com/summing-amplifier-calculator-java/ . Where V2 would be created through a voltage divider to bring 9V down to 2.5V, V1 would be my circuit output ranging from ~ -2V to 2V, and Vout1 and Vout2 in the picture are 0V and 5V, the Arduino range? The overall goal is to bring the midline of the range from 0V to 2.5V to be in the middle of the Arduino input range, so I feel like this would work, but second opinions are greatly appreciated. If this is the best way to go, feedback on if lower or higher resistance values would be better would be greatly appreciated.

Thanks to everyone for all your patience and help! This is quite a journey, and I'm glad to have people who are so knowledgeable to help me through it and understand it. :)
 

eboaylag

Jan 7, 2016
46
Joined
Jan 7, 2016
Messages
46
Also, what film caps are best to use? I bought these: http://www.digikey.com/product-search/en?keywords=399-5443-nd and http://www.digikey.com/product-detail/en/kemet/MMK5225K63J06L4BULK/399-5881-ND/2571316, but the leads turned out to be much shorter than specified so I'm considering buying new ones. Would these be better? http://www.digikey.com/product-detail/en/panasonic-electronic-components/ECQ-E1105KF/EF1105-ND/56380 and http://www.digikey.com/product-detail/en/panasonic-electronic-components/ECQ-E1225KF/EF1225-ND/56392. I'm planning on placing an order before the end of the night tonight so they arrive quickly, but any advice on the correct type of film caps to use would be helpful!
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
If I did the op amp circuit, would it be like this: http://masteringelectronicsdesign.com/summing-amplifier-calculator-java/ . Where V2 would be created through a voltage divider to bring 9V down to 2.5V, V1 would be my circuit output ranging from ~ -2V to 2V, and Vout1 and Vout2 in the picture are 0V and 5V, the Arduino range? The overall goal is to bring the midline of the range from 0V to 2.5V to be in the middle of the Arduino input range, so I feel like this would work, but second opinions are greatly appreciated. If this is the best way to go, feedback on if lower or higher resistance values would be better would be greatly appreciated.

Thanks to everyone for all your patience and help! This is quite a journey, and I'm glad to have people who are so knowledgeable to help me through it and understand it. :)
That's the circuit I would try, but am hoping for a second opinion soon ;)
As far as resistor values are concerned, The values in the divider should be high, like 10k or so. Little Science here, but high values don't often alter the remainder of the circuit when used like low values do. It also keeps current draw low which helps conserve power.
The resistors that may be in-line with the signal should be lower, maybe 1k or 100Ω
You have opamp outputs though which are quite capable 'buffers' so this is less of an issue picking a resistor than if you built a passive filter.
 

eboaylag

Jan 7, 2016
46
Joined
Jan 7, 2016
Messages
46
Alright, so let's say I choose to do the voltage divider at the end of my circuit.
Can I use the 5V output from the Arduino as my offset? In other words, taking the 5V and using two resistors to bring it down to 2.5V, with a cap at the beginning to decouple.
If I use values of 22k for both resistors and a cap of 1uF, the cut-off frequency that results from the created high pass filter is 7.23. If I use a 2.2uF cap, it's 3.288. 10uF, it's 0.723. Those three cap values are the ones I have.
I'm already using the Arduino to feed into the computer, so I wanted to check in and make sure this was a safe and viable option.

Otherwise, if I do the voltage divider with a 9V battery, 270k and 100k resistors will be used. 1uF cap makes a 1.59 cutoff, 2.2uF makes a 0.723, and 10uF makes a 0.159.

I'm not having any luck with figuring out the summing amp, and I'm on a very tight time crunch currently. Doing some research, it seems the voltage divider will work fine for my purposes, as long as it doesn't clip outside of my bandpass filter (7-30Hz), which they for the most part don't do.
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
Alright, so let's say I choose to do the voltage divider at the end of my circuit.
Can I use the 5V output from the Arduino as my offset? In other words, taking the 5V and using two resistors to bring it down to 2.5V, with a cap at the beginning to decouple.
If I use values of 22k for both resistors and a cap of 1uF, the cut-off frequency that results from the created high pass filter is 7.23. If I use a 2.2uF cap, it's 3.288. 10uF, it's 0.723. Those three cap values are the ones I have.
I'm already using the Arduino to feed into the computer, so I wanted to check in and make sure this was a safe and viable option.

Otherwise, if I do the voltage divider with a 9V battery, 270k and 100k resistors will be used. 1uF cap makes a 1.59 cutoff, 2.2uF makes a 0.723, and 10uF makes a 0.159.

I'm not having any luck with figuring out the summing amp, and I'm on a very tight time crunch currently. Doing some research, it seems the voltage divider will work fine for my purposes, as long as it doesn't clip outside of my bandpass filter (7-30Hz), which they for the most part don't do.
'After' the decoupling capacitor, you can use any voltage source you want to create the 2.5V offset. So sure, using the same as the Arduino is fine.
As far as the decoupling cap is concerned, if you found value to make a high-pass that is below the frequency you need, then go for it :)
Wasn't aware of the time crunch, hopefully this does not give you any headscratching moments
 

eboaylag

Jan 7, 2016
46
Joined
Jan 7, 2016
Messages
46
Thanks! I never mentioned the time crunch because I didn't want you to feel rushed or obligated. You're doing this as a favor and to help and you've already helped so much, and I feel like I've been asking so many questions. Just know that I really appreciate how much you've helped me!!

So, for the fake brain we mentioned earlier, I've been using an audio file generated in Audactiy with sine waves ranging from 7Hz to 30Hz. Would feeding Brownian or Pink noise through the system be good to test with too?
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
Thanks! I never mentioned the time crunch because I didn't want you to feel rushed or obligated. You're doing this as a favor and to help and you've already helped so much, and I feel like I've been asking so many questions. Just know that I really appreciate how much you've helped me!!

So, for the fake brain we mentioned earlier, I've been using an audio file generated in Audactiy with sine waves ranging from 7Hz to 30Hz. Would feeding Brownian or Pink noise through the system be good to test with too?
Brown/Pink noise would show you how well your filters are working. It will still output noise, but the values above and below the cutoffs of roughly 7 and 30Hz should be considerably less.
 

eboaylag

Jan 7, 2016
46
Joined
Jan 7, 2016
Messages
46
Brown/Pink noise would show you how well your filters are working. It will still output noise, but the values above and below the cutoffs of roughly 7 and 30Hz should be considerably less.

Alright, I'll use that to test.
I'm in the process of building the circuit now. I built the inst amp and the final amp gain stage together to see if they work, and they do. Going to go stage by stage now for the rest of the circuit! I'll let you know if I run into any problems.
 

eboaylag

Jan 7, 2016
46
Joined
Jan 7, 2016
Messages
46
The fake brain is giving me some difficulty.
The mp3 player I'm using (iPhone 5c) is said to have a voltage output from 0.8 to 1.2V. My voltage divider consists of a 100k and a 2.2 ohm resistor to bring the voltage between 17-26uV.
Plugging the fake brain setup (which has separate mp3s for Brownian noise, Pink noise, and sine waves that range from 7-30Hz) into my Arduino (which I'm currently using as an oscilloscope http://www.x-io.co.uk/serial-oscilloscope/) results in an analog reading of 16, which is the same as 0.07V. Unfortunately, I can't really test the fake brain with my voltmeter because it only reads to mV.

When I use my DC offset voltage divider in conjunction with the fake brain/voltage divider combo, I get readings of around 3V. But, with a voltmeter, I get readings of 2.526V.

When I plug just the mp3 player (no voltage divider) into the Arduino and press play on an mp3 file, I get crazy voltage shifts all the way up to about 200 analog which is 1V.

I don't know why my readings are varied so much, and I'm unsure of why my fake brain voltage divider doesn't seem to be working. I understand that the Arduino won't really be able to detect uV readings that I should be getting from the fake brain by itself, which is why I plugged the fake brain with the offset into the Arduino to see, but I got the unexpected value of 3V.

Do you have any suggestions about how to test it differently or as to what I'm doing wrong?
 
Top