Maker Pro
Maker Pro

EEG Question on Getting Data to Computer

LucidDragon

Feb 22, 2017
6
Joined
Feb 22, 2017
Messages
6
Hi all,


I have a general question on getting eeg data from circuit to a computer. So from a high level my plan for an eeg system is:
Electrodes => Amplifier => Analog-to-Digital-Converter => Digital Multiplexer => ????
Digital Mux is because I’ll have multiple channels, although I’ll test it with only one channel first.

I’m not sure how to go from digital mux to seeing the data on laptop. I’ve looked at a few projects, and a diy project (link below) uses a 3.5mm male-to-male cable to connect the circuit to a computer. However, the connection looks kinda dangerous and I don’t like this way of going from circuit to computer.
http://www.instructables.com/id/DIY-EEG-and-ECG-Circuit/
DWXKs-iWPdFlTJo3nshOxgRbX7t2senJL9eGC_bQngYX4AmJtH0WIKWCJaS6Gx-tOdGpMSrvR_MEK2UIUjw-vuopPl987XffclhLQZ5csild_56pyPzuBWg3sZMaMgLpio6JSA4L


Another OpenEEG project uses a 9-pin Serial Output to get data from circuit to computer. This way looks much better, but I only have a laptop which does not have a 9-pin serial output anywhere.
JpBJuqt_4z0g-S1ZgiR22Ew0sjwWlqoIhpLo4VdxS9F9ksK161ydxVbPoRSCDYA6FliG_xmpYMbchI7JbCK5RPSpZ4gEB0dCK8Ut3xibxciTNOGk0fqxTApmalykBqs1twgIEQfu


Is there anyway to go from a digital mux to seeing data on a laptop with a usb connection? Or do I need to use a development board like an arduino or a microcontroller/microprocessor to transfer the data to a computer. Also, once the data is transferred to a computer, is there any easy way of viewing the data? I planned on using some open source software, like perhaps the code from the diy or somewhere else and then editing it to fit my needs. But the diy code is for eeg data from a sound card. Any free open-source software that’s for eeg data via usb? Any help would be greatly appreciated, thank you!
 

hevans1944

Hop - AC8NS
Jun 21, 2012
4,878
Joined
Jun 21, 2012
Messages
4,878
Are you planing to build an EEG (Electroencephalogram) or an ECG aka EKG (Electrocardiogram) instrument? The EEG uses electrodes applied only to the scalp, because EEG signals are microvolts compared to the heart's millivolt electrical signals. It is difficult enough to record EEG from the brain through the skull and scalp without also adding interfering myoelectric signals from the heart and other muscles in the head, neck and limbs. So I will assume you will take the easy path first, and try to build an ECG instrument that will display heart activity on a personal computer screen.

The easiest approach is to provide separate analog low-level signal conditioning for each electrode. The signal conditioning involves amplification and bandwidth limiting to reject external noise sources before the signals are digitized. You should purchase or have available a decent two-channel digital storage oscilloscope (DSO) to aid in design, build, and troubleshooting of this front-end analog circuitry. Only after you obtain decent (observable) heart signals on the DSO should you proceed along the digital path.

In the dark ages of digital electronics, analog-to-digital converters of high resolution and speed were very expensive. For that reason alone, the ADC input was obtained by analog multiplexing of various inputs and a single digital data stream was processed. The digital processing was responsible for selecting which analog channel would be digitized at any given moment and then directing or storing the resulting digital data stream. This is still a viable option and has some advantages, but today it is cost-effective to dedicate an ADC to each analog input channel and then multiplex the digital outputs from several ADCs, none of which needs to be particularly fast or have high resolution. This has the important advantage of completely eliminating artifacts that can (and do) occur with analog signal multiplexing, glitches that occur during the switching from one channel to another and cannot be removed by later digital processing..

As for getting the digital data into your personal computer... you could go the Arduino route to create a serial data stream with header information to distinguish among channels. The actual hardware interface to a PC would normally occur with a serial data USB connection that would appear (with the appropriate driver software) as a serial data or COM port to your software. Visual BASIC is a relatively simple way to create a rolling display of multiple channels on your PC monitor, very similar to a commercial display, but you would be responsible for all the bells and whistles. I would make this a separate part of your project, perhaps creating data files that you send to a COM port for testing purposes.

If you already have an RS-232 serial data stream available from whatever is controlling the ADC or multiple ADCs, there are inexpensive devices available that will convert RS-232 to USB. Another possibility is Bluetooth communication between the ECG instrumentation (which must be isolated from mains power!) and the PC. You could also consider Wi-Fi but that seems needlessly complicated for such a low-bandwidth application, unless you want to stream to the Internet or the Cloud.

Sounds like a fun project!:D
 

Audioguru

Sep 24, 2016
3,656
Joined
Sep 24, 2016
Messages
3,656
It is extremely important to isolate the EEG probes from any mains powered items (the circuit or the computer) to avoid electrocuting the patient. Isolation is usually provided with an optical coupler (LED to photo-diode). Then the input circuit from the probes is battery-powered and it feeds the isolating couplers.

The circuit on the Instructable has many errors because the author seems to know nothing about electronics. The unshielded alligator wires, the breadboard, the opamps and the biasing are wrong. The 12 ohm and 220 ohm resistors are crazy. The schematic shows noisy old LM358 dual opamps but the parts list has TL084 quad opamps that need an additional negative power supply for them.
 

LucidDragon

Feb 22, 2017
6
Joined
Feb 22, 2017
Messages
6
Are you planing to build an EEG (Electroencephalogram) or an ECG aka EKG (Electrocardiogram) instrument? The EEG uses electrodes applied only to the scalp, because EEG signals are microvolts compared to the heart's millivolt electrical signals. It is difficult enough to record EEG from the brain through the skull and scalp without also adding interfering myoelectric signals from the heart and other muscles in the head, neck and limbs. So I will assume you will take the easy path first, and try to build an ECG instrument that will display heart activity on a personal computer screen.

The easiest approach is to provide separate analog low-level signal conditioning for each electrode. The signal conditioning involves amplification and bandwidth limiting to reject external noise sources before the signals are digitized. You should purchase or have available a decent two-channel digital storage oscilloscope (DSO) to aid in design, build, and troubleshooting of this front-end analog circuitry. Only after you obtain decent (observable) heart signals on the DSO should you proceed along the digital path.

In the dark ages of digital electronics, analog-to-digital converters of high resolution and speed were very expensive. For that reason alone, the ADC input was obtained by analog multiplexing of various inputs and a single digital data stream was processed. The digital processing was responsible for selecting which analog channel would be digitized at any given moment and then directing or storing the resulting digital data stream. This is still a viable option and has some advantages, but today it is cost-effective to dedicate an ADC to each analog input channel and then multiplex the digital outputs from several ADCs, none of which needs to be particularly fast or have high resolution. This has the important advantage of completely eliminating artifacts that can (and do) occur with analog signal multiplexing, glitches that occur during the switching from one channel to another and cannot be removed by later digital processing..

As for getting the digital data into your personal computer... you could go the Arduino route to create a serial data stream with header information to distinguish among channels. The actual hardware interface to a PC would normally occur with a serial data USB connection that would appear (with the appropriate driver software) as a serial data or COM port to your software. Visual BASIC is a relatively simple way to create a rolling display of multiple channels on your PC monitor, very similar to a commercial display, but you would be responsible for all the bells and whistles. I would make this a separate part of your project, perhaps creating data files that you send to a COM port for testing purposes.

If you already have an RS-232 serial data stream available from whatever is controlling the ADC or multiple ADCs, there are inexpensive devices available that will convert RS-232 to USB. Another possibility is Bluetooth communication between the ECG instrumentation (which must be isolated from mains power!) and the PC. You could also consider Wi-Fi but that seems needlessly complicated for such a low-bandwidth application, unless you want to stream to the Internet or the Cloud.

Sounds like a fun project!:D


I actually planned on building a EEG first. I know it’s difficult because all of the interference, but I think I found a good analog filter design for the eeg.

Testing with an oscilloscope is a very good idea. I initially planned to build a one channel system with analog + digital all at once and then test it, but that could lead to a lot of troubleshooting. I do have an oscilloscope available so I’ll first test the analog amplifier part of the circuit to make sure I get a good signals, and then move on to testing the digital portion.

For the ADC, I planned on using an ADS1299, since its designed for eeg/ekg measurements and has 8 channels. So if I wanted to build an 8 channel system, could I just use the ADS1299 since it has 8 channels.

I’m good with the analog portion to filter out each electrode, but I’m a bit confused about digital/computer portion, so I apologize if I ask any basic questions. How exactly do you go about using an Arduino for an eeg? For example, supposing I wanted to create a 8 channel system. Would it be best to use an ADC (ADS1299), then use a digital mux to multiplex the 8 channels, then connect this to an Arduino which would be programmed to control the ADC and the multiplexing and send the data to a computer via USB connection? Or is there another way to do this (everything from controlling adc to getting data on computer) without an Arduino?

I’ll check out visual basic. I think I’ve heard of it before but have never used it. I’m mainly experienced with Python and a little bit of C. Thanks for your response! I think I have an idea of what to do now: Electrodes => Amplifier/Filter (for each electrode) => ADC (for each channel) => Digital Mux => Arduino (controlling ADC, MUX, and sending data to computer) => Computer => Software (either visual basic or something else). And test each step before moving on.
 

LucidDragon

Feb 22, 2017
6
Joined
Feb 22, 2017
Messages
6
It is extremely important to isolate the EEG probes from any mains powered items (the circuit or the computer) to avoid electrocuting the patient. Isolation is usually provided with an optical coupler (LED to photo-diode). Then the input circuit from the probes is battery-powered and it feeds the isolating couplers.

The circuit on the Instructable has many errors because the author seems to know nothing about electronics. The unshielded alligator wires, the breadboard, the opamps and the biasing are wrong. The 12 ohm and 220 ohm resistors are crazy. The schematic shows noisy old LM358 dual opamps but the parts list has TL084 quad opamps that need an additional negative power supply for them.

Oh wow, didn't know it had that many errors in it. I'm not actually building that specific circuit, I was just using it an example for methods to go from an eeg circuit => data on computer. So are you saying that there should be optocoupler between the electrodes and the analog circuit (amps/filters).
 

Audioguru

Sep 24, 2016
3,656
Joined
Sep 24, 2016
Messages
3,656
Instructables have many errors. There is a horrible electronic one one with LEDs that has been copied many times and the author said he is 10 years old.
Yes, any electrical medical device MUST be isolated to prevent electrocution of the patient if the wiring goes is faulty.
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
May 8, 2012
4,960
Joined
May 8, 2012
Messages
4,960
IMHO Instructables should be renamed "Destructibles"! There are no checks or verification of anything posted there.

Chris
 

Audioguru

Sep 24, 2016
3,656
Joined
Sep 24, 2016
Messages
3,656
The signal at the probes is very small. It must have a battery-powered preamp to raise it high enough to drive an isolator.
 

LucidDragon

Feb 22, 2017
6
Joined
Feb 22, 2017
Messages
6

Audioguru

Sep 24, 2016
3,656
Joined
Sep 24, 2016
Messages
3,656
The "safety jack" does not prevent electrocution, it prevents strangulation. The very low output level of an electrode must be amplified by a battery-powered preamp to a level high enough to feed an opto-coupler.
 

hevans1944

Hop - AC8NS
Jun 21, 2012
4,878
Joined
Jun 21, 2012
Messages
4,878
It is extremely important to isolate the EEG probes from any mains powered items (the circuit or the computer) to avoid electrocuting the patient.
This should be the FIRST consideration BEFORE making electrical connections to the human body. It should be tested and verified that there is ZERO leakage current between the "patient" and a good earth ground. Do this BEFORE powering up ANYTHING. There should also be ZERO leakage current between "patient" and a good earth ground AFTER the analog instrumentation is powered on.

... Isolation is usually provided with an optical coupler (LED to photo-diode). Then the input circuit from the probes is battery-powered and it feeds the isolating couplers.
There are many ways to provide galvanic isolation, both optical and electromagnetic. For linear analog signals, as represented by EEG signals on the scalp, linear amplification and bandwidth filtering followed by analog-to-digital conversion is necessary before optically-coupled isolators (which are typically on/off devices, not linear devices) can be used. This front-end circuitry MUST be galvanically isolated from earth ground. A simple approach is to use battery power and digitization, followed by optical couplers driven by the DIGITAL signals to provide galvanic isolation.

It is possible to use an optical isolator as a linear coupler, but that approach is seldom taken because of stability and linearity problems that must be overcome. If you want to try this, a simple circuit will drive the input LED of the isolator with a variable current, say 4 to 20 mA, that is a function of the input signal. The output photo-transistor of the isolator then drives a voltage-to-frequency converter circuit whose pulse rate represents the input signal. A common 555 timer can be used to implement the V-to-F conversion. A software look-up table can be used to "linearize" the pulse frequency (measured with a microprocessor) as a function of input signal. Seems deceptively simple and inexpensive, but analog-to-digital converters are also cheap and simple. So why not do the ADC function first, then optically isolate the resulting digital signal?

... The circuit on the Instructable has many errors because the author seems to know nothing about electronics. The unshielded alligator wires, the breadboard, the opamps and the biasing are wrong. The 12 ohm and 220 ohm resistors are crazy. The schematic shows noisy old LM358 dual opamps but the parts list has TL084 quad opamps that need an additional negative power supply for them.
The "projects" submitted to Instructables are not vetted and vary in quality and correctness. It would be extremely foolish to attempt to build an EEG or ECG using monkey see, monkey do "information" derived from an Instructable. There are far better sources of reliable information and Google is your friend to find them. And you can get help here on EP too, but we expect you to do your own research first.

This is a very old Instructable, and the circuits have been previously discussed here. Although it does appear to be the work of a serious amateur, he bailed out on replying four years ago. If you read the long list of comments, many people had problems with the "monkey see, monkey do" philosophy of Instructables project duplication, for which Instructables is infamous. Besides the problems that @Audioguru pointed out, apparently the software was also full of errors and didn't work "out of the box". Some assembly required. Or maybe C, C++, or even BASIC.

So, if you want to build an EEG machine, take this Instructable only as a starting point for inspiration. There are good ideas therein, such as the use of instrumentation amplifiers, notch and bandpass filters, and battery operation for isolation. However, the use of a PC sound card in a battery-operated laptop computer for waveform digitization and galvanic isolation is a bit iffy. You will be tempted to use a line-powered power supply on the laptop, which may or may not provide galvanic isolation. Personally, I think it is a bit risky compared to an on-board ADC in the front-end circuits, with optical isolation of the digital signals between the front-end floating, battery-powered electronics and a USB serial port.

Building this project on a solderless breadboard is also likely to lead to a big fail. Microvolt signal processing needs point-to-point soldered connections and specific construction techniques. Brain wave signals are tiny and the subject is immersed and surrounded by much larger electrical fields from the mains wiring. Sophisticated techniques are required to recover the scalp potentials associated with brain-wave activity while rejecting all the ambient electrical noise. That noise includes myoelectric skin currents generated by muscle movement. I won't go so far as to say that the "patient" must be situated in a Faraday cage (or a conductive copper screen room) and paralyzed with strong drugs to prevent movement, but that would surely be an excellent "control" situation to test the EEG equipment against. Maybe just saying, "Hold still and concentrate" will be sufficient.

So are you saying that there should be optocoupler between the electrodes and the analog circuit (amps/filters).
That would difficult, if not impossible, to achieve.

Clearly you have NO understanding of galvanic isolation and why it is REQUIRED for "patient" safety. In the diagram you included with your first post, the entire diagram represents the "front end" of the EEG. This front-end needs to be galvanically isolated from earth ground (typically with optically-coupled isolators) at the point you labeled "9-pin Serial Output." This output represents the front-end connection to the real world. Anything can happen in the real world, including "patient" electrocution, without galvanic isolation.

Your EEG should be divided into two halves: a front-end signal conditioning half and an "everything else" half. The front-end includes the electrodes, the electrode leads, the instrumentation amplifier(s), the bandbass and notch filters, the Analog-to-Digital Converter (ADC), and the method used to galvanically isolate the front-end from the "real world". Typically, galvanic isolation is easily achieved by using the ADC digital output to drive one or more optically-coupled isolators. The input of the isolator is galvanically isolated from its output. When you attach the "patient" to the front-end using the electrodes, the "patient" becomes an integral part of the front-end circuitry. You DO NOT connect any part of the body of the "patient" to earth ground, nor do you allow any "leakage" currents to occur between the front-end and earth ground.

Your front-end circuitry will have a common to which all its signals and voltages are referenced. This common is floating. It is not connected to earth ground. Never connect the front-end common to anything (other than the "patient") in the real world. Place the front-end circuitry, including batteries, in a plastic enclosure to ensure this never happens. It is okay to place the plastic enclosure with the front-end circuitry inside a conductive outer metal box connected to earth ground for shielding purposes. It may even be necessary to do this to prevent coupling external signals from the real world (nearby mains wiring usually) into the front-end circuitry.

For advanced builders, it is possible to forego battery operation of the front-end and use an isolated line-powered power supply. After all, commercial EEG machines are line powered. However to attempt to build such a device as an amateur is highly risky. Medically qualified isolated power supplies are pricey. See here for examples. Specially constructed transformers and patient protection circuits are required to obtain safe and reliable isolation. Your typical wall-wart does not qualify, so don't even think about going there.
 

LucidDragon

Feb 22, 2017
6
Joined
Feb 22, 2017
Messages
6
@hevans1944
I understand the importance galvanic isolation from reading your comment. I'd rather not electrocute myself, so I'll definitely include an opto-isolator in my circuit. Also, I did plan on using a breadboard and still will, but if it doesn't work, I have experience using a soldering iron and pcb board so I'll just use those instead. Thanks for your comments, I have a much clearer picture of what to do now!
 

hevans1944

Hop - AC8NS
Jun 21, 2012
4,878
Joined
Jun 21, 2012
Messages
4,878
I know you will have a lot of fun with your project, and I certainly don't want to discourage you, but working with microvolt signals in the "wild" in a "floating" environment (for safety) is not easy.

Ideally, your scalp electrodes would only pick up signals related to brain-wave activity. Good luck with that! It is important to filter out mains low-frequency noise (50 or 60 Hz and their harmonics) as well as mains noise spikes from motors, electronic lighting, plasma televisions, nearby radio stations, and any other non-constant noise sources lest you be fooled into thinking you are "seeing" brain waves when what is actually recorded is something else.

One viable approach is to use a very high resolution ADC (24 bits or more) and digitize everything. Let the computer software sort it out. You then need only a low-pass filter with a cut-off frequency that is less than half the ADC sampling rate (Nyquist criterion) and enough dynamic range to capture everything from nanovolts to volts. Just a thought, because a low-res ADC (8 to 16 bits) with proper filtering ahead of it will work, and software enhancement is still possible. High-res ADCs tend to use delta-sigma topology and are relatively slow, but some microprocessors now offer them as a built-in peripheral.

If this were my project, I would at least consider using a shielding helmet over the "patient's" head after the electrodes are applied. Again, this would be a floating shield connected to the isolated circuit common, not to earth ground.

I routinely breadboard projects on solderless breadboards. And on more than one occasion that has come back to bite me in the ass, wasting hours of time troubleshooting a circuit that should work, but doesn't because of a faulty or intermittent breadboard connection. Nevertheless, I still use 'em for initial prototyping because they are incredibly convenient. Just be aware of their many limitations and what effect those limitations can have on your circuits, all of which is best learned from actual experience... either others or your own.
 
Top