EEG Open Source hardware and software search

A couple of months in the laboratory can frequently save a couple of hours in the library.

Frank Westheimer

And now we have Google 😉 In an attempt to avoid some of that time in the lab lining up a load of analogue filters I was tempted to go DSP, but I lack the DSP smarts to do this in hardware, so I turned to the Big G again. Turns out I didn’t spend enough time in the library.

An EEG has two technical challenges, the hardware of the signal-conditioning amplifiers, and then the display mechanism, which was an analogue filter bank and LEDs in the original Mind mirror, and a computer display afterwards. This is software, and in modern practice this hardware/software division is clear. There has been a lot of open source activity in this field, although as it happens I am still drawn to the retro.

Hardware

There are two big open source/hardware projects for EEG hardware that I can find. OpenBCI seems to be in the lead with a multichannel board that digitises 16 channels of EEG and sends this via Bluetooth to a computer. There is another one, OpenEEG, which seems to be at least 15 years old. Anybody who still keeps their introductory material in Adobe Flash has clearly not kept up with the times.1

The obvious one to favour is OpenBCI, but there’s one small problem. It’s shockingly expensive. A Cyton + Daisy RF module gives me an impressive 16 channels for about a thousand dollars. In comparison, the Vilistus 4 interface is £650 (£850 with Bluetooth).

£540? You have to be kidding, right?

Unfortunately in the latter case one has to buy a 1984 DOS looking piece of software for £540, which is apparently the most advanced Mind Mirror program yet. Even if I were a billionaire it would pain me to hand over £540 for something that looks like an old program I wrote for a BBC Micro in the late 1980s tracking galvanic skin resistance. But compared to OpenBCI their hardware is pretty good value.

OpenEEG has the problem of being 10-15 years old. The schematic is from 2003, but pretty much how I would have done it. It doesn’t base it all on a proprietary chip, if I blow the input up the INA114P can be changed out for about £7. It’s available for ~£75 assembled, which is sort of within the groove. I’m kind of up to £200 interested in this, not much more. It’s only two channel. I could get the digital interface for another £50.

So although it’s old, OpenEEG matches my budget and requirements better. There’s not much point in me trying to wrangle the analogue front-end myself, unless I use active electrodes, in which case I can lose the INA114P and I may as well make the analogue back-end LPF of OpenEEG on veroboard

Software

Looks like I am late to the party and EEGMIR from Jim Peters on the openEEG project had largely solved this for me more than 10 years ago. Now I just said a lot of rude things about Vilnius’s most advanced MM software looking fugly, and EEGMIR isn’t a thing of beauty either

but you can’t grouse about the price, if it works 😉 Instant win. Since it runs on Linux it will be Raspberry Pi friendly, in theory, though I have no idea of how much Linux has changed in the intervening 14 years. The nice thing about the Pi is all those GPIO pins – so I can hate on this display all I like, but if I want it to be on LEDs I can do it. And Jim Peters seems to be using IIR filters from the filter description language. I would need to purchase the £50 EEG Digital board or hack a PIC or an Arduino to output the openEEG type 2 serial data format. A 16F88 would probably cope a treat on two channels. Continue reading “EEG Open Source hardware and software search”

First evidence for higher state of consciousness found at Imperial

It’s heartening to see that all that drinking, listening to Pink Floyd and setting the world to rights many years ago at my alma mater has finally borne fruit at Imperial

Researchers have uncovered the first scientific evidence of a ‘higher’ state of consciousness.

In the study, neuroscientists observed a sustained increase in the diversity of brain signals of people under the influence of psychedelic drugs, compared with when they were in a normal ‘awake and aware’ state.

This measure of the complexity of brain activity – called neural signal diversity – provides an index of the level of someone’s consciousness.

Scientists have shown that people who are awake have more diverse neural activity using this scale than those who are asleep. Previous studies have tended to focus on lowered states of consciousness, such as when people are asleep, under anaesthesia, or are in a ‘vegetative’ state.

Must’ve been an interesting assignment.

For the study, Michael Schartner, Dr Adam Barrett and Professor Seth of the Sackler Centre reanalysed data that had previously been collected by Imperial College London and the University of Cardiff in which healthy volunteers were given one of three drugs known to induce a psychedelic state: psilocybin, ketamine and LSD.

Poor old Max Cade was there in the 1970s, although without the psychedelic drugs, and elementary observation of the likes of Syd Barrett on acid or listening to some of the, er, stranger Floyd tracks might have shown that LSD alters consciousness, but it’s good to have independent corroboration. Exactly why they chose to use a magnetic imaging technique rather than, say EEG but good for them. Slightly embarrassing for Imperial who did the initial work, it appeared they failed to spot the differences, and it was the University of Sussex who reprocessed the data. Perhaps post-processing had got more powerful since the original results.

A good year for Nightingales, locally

First I hear a pair at Newbourne Springs, then one at Orwell Country Park

Orwell Country Park, not really classic Nightingale habitat of low scrub

 

and finally one at Mill Stream Nature reserve

Three separate places with a fair amount of human and dog interference in less than a week.

The BTO doesn’t seem to agree that it’s a good year countrywide – Nightingale reporting seems lower than the historical average

Nightingal reporting seems down accordign to Birdtrack

Building the Mind Mirror filter bank

Drafting out the Mind Mirror analogue filters, scaling values to the nearest good combination of series resistors looks good at 1% tolerances of resistors and capacitances, according to LTspice

Monte Carlo simulation at 1% tolerance

but realistically the capacitance tolerances are 10% although resistors are 5%, and that’s makes a mess of some channels

Monte Carlo simulation with resistors at 5%, capacitors at 10%

in particular the 6,7.5, 9, 10.5, 12.5 and 19, 24, 30 and 38Hz channels. These are simulated using multiple-feedback bandpass filters (MFBP). I then simulated the same spread on the highest Q so most sensitive 9Hz band on the dual amplifier bandpass topology (DABP) and the state variable topology (SVBP) using three opamps per stage.

the DABP and SVBP simulated filters, SVBP on top. The funky values are so the Monte Carlo simulation can tinker with the values between runs

Both the latter are meant to have a lower sensitivity to tolerances, and both have the advantage of having a defined gain, whereas the MFBP gain varies quite dramatically with fractional bandwidth and Q.

sensitivity of the topologies, blue is the DABP, green is the MFBP and red is the SVBP

There’s not much to be won here with the different topologies regarding sensitivity to tolerances, which surprised me. Williams states that the DABP is less sensitive to component tolerances than the MFBP and the SVBP less still. Examining the SVBP I got a variation in level of 5dB, the MFBP of 2.4dB and the DABP of 3.07. I have the suspicion I will need to tune these, in which case the DABP is easier, since the MFBP has interaction between fc and Q in tuning, as well as a wider spread of resistor values with Q² as opposed to with Q in the DABP. However, that is 14ch × 2 stages × 2 sides = 56 pots or S.O.T. resistors 😉 As they said

The original analogue filters in Mind Mirrors 1 and 2 were precise but expensive to manufacture. The digital Band Pass filters parameters were modelled on the band pass characteristics of the analogue filters, and were able to more accurately guarantee the performance of the filters.

Lining up the analogue filters isn’t too hard – Williams [ref]Electronic Filter Design Handbook, A Williams, McGraw-Hill, 1981, p5-46[/ref] says set the input frequency to be the desired centre frequency, monitor the input and output of the filter on a scope set to XY mode and adjust filter centre frequency until the Lissajous figure closes to a straight line. The thought of doing this 56 times does not fill me with joy, however. So one last time, how about DSP? Continue reading “Building the Mind Mirror filter bank”

Mind Mirror reverse engineering

The are three functional blocks in the Mind Mirror – the electrode positioning and pickup, the filter banks and the display. As far as the electrode position goes I’d follow the original T5-O1 and T6-O2 placement.

There are few pictures of the Mind Mirror, because the first model was produced in June 1976, and presumably the computer version was developed in the mid 1980s. The Dragon Project Trust has some pictures from Paul Devereux’s 1970s monitoring project at the Rollright Stones.1including a few photos of it in use.

Display

Mind mirror in use with the Dragon Project

The display was each frequency band presented on a linear voltage scale via 16 LEDs in dot mode, presumably to save power. This was replicated 24 times, 12 for each frequency band and in two channels, which already tells me there is a difference between the original hardware Mind Mirror 1 and the software variants – the filter specs I got were for the MM3 developed in 1992. It appears the MM1 used red and green LEDs for the different bands.

In the 1970s LEDs had only just come in and there were all sorts of display chips. I like the Telefunken U1096 which Charlieplexed 30 LEDs off 9 pins, but this and most of the 1970s chips are hopelessly obsolete. My choices now are either digitise and use an Arduino or a PIC, or use the LM3914. The LM3914 is only 10 output so it makes sense to cascade two, getting a 20-LED bargraph. I then rectify the output of the filters and feed that. A PIC would also do the job, perhaps better by controlling the meter dynamics digitally and multiplexing one 8-bit port across two banks of LEDs would give a 16dot display. It would also enable a hold command and be able to write out the digital value for a recording display. But it’ll be dearer…

Filter channels

Looking at the DPT machine, the original set of 12 frequencies on the Mind Mirror 1 can be seen. Let’s take a look

The overlaps are less even than they are in the new version, below

so it probably makes sense to make the display modular and provision 14 slots. I’ve now located a copy of Blundell’s Book

In which he has the technical specifications – the Dragon Project pic shows the MM1, but there was a Mind Mirror 2 which has the 14 more evenly spaced channels, which is shown on the cover of the book.

elsewhere it says the EMG channel displaying interference from the powerful neck muscles is showing 100-200 Hz. While the response of the bandpass filters is 40dB down an octave out, the response flattens out to the limiting case of 12dB/octave. However, a display resolution of 5% (if 20 LEDs are used) gives a minimum response of -26dB so that doesn’t matter.

Mind Mirror Filter sections

This is all low frequency stuff. I derived my simulation by calculating the staggered LC elements of a two-pole Bessel bandpass filter. For example, the 6Hz filter is this

and I’m immediately in trouble for the 7H inductors, and the 90µF capacitor isn’t that handy either, I’m not going to find these inductors at Digikey. I had been thinking along the lines of the LMF100 switched capacitor filter, but decided to compute the values for a standard multiple feedback bandpass filter(MFBP). These sweat a single stage and have the fewest components for a given shape, the downside is they can easily push the gain-bandwidth of the opamp, particularly as there is no independent control of the gain, which can end up quite high.

These are Bessel filters with low Q requirements, the highest I computed was <7. Williams[ref]Electronic Filter Design Handbook, A Williams, McGraw-Hill, 1981, p5-43 Equn 5-70[/ref] indicates the gain is 2Q^2 at resonance, so the gain of the amplifier needs to be a lot more than this. At such low frequencies this is doable, so choosing a value of C at 1µF and 0.47µF I can use normal MFBPs without resorting to switched capacitor filters. I was surprised but chuffed.

Amplifier

I was thinking of using something like OpenBCI’s Ganglion board which would be very good, but it is dear at $200 and I don’t need the digital whizzery, I will be using an analogue system. I will probably pinch their idea of using instrumentation amplifiers, which have come down a lot in price. I will wing this and assume the front end is soluble, after all it was in 1976 and things have got much better and cheaper since. Instrumentation amps are in the £5-£10 mark, they were much dearer way back then.

Next – deriving and simulating  the filter bank and the effect of tolerances.


  1. The Dragon Project was a fascinating 10-year attempt starting in 1977 to monitor physical characteristics around megalithic monuments, but details of that part of the work are tantalisingly scarce, Devereux seems to have come to the conclusion the physical monitoring delivered a null result. 

Making a Mind Mirror EEG

Way back in the 1970s there was an EEG device called the Mind Mirror, which was a spectral display of the brain activity of the two sides of the user’s brain. This was in a world without desktop computers and smartphones, no DSP, and used analogue electronics to get the display of 14 frequency sub-bands in rows of 16 LEDs. Designed by Geoff Blundell in association with Max Cade, this was used to look at the brainwaves of people in meditative states.

the original 1970s device
Kindle version of this book

If you’re a materialist rationalist, you may as well stop reading now because there’s a fair amount of woo-woo in this. I personally like the combination of tech and woo-woo, but each to their own 🙂 The area of biofeedback has a lot of fantastic claims, but ranges from the sinple use of relaxation tapes through all sorts of werd and wonderful ideas of changing consciousness by feeding back signals from the body.

Although the development of the Mind Mirror was largely empirical, the studies leading to it’s development did at least use many subjects and try and control many of the variables.

In the 1970s Max Cade was studying biofeedback using skin resistance, then in 1973 using a single channel EEG, with a single channel display where the filters were switchable to present a choice of frequency bands, one at a time. He ran this with a bunch of people chosen for experience with meditation, the long-form description is in the book “The Awakened Mind” by Nona Coxhead. Basically they observed similarities in the mix of brain activity between different people in similar states of consciousness.

The trouble with using an EEG is that it’s like trying to get information about a crowd by recording the amplitude of the sound picked up a distance away, but since there’s no mind-jack in the side of people’s heads it’s the best to be had. Nowadays you can get spatial detail of what’s going on in the brain using fMRI but this is still a macro observation, in that case of changes in blood flow as a result of brain activity. The EEG is picking up the electrical signals from the brain, but averaged over many neurons.

There was also a more specific book on the Mind Mirror called The Meaning of EEG by Geoff Blundell which I gather was the instruction manual, but there’s not much on that to be found, apart from a cover picture.

Why the Mind Mirror – forty years of better tech has overtaken it surely?

Getting an EEG is a lot easier now. Get yourself onto OpenBCI and you’ll have no end of fascinating stuff to play with, or review some more approaches here. Looks to me like the tech has been sorted.

But at the end of the day, it’s all just sensor data. We are taking the faint signals averaged across a load of wetware and insulating material and displaying them on the screen. Woo-hoo, but so what?  It’s all just numbers on a screen, there is no meaning to it. What Cade and Blundell did was actually trial their machine on real people –

Maxwell Cade and Geoff Blundell calibrated the first prototype Mind Mirrors on people with known advanced training in mind states and were able to bridge the gap between internal descriptions and measurable EEG states on the brain.

The limitations of their hardware led them to focus on two channels, near the occipital lobe, and they experimented to try and get some reproducibility and correlation with different states of consciousness/relaxation/meditation. It’s this part of the puzzle that’s missing from the geeky big data stuff out there, and without that it’s just data, not information. As lifehacker says

Of course, self-awareness is a big part of both therapy and philosophy. It’s also the basis of the quantified self movement , which assumes that if you collect data about yourself you can make improvements based on that data.

The trouble with quantification is that data is not knowledge and knowledge is not wisdom. Where Cade and Blundell scored versus a lot of quantified self data is they looked at the quantified data across many people, trying to correlate it with characteristics of self-awareness, or at least chilled-outness.

The advantages of the Mind Mirror is partly due to the simplicity of the rig, picking up signals from two channels and displaying them. It meant that the machine was portable, but it also makes correlation of the display with other people’s states of mind a lot easier than trying to parse the welter of data from, say, a 16 channel EEG display. The value of the Mind Mirror to my eyes is the combination of work of Cade and his successors with this particular methodology and filter bank, and the fact that it isn’t limited to a particular place.

1970s image of Mind Mirror used in the field

Reverse engineering the Mind Mirror

There’s a lot of good information about the machine on Mind Mirror EEG.

Mind Mirror EEG are good enough to give us the filter frequency specifications indirectly, and more directly here.

I converted these to a staggered tuned second order bandpass filter and simulated this.

And you can immediately see that they adjusted the centre frequencies unevenly, presumably to get more resolution in the alpha and beta wave regions. This is a log frequency display, and the obvious way is to spread the channels evenly keeping a constant fractional bandwidth.

Now the obvious way to do this nowadays is with a PC and a FFT, and you can buy a Mind Mirror from Vilistius  that’s probably how the latest incarnation of this works. But it is £1.5k, and it uses a computer for the display, which is not a thing of beauty.

the software Mind Mirror display. It’s a little bit gonzo DOS 1984 style for me, but the £1500 is the killer, although to be honest it’s not an unreasonable price for such a device made in small numbers given how dear the OpenBCI boards are.

I don’t find computers and smartphones conducive to relaxation and meditation. They are good at what they do, but relaxation not one of them. Whereas the original Mind Mirror was self-contained and used LEDs for a display.

In the next part I will look at what can be gleaned about the Mind Mirror hardware.

 

Spinning AC mains frequency display

The guys at dynamic demand have a meter showing the frequency error of the UK AC mains, which shows typical values ranging between 49.9 and 50.1. A digital count will do that a treat, but the trouble with digital displays is they have no soul, IMO.

Frahm vibrating reed frequency meter has a steampunk charm of its own, but lacks precision to < 1%

In the past there were all sorts of weird and wacky methods of displaying measured variables, analogue sensors sometimes wear their heart on their sleeves, like the vibrating reed frequency meter.This doesn’t have the frequency precision needed, however.

The click of a Geiger counter is well known, but old-school Geiger counters also had dekatron tube displays, which whizzed round faster at high rates and inched round at slow rates. These tube displays, where a red glow would move clockwise round the tube, was a good, intuitive indication of count rate. I wanted something like that.

So my idea is for a rate counter. A single ring of red LEDs, one of which is lit. If the mains is too fast the lit one will progress clockwise, if too slow, it will move anticlockwise. A set of red LEDs on black perspex is hard to get a good picture of, it looks better than that in real life. Normally it spins a lot faster, I had to wait for a point close to 50Hz to get both too low and too high frequency.

This is built largely out of a 16F628 PIC. The mains is run through a wall-wart 9V transformer, which is an increasingly rare beast nowadays. Often old land-line phones and answering machines had low-voltage AC power supplies, but switch-modes are far more common now.

Schematic

The 9V is half-wave rectified, clipped to 2V with a LED and sliced with the comparator in the PIC, with the voltage regulator module providing the other side. Internally the transition copies the state of a 16-way counter fed from a 6400Hz clock derived from the 4MHz crystal. There isn’t an integer relationship between 4MHz and 6400 Hz so I used Roman Blacks Bresenham timing ideas to toggle a divide-by 76 and 77 counter using TMR1, I confess I got it roughly right by calculation and then tinkered with the ratio while watching the dynamic demand display to fine-tune the 50Hz point. My null is ever so slightly higher than theirs, but it’s good enough IMO.

I like the effect, it’s more for its ornamental nature, it’s not like I will be calling up Sizewell to throw some more fuel pellets into the reactor, but it’s a sort of connection with what my fellow Britons are up to and there’s a surprising amount of variation moment to moment. It will be interesting to see if a ad break in a big TV program is perceptible, the speed of rotation reacts quickly to frequency changes, a little faster that dynamicdisplay’s meter

Code and schematic

at Github

Over at Return to Zero they’re counting over 100 cycles to get a digital display. Which is fine as far as it goes, but doesn’t have the at-a-glance feel of the spinning LED display IMO. I tip my hat to RTZ for accuracy, if you need to really know what the frequency is, there’s nothing wrong with that solution at all.

laser cutting rather than drilling

Construction was Veroboard and because I’m far too imprecise a craftsman to make the display right I used Razorlab to laser cut the holes and panels from black Perspex, controlled by an Inkscape drawing. That worked remarkably well; I’m tempted to make more designs that way and it may be a solution for decent looking front panels too. The display really had to be regular and even to look any good, and Inkscape made that easy.

Olympus LS-10 remote control success

I’d experimented with the wired remote for the Olympus LS- series recorders before. I have an Olympus LS-10 and an LS-14, and previous experiments showed I could make this work in principle. There’s a big gap between making it work on the bench and getting it to work in the field, however. This is the next step of boxing it up and making it stand alone.

16F628 PIC is fitted into the space of two batteries in a 4-way battery box, giving me a small box with battery holder and on/off switch. A 32kHz watch crystal gives an easy integer divide down to seconds and then hours, and reduces the power drawn by the PIC and lets me drop down to 2V Vcc and stay in spec over the industrial temperature range.

Either my LS10 is knackered or it never was compatible with Olympus’s wireless remote, it doesn’t provide 3.3V power on the plug tip, so I have to power the PIC 16F628 from two NiMH cells, which means I am short of headroom for 3.3V because there’s a 0.9V difference. I’d expect the PIC to drag the remote control line, which rests at 3.3V down to ~ 3V (2.4V VCC + 0.6V input protection diode drop)

I used a diode for the stop command pulling to ground, which still works with that diode drop, so the drive circuit is

Driving the 3V3 LS10 from a 2.4V PIC

RA4 is an open-drain connection, I figured I would chance the forward-biasing of the input protection diodes via the 100k. It works fine, at least at room temp – a 100ms pull to gnd via RA4 starts the recording, and then a 100ms pull to ground of RA2 stops the recording. Pins are switched to hi-Z inputs when not active. I guess the 3V3 from the LS10 has to go through two diode drops now to get to the 2.4V rail (diode shown and the input protection diode), and this is enough to let it float OK.

I got it to start the recorder at 4am, which is too early, but recording for two hours got me this recording at about 5:30 am of the local birds. I hear Great tit, Robin, Blackbird, some sort of gull, Wren, Woodpigeon, Crow, in that lot.

Using a 3.5mm socket as a workaround for the fiddly 4-pole 2.5mm jack plug – it’s a lot easier to wire a socket than a 4-pole plug, and I got a 4-pole 3.5mm jack to 4-pole 2.5mm jack cable from Ebay. Wiring the 4-way socket is dead easy now, and saves having a flying lead from the box.

In search of microphone weatherproofing ideas

I need to now find a way to get a reasonably weatherproof microphone. Looking at how B&K do this in the manual for the UA1404 the way to go is to use a small raincover just over the mic capsule

B&K’s solution to weatherproofing

Their mention of birds makes me thing this is very close to a mesh nut feeder – I could put horticultural fleece around the mesh and use the top cap as a rain guard. Another option is to go minimalist, recess an omni electret capsule in something like a plastic bottle cap. I’d have thought that the cavity of the raincover would cause dreadful resonances, but if it is say 2cm diameter that would be a wavelength of 330/.02 ~ 16kHz – perhaps theirs is 0.5cm keeping this down to ¼ wavelength. Where this would score is it’s small, and electret mic capsules are cheap so I could afford to lose some. I can take the line that I’ll omit the big foam guard and use a piece of horticultural fleece across the cap, this makes a reasonable wind baffle, and I’m not going to get a good recording if the wind is over 5 mph anyway because of the hiss of the wind in the trees even if I were to keep wind blast out of the mics.

I am thinking of using a small Dribox to rig the recorder and timer, and sample some birdsong from other places. A pair of AAs run the timer for at least three days and the power drain of the LS10 on standby is also low, probably good for a couple of days, but I don’t have more than four hours of recording time on the LS10, it is 2Gb. So I can live with that – the Dribox has enough room for a bigger battery if that starts to look necessary.

Urban birdsong – Brunswick Rd rec dawn chorus

Ipswich council did a nice job making this rec better for wildlife while keeping the facilities, and it’s a pleasant little oasis of birdlife. The birds are getting up earlier than the Sunday traffic on the ring road, this recording is a lovely piece of avian exuberance and joie de vivre.

Recording started at 5:30 am

Brunswick Road rec wildlife area