Sunday, 24 February 2013

Epileptic Seizure Detector (3)

I installed an accelerometer on the underside of the floorboard where my son sleeps to see if there is any chance of detecting him having an epileptic seizure by the vibrations induced in the floor.
I used the software for the seizure detector that I have been working with before (see earlier post).

The software logs data to an SD card in Comma-Separated-Values (CSV) format, recording the raw accelerometer reading, and the calculated spectrum once per second.  This left me with 26 MB of data to analyse after running it all night.....

I wrote a little script in Python that uses the matplotlib library to visualise it.   I create a 2 dimensional array where there is one column for each record in the file (ie once column per second).  The rows are the frequency bins from the fourier transform.  The values in the array are the amplitude of the spectral component from the fourier transform.
The idea is that I can look for periods where I have seen high levels of vibration at different frequencies to see if it could detect a seizure.  The results are shown below:
Here you can see the background noise of a few counts in the 1-7 Hz range.   The 13-15Hz signal is a mystery to me.  I wonder if it is the resonant frequency of our house?
Up to 170 sec is just me walking around the room - discouragingly little response - maybe something at about 10 Hz.  This is followed by me sitting still on the floorboard up to ~200 seconds (The 10 Hz signal disappears?)
The period at ~200 seconds is me stamping vigorously on the floorboard, to prove that the system is alive.
Unfortunately the period after 200 seconds is me lying on the floorboard shaking as vigorously as I could, and it is indistinguishable from the normal activity before 170 seconds.

So, I think attaching a simple IC accelerometer to a floorboard will not work - attaching it directly to the patient's forearm looks very promising, but not the floorboard.

I am working on an audio breathing detector now as the next non-contact option....

The code to analyse the data and produce the above chart can be found on github.  It uses the excellent matplotlib scientific visualisation package.

Wednesday, 13 February 2013

Epileptic Seizure Detector (2)

Update to add another spectrum...

I have been working on setting up the Epileptic Seizure Detector.  I tried wearing it for a while, and simulating the shaking associated with a tonic-clonic seizure.   Some example spectra collected on the memory card are shown below:
This shows that the background noise level is at about 4 counts.   
Wearing the accelerometer on the biscep gives a peak up to about 8 counts at 7 Hz, but it is not well defined.  
Wearing the accelerometer on the wrist gives a much more well defined peak at 6-7 Hz. (and it raised an alarm nicely).

I have also tried an ADXL345 digital accelerometer.  The performance is similar to the analogue one, but I think it may be slightly more sensitive.  Example spectra with the accelerometer attached to the biscep are shown below.  ONe is a simulated fit.  The other is a false alarm going down the stairs.  Not that much difference!


Therefore I think there is scope for this set up to work if it is worn as a wrist watch, but just attaching it to other parts of the body may not be sensitive enough.

I wonder if I could make a wrist sensor that is watch sized, with a wireless link to a processor / alarm unit?

Not sure if I will be able to persuade Benjamin to wear a wrist sensor though....Might have to think about microphones.

Saturday, 9 February 2013

Soldering onto Surface Mount ICs

I recently bought an accelerometer IC to use on my epileptic seizure detector project.  It is a tiny surface mount device as you can see below.
I gave a lot of thought to how to connect wires to it.  I did consider conductive glue, but it would be difficult to hold them all still for long enough for it to set, so I went back to solder.  This is how I did it...

1.  Mount the IC onto stripboard using apoxy adhesive:

2.  While the glue is setting, modify the soldering iron by wrapping some 1mm2 copper wire around the tip to give a very fine tip.  Use solder to increase the heat transfer between the wire and the tip:

3.  Tin the solder pads on the IC, using some very fine solder (I got some 32swg solder off ebay).

4.  Obtain some very fine copper wire (I disassembled some cheap alarm flexible cable, and used strands from that).

5.  Hold a strand of wire onto a solder pad, and touch it with the soldering iron to melt the solder and create the joint.

6.  Repeat for all connections:


7.  Route the fine wires to the copper tracks, and solder on.  I used the insulation from the original alarm  cable to prevent short circuits:

Fiddly, and not very neat, but it worked for me - it is being used in my prototype epileptic seizure detector.



Epileptic Seizure Detector (1)

Our son worried us a bit a couple of weeks ago when he had quite a nasty fit, so I have been thinking about making an alarm to warn a carer that a person in their charge is having a seizure.

There are a few different ways to do this that I have thought of:

  1. Detect Movement using an accelerometer
  2. Detect the sounds associated with the movement using a microphone
  3. Monitor the movement with a CCTV camera and use image processing to detect the abnormal movement.
I am trying option 1 (accelerometer) first, but am working on the CCTV approach in parallel by learning OpenCV.

Because our son is autistic, it will be very difficult to get him to wear a device, so I hope to detect movement through the floorboard where he sleeps, but this will be much less sensitive than detecting it directly.  Therefore, this first proof of concept version is working by attaching the accelerometer to a limb to see if I can get it working.  The issues with it are:
  1. We do not want false alarms caused by normal movement - I am addressing this by using a fourier transform to filter out only a range of frequencies of movement, in the hope that I can select the characteristic shaking of a seizure, but not detect too much normal movement.
  2. A quick shake should not raise an alarm, so to set off an alarm the acceleration in the appropriate frequency band should be more than a threshold value for a specified length of time (3 sec currently).  This will give a warning 'pip'.   If the shaking continues for 10 sec, it raises a buzzing alarm.
  3. Sensitivity will be a problem for detecting it through the floor - will need to work on that another evening.
The system uses an Arduino microcontroller, connected to a Freescale MMA7361 three axis accelerometer.   The accelerometer is a tiny (5mm x 3mm) surface mount device, so soldering it is a challenge - you can see how I did it here.
To enable data logging so I can tune it to get the frequency response, threshold etc. the arduino is also connected to a real time clock module and a SD card module.
The completed prototype is shown below:
The code is in my Arduino Projects github repository.

And here is a simple demonstration of it working - you can hear the warning 'pip' and the alarm 'buzz' in the background when I shake my arm to simulate a seizure. 
Still quite a bit of work to do - build it on stripboard to make it more robust, then try attaching it to the floor and seeing if I can detect any signal from someone shaking.  If not, I will have to minaturise it to make it wearable, and train Benjamin to wear it....


Monday, 28 January 2013

Getting Started with Raspberry Pi

I have had a Raspberry Pi single board computer in a box in the attic for a few months - I had forgotten that I had pre-ordered it, and was busy with the Arduino solar panel power meter when it arrived, so didn't do anything with it.

Well, I know that the wheelchair project will need some brackets to mount motors, lights, GPS receiver etc., and have been reading about 3d printing, and thought it would be a handy excuse err... a necessary part of the project, to try out 3d printing for these parts.   And the 3d printer will need a little print server, so I don't tie up my laptop when it is printing.   So, I am dusting off the Raspberry Pi and having a go at setting it up to see if it will be able to do that.

These are my notes, so that I can do it again if I accidentally break it...

Basic Set-Up

  • Download the Debian root filesystem image from the Raspberry Pi web site.
  • Unzip the archive to give us 2012-12-16-wheezy-raspbian.img.
  • Copy it to a 4GB SD card using dd if=2012-12-16-wheezy-raspbian.img of=/dev/sdb.  (Note, write to whole SD card, not to a partition - sdb, not sdb1).
  • Put SD card into raspberry pi, connect HDMI to TV in living room and switch on.
  • Success - boot messages displayed on TV
  • Failure - it lands in an interactive set-up utility, and I don't have a keyboard for it - doh....maybe I should have gone for openWRT.
  • Try different approach - forget the TV now I know it boots, and just connect it up to the network.  It gets is IP address from my router, and I can now ssh into it, with username pi, password raspberry.
  • Now I can run sudo rasppi-config, which is the same config utility that came up on the TV monitor.  Used this to expand root filesystem to fill SD card, but didn't see much point in changing anything else (will sort out a user in a minute and do away with the pi user).

3d Printing Stuff

  • Followed instructions at https://github.com/w-A-L-L-e/printerface, with the following exceptions:
  • mv kliment-Printrun-71e5da0/ printrun
  • Node-js needed sudo apt-get install nodejs not node-js.
  • Had to do sudo ln -s /usr/bin/nodejs /usr/bin/node to get npm install.sh to work.
  • needed to  curl https://npmjs.org/install.sh | sudo sh. to avoid directory access errors.
  • The forever@0.9.2 failed to install with lots of errors, but npm install -g forever worked.
  • But starting printerface using forever failed with an error on line 404 (monitor.send).
  • node printerface.js works though - web interface appears on port 8080.
Will update when I get further....

Sunday, 6 January 2013

Design Calcs for Power Assisted Wheelchair

Update to correct my deliberate mistake...Answer is still about the same, but I am now designing to a 1 in 3 (18 deg) gradient.

A very quick go at some preliminary design calculations for the power assisted cross country wheelchair.
The idea is that the motor should be capable of preventing it slipping backwards on a 18 deg incline (fairly arbitrary, but needed to make a design assumption).
  • Based on an assumed mass of 50kg, would give a weight of 490 N.
  • This resolves to a force down the 18deg slope of 152 N.
  • Which is equivalent of a torque on an 18" (0.46m) od wheel of 85x0.46 = 35 Nm.
Alas this is more than twice the torque delivered by the bicycle hub motor (15 Nm).  Now the motor is likely to have internal gears, but it could be tricky to make some new ones to reduce its speed and increase its torque... [Update - oh no it doesn't - it is shown as gearless].
So it looks like if I am going to use hub motors, I will have to use two of them.  This would probably  be sensible, as it will be better to drive the rear wheels, but also expensive...

I have ordered an electric wheelchair conversion kit off ebay - will see how that goes.  Torque and speed should be ok, but it looks heavy and clunky, so I expect to upgrade it...

Power Assisted Cross Country Wheelchair

Our son Benjamin does not walk too well, and will suddenly run out of energy, so when we are out in the countryside we take a three wheeler cross country wheelchair for him:
He has got too big for this one, so we are going to get him the biggest one we can find:
This new one has 16" spoked wheels, so this means it should be possible to add some form of power assistance to it, as you can get some nice lightweight motors that fit into bicycle wheel hubs.
So, I intend to get an electric bicycle conversion kit, and fit it to the wheelchair.  There are a few things to deal with to make it work:
  1. Will the new hub fit in the front forks of the wheelchair? (waiting for supplier to measure it for me on Monday).
  2. Although fitting the powered wheel in the front will be the easiest mechanically (assuming it fits), the front wheel has less weight on it, so it may just spin, and not be much use, so I may have to look at how to fit it to one of the rear wheels (which then raises the concern about whether it will spin round in circles!
  3. The bike set-up will be intending to go a lot faster than I want this wheelchair to go (I guess it will target around 12mph, but I think 4mph will feel quite fast enough for me).   Mounting the hub in a smaller wheel will reduce the speed, but I think it will still be too fast (will do the sum later...), so I think I will have to modify the motor driver.    The motor is a brushless motor, which from what I have read sounds pretty much the same as a stepper motor - you have to feed it with a wave form to get it to go around (and go in the right direction).   So even if I can not simply modify the controller, I can use its power transistors etc. and use an arduino to make the waveforms.
An alternative may be to go for two electric wheelchair motors, but they look awfully heavy compared to the bike motor, so I am tempted to go with that as a trial.   If it doesn't work, I'll put the electric kit on our Hase Pino tandem to help me up the hills, as Benjamin doesn't put too much effort into pedalling!
IMAG0035

I'd be interested to hear if anyone has tried this and has experiences to share.