Torso position determined via accelerometer!

General Discussion on any topic relating to CPAP and/or Sleep Apnea.
User avatar
BasementDwellingGeek
Posts: 262
Joined: Sat Nov 05, 2011 12:54 pm
Location: N Billerica, MA, USA
Contact:

Torso position determined via accelerometer!

Post by BasementDwellingGeek » Sat Jun 09, 2012 9:51 pm

Thursday night I taped my new three axis accelerometer/data logger to my torso just below the rib cage. I was hoping to be able to capture rise and fall of breathing in addition to my general body position. I was able to capture the early breaths as I first got into bed. They were deeper than the later more relaxed breaths. Perhaps scaling the data differently would yield more info.

It took me a few hours to patch my code to show all three axises and make sense of the additional data Friday morning. It took most of the afternoon and evening and a good part of Saturday to figure out how to show the orientation in a sensible manner and add/debug the code.

Here is a 2 hour chunk of breathing waveforms.
Image

Again with torso position indicated. Red is back, blue is front.
Image

And again with the accelerometer data shown.
Image

And a different view with Zeo data instead of breathing waveforms.Image

I started in a prone like leaning left position. Then I rolled over to the right, not quite on my side for about an hour vacillating between light and not quite deep sleep. I flipped over back to the original potion and had a really short dream (30 seconds is the minimum span of a Zeo state without getting really jiggy, this was a 30 second dream), some more deep and light sleep followed by a longer dream. Note the twitch as the dream began and another part way through. I have no clue what they could mean. There was another period of light sleep followed by an awake period. The detail below shows I spent most of the awake time on my back before flopping on to my left side and soon entered REM. I stayed on my left side for the rest of 2 hour chunk of time.
Image

That little downward spike just after the first repositioning was scored as an Hypopnea. There were 2 more Hypopneas in the U shaped notch about 1:08.

_________________
Mask: Swift™ FX Nasal Pillow CPAP Mask with Headgear
Humidifier: S9™ Series H5i™ Heated Humidifier with Climate Control
Additional Comments: own home grown SW to make it all work together, SH too.
bdg
(PR System One REMstar Pro CPAP Machine with C-Flex Plus and related humidifier as backup)

There are two types of people in this world. Those that can extrapolate from incomplete data

Matty332
Posts: 168
Joined: Tue Jan 10, 2012 6:16 pm
Location: Canberra, Australia

Re: Torso position determined via accelerometer!

Post by Matty332 » Sun Jun 10, 2012 3:36 am

This is incredible! Did you make the accelerometer? I have made one from a 'silicon chip' (http://www.siliconchip.com.au/) article but mine is not set up to log data (but can be).

You should be an engineer if you are not already one, I am amazed by this.

_________________
MaskHumidifier

User avatar
pats
Posts: 289
Joined: Sun Apr 22, 2012 5:52 pm

Re: Torso position determined via accelerometer!

Post by pats » Sun Jun 10, 2012 7:09 am

BasementDwellingGeek wrote:Thursday night I taped my new three axis accelerometer/data logger to my torso just below the rib cage. I was hoping to be able to capture rise and fall of breathing in addition to my general body position. I was able to capture the early breaths as I first got into bed. They were deeper than the later more relaxed breaths. Perhaps scaling the data differently would yield more info.

It took me a few hours to patch my code to show all three axises and make sense of the additional data Friday morning. It took most of the afternoon and evening and a good part of Saturday to figure out how to show the orientation in a sensible manner and add/debug the code.
Could you post or create a web page with some technical details? Ideally, I would like your code and the instructions to duplicate your hardware.

I'm thinking of a slightly different application. I'm trying to cut down on sleeping on my back, and don't like any of the mechanical solutions. I would like both to log position, and also possibly to create an alarm that will wake me up if I spend more than a couple of minutes lying on my back.

_________________
Mask: Swift™ FX Nasal Pillow CPAP Mask with Headgear
Additional Comments: Software: SleepyHead.

User avatar
MaxDarkside
Posts: 1199
Joined: Sun Dec 18, 2011 4:21 pm
Location: Minneapolis, MN

Re: Torso position determined via accelerometer!

Post by MaxDarkside » Sun Jun 10, 2012 7:54 am

Very well done! Yes, writing up what / how you did, starting with the hardware through data on the computer would be nice. If you are pressed for time or don't have a place to put it on the web maybe you could provide enough information to guide us along, I could replicate your work and document it and put it on my blog with proper attribution to you.

_________________
Mask: Quattro™ FX Full Face CPAP Mask with Headgear
Humidifier: S9™ Series H5i™ Heated Humidifier with Climate Control
Additional Comments: CMS-50E Oximeter, Zeo Bedside, Software: Comm'l grade AI analytics server & tools & SleepyHead
Do or Die... Sleep Apnea killed me, but I came back. Click for my story
Please visit my My Apnea Analytics blog. Maybe we can help each other.
54 yrs, 6' 1", 160->172 lbs

User avatar
Suzjohnson
Posts: 499
Joined: Fri Apr 13, 2012 8:49 am
Location: Dammeron Valley, UT

Re: Torso position determined via accelerometer!

Post by Suzjohnson » Sun Jun 10, 2012 8:06 am

I am very impressed! You are a genius! How soon before this is ready to hit the market? I want whatever it is. It would help make the SH charts more sensible.
All I can say is WOW!

Suz

_________________
Mask: AirFit™ P10 For Her Nasal Pillow CPAP Mask with Headgear
Humidifier: S9™ Series H5i™ Heated Humidifier with Climate Control
Additional Comments: SleepyHead, CMS 50D+, Deluxe Chinstrap, began CPAP 4/21/2012
"We are what we repeatedly do, so excellence is not an act but a habit". ~ Aristotle

User avatar
MaxDarkside
Posts: 1199
Joined: Sun Dec 18, 2011 4:21 pm
Location: Minneapolis, MN

Re: Torso position determined via accelerometer!

Post by MaxDarkside » Sun Jun 10, 2012 9:34 am

Actually, using that device (X16-1C) looks pretty straight forward. At what frequency do you record and how full does the 2 GB RAM card get overnight at that freq?

_________________
Mask: Quattro™ FX Full Face CPAP Mask with Headgear
Humidifier: S9™ Series H5i™ Heated Humidifier with Climate Control
Additional Comments: CMS-50E Oximeter, Zeo Bedside, Software: Comm'l grade AI analytics server & tools & SleepyHead
Do or Die... Sleep Apnea killed me, but I came back. Click for my story
Please visit my My Apnea Analytics blog. Maybe we can help each other.
54 yrs, 6' 1", 160->172 lbs

User avatar
pats
Posts: 289
Joined: Sun Apr 22, 2012 5:52 pm

Re: Torso position determined via accelerometer!

Post by pats » Sun Jun 10, 2012 9:42 am

MaxDarkside wrote:Actually, using that device (X16-1C) looks pretty straight forward. At what frequency do you record and how full does the 2 GB RAM card get overnight at that freq?
I don't think card fullness will be an issue, because it is actually getting quite hard to buy something as "small" as a 2 GB card.

_________________
Mask: Swift™ FX Nasal Pillow CPAP Mask with Headgear
Additional Comments: Software: SleepyHead.

User avatar
MaxDarkside
Posts: 1199
Joined: Sun Dec 18, 2011 4:21 pm
Location: Minneapolis, MN

Re: Torso position determined via accelerometer!

Post by MaxDarkside » Sun Jun 10, 2012 9:58 am

pats wrote:I don't think card fullness will be an issue, because it is actually getting quite hard to buy something as "small" as a 2 GB card.
You are likely correct, as BDGeek said at first he recorded more data than useful, so it seems there's room for "too much". I think this is only "Post-Sleep" importing, not streaming, so the request to "create an alarm that will wake me up if I spend more than a couple of minutes lying on my back" would not be possible? One would have to use a blue-tooth or tethered device for that.

_________________
Mask: Quattro™ FX Full Face CPAP Mask with Headgear
Humidifier: S9™ Series H5i™ Heated Humidifier with Climate Control
Additional Comments: CMS-50E Oximeter, Zeo Bedside, Software: Comm'l grade AI analytics server & tools & SleepyHead
Do or Die... Sleep Apnea killed me, but I came back. Click for my story
Please visit my My Apnea Analytics blog. Maybe we can help each other.
54 yrs, 6' 1", 160->172 lbs

User avatar
pats
Posts: 289
Joined: Sun Apr 22, 2012 5:52 pm

Re: Torso position determined via accelerometer!

Post by pats » Sun Jun 10, 2012 10:30 am

MaxDarkside wrote:
pats wrote:I don't think card fullness will be an issue, because it is actually getting quite hard to buy something as "small" as a 2 GB card.
You are likely correct, as BDGeek said at first he recorded more data than useful, so it seems there's room for "too much". I think this is only "Post-Sleep" importing, not streaming, so the request to "create an alarm that will wake me up if I spend more than a couple of minutes lying on my back" would not be possible? One would have to use a blue-tooth or tethered device for that.
Either that, or build the alarm into the unit that is worn. Perhaps a small Arduino monitoring the position data and controlling a buzzer?

_________________
Mask: Swift™ FX Nasal Pillow CPAP Mask with Headgear
Additional Comments: Software: SleepyHead.

User avatar
avi123
Posts: 4510
Joined: Tue Dec 21, 2010 5:39 pm
Location: NC

Re: Torso position determined via accelerometer!

Post by avi123 » Sun Jun 10, 2012 11:05 am

[quote="BasementDwellingGeek"]Thursday night I taped my new three axis accelerometer/data logger to my torso just below the rib cage. I was hoping to be able to capture rise and fall of breathing in addition to my general body position. I was able to capture the early breaths as I first got into bed. They were deeper than the later more relaxed breaths. Perhaps scaling the data differently would yield more info.

[quote]

Comment,

It seems to me that what you're trying to do with the accelometers exists already. See here:

Image

Link:

http://www.camntech.com/images/products ... watch8.pdf

For sleep body position you could use a gravity switch which is much cheaper than using accelometrs:

http://www.grasstechnologies.com/produc ... n_slp.html

_________________
Mask: Mirage™ SoftGel Nasal CPAP Mask with Headgear
Humidifier: S9™ Series H5i™ Heated Humidifier with Climate Control
Additional Comments:  S9 Autoset machine; Ruby chinstrap under the mask straps; ResScan 5.6
see my recent set-up and Statistics:
http://i.imgur.com/TewT8G9.png
see my recent ResScan treatment results:
http://i.imgur.com/3oia0EY.png
http://i.imgur.com/QEjvlVY.png

User avatar
MaxDarkside
Posts: 1199
Joined: Sun Dec 18, 2011 4:21 pm
Location: Minneapolis, MN

Re: Torso position determined via accelerometer!

Post by MaxDarkside » Sun Jun 10, 2012 11:17 am

avi123 wrote:It seems to me that what you're trying to do with the accelometers exists already. See here:
Many ways to the same or similar result. I don't see how you can order that watch or see the cost. They just have "get a quote" and I don't see it on Amazon. Following in BDGeek's footsteps, I ordered the X16-1C USB Accelerometer this AM. I may use it for things other than sleep as well. I may yet do something with my Droid, too.

_________________
Mask: Quattro™ FX Full Face CPAP Mask with Headgear
Humidifier: S9™ Series H5i™ Heated Humidifier with Climate Control
Additional Comments: CMS-50E Oximeter, Zeo Bedside, Software: Comm'l grade AI analytics server & tools & SleepyHead
Do or Die... Sleep Apnea killed me, but I came back. Click for my story
Please visit my My Apnea Analytics blog. Maybe we can help each other.
54 yrs, 6' 1", 160->172 lbs

User avatar
BasementDwellingGeek
Posts: 262
Joined: Sat Nov 05, 2011 12:54 pm
Location: N Billerica, MA, USA
Contact:

Re: Torso position determined via accelerometer!

Post by BasementDwellingGeek » Sun Jun 10, 2012 12:21 pm

Thanks for the positive feedback. I am an 55 year old unemployed, largely self educated hack. Finding a decent job without a degree in this economy is not easy. I do this to keep my mind alive.

The hardware is an X16-1C from Gulf Coast Data Concepts, LLC. It's bigger and heavier than I would like but it's also ½ to to 1/3 the price of the next better choices.
http://www.gcdataconcepts.com/xlr8r-1.html I really can't tell you much other than there is a AA battery making it bulky, a 2GB sdcard, and probably a ADXL345 accelerometer based on info in one of the files that it came on the sdcard. There are multiple modes of operation but as I use it I am required to press a recessed button with a pen pint or other similar slender object to start it. A press and hold stops the recording. Then I plug it into a USB port and suck up the CSV file that has been generated.

This page http://www.basementdwellinggeek.org/CPA ... iewer.html has a little history of my application. I'll update it in the next few days with more info about the accelerometer. This thread has some of the back story viewtopic.php?f=1&t=78584&p=715068#p715068 about the accelerometer. It shows an early test of the data being displayed in the tool, a java JAR file, that comes with the data logger. It was easy enough to see that tilt could be derived via the force of gravity on a single axis. My first implementation only considered the X axis. The first few nights of experimentation consisted of a lot wheel spinning and not much traction. The attachment to my headgear failed, so no data. I did capture "good" data the second night but using the default configuration I ended up with way more data than I wanted to deal with and in multiple files to boot. The third night I had the device configured to what I thought was reasonable. The important items were sample rate, deadband, and deadbandtimeout. The default sample rate of 50/sec is way over kill for my needs. I would have gone slower but 12 was the minimum. Sample rate determines how often the the X,Y,Z values are checked, not necessarily written to the log. The deadband setting specifies how much change, in any axis, is required to cause another measurement to be logged. I though 0.1g was sufficient. Fewer writes equal longer battery power. As I get a feel for magnitude of changes and what they mean I may crank that up. The third parameter that I altered, deadbandtimeout, specifies how often to log a sample when the system has not changed enough to exceed the deadband. I picked 1 second, but may crank that up as well.

I patched my application to scale the X axis data, manually synchronize to the timestamps of the other data sources and draw a waveform. The "master" clock is the CPAP machine. I have controls to shift the other data sources to align with the "master". Zeo needs a 127 second adjustment and the data logger a 375 second adjustment. The adjustment for the Pulse/OX varies by long it takes to finish starting the record mode.

It didn't take long to figure out that a second axis was required. A single axis can give tilt but can't tell you whether you are face up or face down.
Image I spent many hours with this image and its corresponding CSV file. The X axis, the red line shows a series of movements I used to figure out what was happening when. Holding the device level I started it, then rotated 90 degrees to the left and held it there for a while, then rotate right back to the original position again holding for a moment. Then repeat the process except rotate right initially. During the first phase the line dipped then returned to normal. Second phase the line rose then returned to normal. Then rotate through 360 degrees to the right returning to normal the right end of the image. The Y axis, blue line, didn't do much but wobble around as the center of the device moved up and down. The Z axis, green line, is 90 degrees from the angle of the X axis. Therefore, the Z axis being negative tells me that I have rotated past vertical and am now facing down.

Through the wonders of cut and paste I created a stripped down application to read the data and experiment on how to display it. I visited many many web pages searching for information on how to translate values returned by the accelerometer to tilt or angle or orientation... I found a formula that I will paraphrase. Divide the reading by the force or gravity and take the arc sin of the quotient. This gives angle in radians. Then to convert to degrees multiply by 180 divided by Pi. This gives basic tilt. Then factor in the value of the other Axis. In my case as I had the device mounted this was the Z Axis. Depending on how you mount the device and what normal is and how you rotate will determines which two axes you will need to use. You may need to diddle with some signs in places to make it all work.

After that is was just a matter of learning how to draw a bitmap at a angle of rotation and devising a scheme to select when to show the body position symbol. I thought about moving averages and showing a symbol when the magnitude of change exceeded some preset amount. It seemed like a lot of work. I settled on dividing the time displayed into 20 spaces and showing one symbol for each based on a single sample at that location. By contracting the timebase more detail is revealed. I can drag the time buy small increments and watch the symbol roll over.

I've nudged jedimark with the basic info. How soon, or if it gets incorporated into SH is out of my hands. Well not really, with SH being open source I could implement my code but it would be a long hard uphill battle learning the environment he works in.

I've uploaded http://www.basementdwellinggeek.org/CPA ... %20out.zip. It is a zip VS2010 project with sample data. Buried inside is "finger this out.exe". Run it, chick the button and navigate to DATA-007.CSV. AccelDebug.cs has most of the code for dealing with the accelerometer.

_________________
Mask: Swift™ FX Nasal Pillow CPAP Mask with Headgear
Humidifier: S9™ Series H5i™ Heated Humidifier with Climate Control
Additional Comments: own home grown SW to make it all work together, SH too.
Last edited by BasementDwellingGeek on Sun Jun 10, 2012 12:35 pm, edited 1 time in total.
bdg
(PR System One REMstar Pro CPAP Machine with C-Flex Plus and related humidifier as backup)

There are two types of people in this world. Those that can extrapolate from incomplete data

User avatar
MaxDarkside
Posts: 1199
Joined: Sun Dec 18, 2011 4:21 pm
Location: Minneapolis, MN

Re: Torso position determined via accelerometer!

Post by MaxDarkside » Sun Jun 10, 2012 12:30 pm

Thanks. If I tethered the device with a USB cable and read/renamed and/or deleted the file ever so many seconds, I'm wondering if I could turn a "Post-Sleep" analysis into a real time one. I may try that to see under what situations the device won't burp while the file is being tampered with.

_________________
Mask: Quattro™ FX Full Face CPAP Mask with Headgear
Humidifier: S9™ Series H5i™ Heated Humidifier with Climate Control
Additional Comments: CMS-50E Oximeter, Zeo Bedside, Software: Comm'l grade AI analytics server & tools & SleepyHead
Do or Die... Sleep Apnea killed me, but I came back. Click for my story
Please visit my My Apnea Analytics blog. Maybe we can help each other.
54 yrs, 6' 1", 160->172 lbs

User avatar
BasementDwellingGeek
Posts: 262
Joined: Sat Nov 05, 2011 12:54 pm
Location: N Billerica, MA, USA
Contact:

Re: Torso position determined via accelerometer!

Post by BasementDwellingGeek » Sun Jun 10, 2012 12:54 pm

USB cable and read/renamed and/or deleted the file ever so many seconds
This is my config file.
; PRODUCT_ID = X16-1C
deadband = 100
DeadBandTimeout = 1
samplesperfile = 72000
statusindicators = Normal
SampleRate = 12
;rebootOnDisconnect
Last night was a short night (4.5 hrs) since I was up late playing and daybreak tends to wake me. The csv file was only 513k. The longest was 737k for almost 8 hours of hose/bed time. Depending on how active you are while sleeping you may log more samples. I haven't done a study to see how many samples are DeadBandTimeout vs deadband induced. I figure that is your ballpark

If you set the samples per file low enough you could probably stay just behind "realtime". It logs to names like DATA-xxx.CSV. When I deleted earlier files DATA-001.CSV and DATA-002.CSV with 003 and 004 still on the "drive", it chose to re-use the earlier name/numbers in latter passes.

_________________
Mask: Swift™ FX Nasal Pillow CPAP Mask with Headgear
Humidifier: S9™ Series H5i™ Heated Humidifier with Climate Control
Additional Comments: own home grown SW to make it all work together, SH too.
bdg
(PR System One REMstar Pro CPAP Machine with C-Flex Plus and related humidifier as backup)

There are two types of people in this world. Those that can extrapolate from incomplete data

User avatar
tschultz
Posts: 257
Joined: Sun Dec 19, 2010 9:36 pm
Location: Toronto, ON, Canada, Earth, Milky Way Galaxy

Re: Torso position determined via accelerometer!

Post by tschultz » Sun Jun 10, 2012 12:56 pm

Good job on what you've done. I can see there are a few people that want to know their body position.

I am part way through PCB layout for a small re-chargeable wearable unit with both a 3 axis accelerometer and temperature measurement which I hope to have built and working in prototype form by mid July. I have found a suitable plastic case for the design which measures approx 2" x 1.25" x 0.6" or 52mm x 32mm x 15mm and is available in low volumes. The unit could be made quite a bit smaller if I can find a suitable enclosure. Initially this version will be recording with data that can be downloaded later via USB but I have also started a design spec for a unit that interfaces to the Zeo Bedside via its serial port and provides a direct Ethernet connection, allowing simultaneous real-time monitoring, as well as recording, of the raw Zeo data as well as data from external wired and wireless sensors such as a heart-rate belt. My intention is to document the projects and make them open-source for the hardware and firmware with an open file format and communication protocol.

For me I am wanting to collect data on position, body temperature, room temperature and relative humidity as well as the Zeo raw data. I want to layer include chest effort and heart-rate monitoring. I have found that how I sleep is closely related to the room temperature and this is why I am wanting to add the room to the data-set.

Updating SleepyHead to handle this additional data is relatively easy and would allow for a single program to monitor our sleep.

_________________
Mask: Mirage™ SoftGel Nasal CPAP Mask with Headgear
Humidifier: S9™ Series H5i™ Heated Humidifier with Climate Control
Additional Comments: Currenlty using Auto 15-20, EPR 1 with medium response; 95% pressure is 16.8
Adjusting to life with OSA and being pressurized each night ...