Inspiration

I was recently diagnosed with Sleep Apnea, and wished to use the comprehensive diagnostics generated by the hardware to allow me to make more informed decisions about my sleep habits. I felt that pursuing and developing tools that allow access to this data would allow me to make a number of informed decisions about my sleep habits: it is difficult for me, while sleeping, to gauge the impact of sleeping on a certain side of my body. With SleepCycle, I wanted to construct a system that would allow me to collect and obtain records of significant sleep metrics, and use these to measure changes in my sleeping 'setup.'

What it does

SleepCycle takes as input, a single .edf file generated during the operation of a CPAP machine, and extracts information about what the device deems "significant sleep events." Date and time are also extracted and computed, allowing me to compare the device's timeline against known external events.

How I built it

I began by researching common metrics used by pulmonary professionals: in some cases, this also was used to understand some of the more technically complex measurements performed by the device, or discard them as needed.

The largest effort of the hack was reviewing visible text and hex data to construct theories as to how the data was stored in the .edf format. This information was checked against less-descriptive, but publicly available usage data and utilities. Then, using python, I stripped the document of the needed data by performing bitwise searches and operations on the file itself.

Challenges I ran into

My goal with every Hackathon is to push myself far out of my comfort zone: in this case, my eyes were larger than my ability to perform data mining and analysis on a format that I'd never seen before. My ability was hampered by, despite early indications of the data being in a common open standard, large swaths of it was either reliant on medical expertise, or was exclusively machine-readable.

Existing open source projects did little to aid my coding directly: they had the luxury of time, have access to industry standard software suites which they can use to both model their display and collection of info.In addition, they were much more concerned with the display of medically interesting information that I had no means of understanding or incorporating. Multiple free libraries existed for interpreting the edf data, but the CPAP device I used stored the most useful data (time-stamped event 'logs' of apnea events,) in a fashion none of them were able to understand.

My biggest breakthrough came from eschewing any of their methods, and directly examining the binary code of the data files, decoding the numerical values attached to the only plain-text visible in an editor (a combination of time in seconds with three unrelated numbers in-line.)

Accomplishments that I'm proud of

While this project offered opportunities to experiment with devices that could provide auxiliary data, I ultimately chose to dedicate my efforts towards analysis of the device, the types of data it provided, and the ways in which I could best access that data.

What's next for SleepCycle

I have the tools to easily add additional metrics to aid in my sleep study, and would like to integrate the Fitbit Fitness tracker API to track sleep events the CPAP machine cannot, such as tossing and turning. I would also like to use an external microphone with the RaspberryPI, as a way to account for external events that could be interfering with my sleep. Results are being stored in SQLite DB, so adding additional sources of information would be nothing more than another table that I would join along a time index.

Built With

  • bitstring-pythonlibrary
  • python
  • resmed-airsense-10
Share this project:

Updates