Sonntag, 10. Februar 2008

My GSR-Monkey 0.9 beta

The GSR-Monkey is skin conductance measurement toy consisting of a combination of some pieces of electronics and the little program 'my GSR-Monkey'. The program was coded instead of a rather boring final homework for a beginners programming course at the Faculty for Psychology and Neuroscience at my university. The hardware (besides the PC itself) consists of four parts: the electrodes, two little amplifiers, a delphi/C++/etc programmable USB-Interface and last but not least a black and more or less evil looking monkey. All available at ebay within a students budget.

Main purpose of the program is to measure and record the skin conductance of up to two subjects (players...).
This is achieved by using the human body as a conductor for a reference voltage and measuring the passing voltage with the interface card. After passing the body the current is very low, so the signal has to be amplified to become measurable by the microchips analog to digital converter (ADC). The microchip sits on the interface card, and its implementation in Delphi is really very easy to understand and to program. It comes with some demo-sourcecode that explains all available functions and procedures.
I found myself very astonished when I finally made the first working tests with program and working hardware and saw that it really really worked. The signal is noisy and you have a quite narrow spectrum to measure but the overall system definitely does work. And it is really easy. I did not have had any mentionable electronics skills and my programming skills are limited to the very basics. So, this is really an easy project and I hope you enjoy reading my post and consider making your own GSR monkey, too.
  1. The amplifiers:
To make the skin conductance measurable I decided to go with these little out-of-the-box kits. (Seen here wired in their metal home.) I have seen better working amplifiers, but those will have to works for now. Easy to assemble, easy to modify and readily available. Additionally they have a small capacitor to dampen the 60Hz hum. You can basically take any 'lie detector' circuit which has (+-) three transistors and an LED which changes its brightness in correlation to the skin conductance. Just leave out the LED and connect one anolog port of your I/O board instead. (Note: you could also try to change the LED with a 10kOhm resistor and measure on both sides of it, I was told recently this was better but didn't try it yet.)

[manual kit: german]
[manual kit: dutch]

I do recommend to buy these at ebay (or elsewhere) because they are a lot cheaper than elsewhere. (Besides: the certain electronics company seems heavily overrated... way to expensive)

You can also go and build one for yourself. I built a prototype (seen on the right) which was described in a friend's book for kids 12yrs and up. Although it was essentially the same it didn't quite work that well. I'm sure for someone with a little knowledge in electronics it shouldn't be to hard to make some modifications. There are a lot of different approaches around, just google. You can also check out these links (which are all different versions) if you're interested: [ONE] [TWO] [THREE] [FOUR] and so on. You should definitely check out this very interesting and valueable LINKLIST (via waybackmachine).

2. The interface board: Velleman K8055

Nice little toy. I bought it just before the course to practice Delphi with it. (Because it said on the label: Programmable with Delphi.) You can get it on ebay for around 30 €. Even cheaper if used. It has:
5 digital inputs (which means you can attach 5 'real' physical switches which state you can detect via predefined procedures in your program),
8 digital outputs (which means there are 8 switches inside the card which you can control via procedures),
2 analog inputs (which means there are two voltmeters which transform a current into a simple integer value: 0-255 -> 8 bit. This can be useful for measuring a variety of other things like temperature, light intensity, force, heartbeat or the skin conductance... you could also write a program which controls the loudness of your speakers via a real knob, whatever you can imagine.)
2 analog outputs which do it exactly the opposite way around: they release the output you specify with a procedure

[Manufacturer: Specifications Velleman K8055]

3. The Electrodes

After experimenting a bit with other materials I decided to make my own silver/silverchloride (Ag/AgCl) electrodes. Nonchlorided electrodes on the skin can polarize after a while which means that they themselves work a bit like a battery. Charge is building up on the skin/electrode border. Although for this purpose it's not really an essential, we do not want this.
But making chlorided silver electrodes is really easy. Just cut a little piece of silver (--> ebay, old blingbling) and solder it to your electrode cable. Cover the back of it with some hotglue. Then you get yourself a glass of saturated salt solution. Use your electrodes as anode (+) and a little piece of silver as cathode and apply 1.5 V for approximately 90 sec. Your electrode should darken while the piece of silver bubbles. (Don't forget: Use a resistor somewhere to prevent short-circuiting your battery. See that only silver touches the salt-solution on the cathode (-) side. Use a non-metallic container. Electrode plates must be same size.)

Of course, there are other options including buying pre-geled adhesive electrodes on ebay or soldering small 1 or 2 cent pieces to your cable (as you can see on my 'prototype'). Which should do the trick...
You should also consider using some electrode-gel (2€ a bottle) and a little alcohol or abrasive gel to remove fat residues. (ebay, ebay, ebay...)

4. Shielding

Shielding is definitely an important issue. I had a lot of trouble with the 60 Hz noise generated by the 220V AC electricity in the standard home environment. Long, unshielded cable acts as antenna: The magnetic waves emitted from the electricity cables in rooms and houses induce a current in the electrode cables which are easily picked up by the amplifiers. You can spot this in the recordings which form appears as a band rather then as a line on the chart.
Filtering it out by software wouldn't work because if you want to filter something you must have a sampling rate of at least two times the highest filtered frequency which means to filter out 60hz 'mains hum' you must have hardware which can write at least 120 samples per second. (Read more about this here.) Our sampling rate is ca. 20 S/s.

I used shielded microphone cable for the electrodes and put the amplifiers in a metal box. It did a lot to the noise but it's still more than noticeable.
It may be interesting to experiment with different versions of wiring the body with the shielding or a ground wire. Maybe it is possible to construct a simple DRL-circuit like in EEG setups?

5. The Monkey

You can find an adequate device at your local 1€-shop (or similar). Mine was 75 c at 'blokker' and came with a sound module. The original plan was to equip the monkey with illuminated eyes and a vibrating motor which would have been used to give feedback to the player (eg. for conditioning the player to show a measurable response only when the monkeys eyes are green). This plan failed because I destroyed all my LEDs with the help of a full 9V. (Don't ask...) AFTER I wired them... (maybe in the next version.)

6. Software

The software 'my GSR-Monkey' is a small program written in Delphi at the end of this years course 'Programming with Delphi' at the faculty of psychology at the University of Maastricht.
It reads the data from the K8055, and writes this data to memory. This data is then plotted in a chart. Because the procedure that does this is an onTimer event it is fairly inaccurate. Nonetheless it should give a samplerate of about 20 samples per second.
As a little extra, there is a built in monkey game which is able to demonstrate that the device is actually working. After 100 samples of a 400 sample recording period a loud sound (roaring monkey, what else...) is presented to both players. You can clearly see (as in the screenshot) if one of both players wasn't prepared for that. The program decides who wins by averaging the first and the last 100 values for each player, calculating the distance and comparing both values.
Additionally there are some statistical calculations procedures to explore and see if the data looks alright. It gives you min, max (which are useful to see if values reach boundaries of 0/255), max-min, mean and variance of each players data. It is a necessary function: absolute values are only to be seen in the calibration test and in the saved data files, the graph only shows standardized values (ni-n1 in this case).

7. Problems:

There are a few problems associated with my setup which make it rather unfit for 'real' research purposes:
a) sampling rate:
The samplingrate of 20 Hz seems a bit too low. If you want to filter out mains hum you need at least 120 Hz. If there wasn't any signal noise it would be sufficient though.
b) range and resolution:
The K 8055 has a resolution of 8 bit on a range of 0-4 V. That means it's measurement has only 256 possible outcomes and it measures always only up to a maximum of 4 V. From the outcome, you can calculate the measured current (eg. value := 150 --> 4/256*150 --> ~0,016 *150 = 2,4) . The 'smallest noticable difference' is thus 0,016 V and we can measure only up to 4 V. This range is much less than we need with the consequence that within a 15 minute recording session the values can easily rise above our available range.
c) safety:
Experimenting with electrical current and humans connected to each other must always be considered dangerous. In the case is has to be done anyways, certain precautions have to be made such as using only appropriately shielded and grounded electronics. None of the devices used in this project can be considered such, therefore it is only operable on battery power and with battery powered laptops (-> 8.)
d) software-bugs:
There are still some minor bugs in the software left. As soon as the software is out of beta state it will be released on (without copyright protected illustrations) and if I can get further input there might be even a working 2.0 with new hardware one day.

To adress these problems the use another analog digital converter and another amplifier is indispensable. Possible candidates are so far:
- ModularEEG digital and analog board
very interesting: fully equipped for EEG/EKG/EOG/EMG 6 channels á 10 bit, 256 Hz samplerate, onboard filter, DRL circuit, opto galvanically isolated... but if you want to program something for it you have to access to the COM port (also referred to as: RS232, serial or d-sub9 connection) in Delphi which seemed a bit complicated for a beginner like me.

- the bigger brother of the K8055: Velleman K8061
the same thing but bigger and with a higher resolution (10bit) and it seems to be a lot faste

- an oscilloscope USB measuring card (used from ebay)
those things can measure up to many thousand times per second with a resolution of up to 16 bit

8. Safety issues:

I feel obliged to give a last quick warning if really somebody decides to build this: the k8055 should only be connected to a human via electrodes if the computer is operated ONLY by BATTERY! This is very important because the K8055 is not opto-galvanically isolated which means if there's a short-circuit or a lightning strikes a nearby power line you can get painfully electrocuted and even die.
Of course, the GSR monkey must be seen as an educational toy and not a scientific or even medical instrument.

If you have an ideas or questions do not hesitate to comment or write an email. There will also be a website some day.

bill of materials:
4 pieces of pure silver (or simple coins) ( 4ct - ca 5€)
1 analog/digital converter (my software only works w/ Velleman K8055) (20-40 €)
2 lie detector circuits (2,50 if you buy the components 10 € for complete kits)
2 9V batteries
4 m shielded microphone cable (or other lightweight, flexible, shielded cable) (6 €)
1 old telephonecable (min 3 pol) to connect amplifier w/ interfaceboard (0 €)

plugs to detach your electrodes from the amplifiers,
d-sub cable/plugs to disconnect amplifiers from I/O board,
metal box the thicker the better,
a switch to disconnect batteries from amplifiers,
velcro tapes for fingers instead of medical adhesive tape;

you will need:
soldering iron,
shrink tube,
some cables,

scissors, hammer, steel wool (for polishing) and a small anvil for preparing the silver,
holder for circuit board (better if you assemble the kit yourself),