Marc's Public Blog - OSA, Obstructive Sleep Apnea and MMA Surgery

All | Aquariums | Arduino | Btrfs | Cars | Cats | Clubbing | Dining | Diving | Electronics | Exercising | Flying | Halloween | Hiking | Linux | Linuxha | Monuments | Museums | Public | Rc | Sciencemuseums | Snow | Solar | Trips

This page has a few of my blog posts about my issues with OSA, Obstructive Sleep Apnea, which basically means not being able to breathe at night and having restless nights, night after night.
Because my sleep apnea scored low but somehow the impact on me was fairly high, it took a while to diagnose, and I tried several things before eventually getting Maxillomandibular Advancement Surgery (MMA) to fix my airway for good.

I made this summary page after the fact, so it starts with a few sleep studies I likely did 5 years later than I should have.

Table of Content for osa:

More pages: December 2011 May 2011 March 2011 December 2010 August 2010 July 2010 January 2010 December 2009 July 2006 April 2006 November 2005 March 2004

2011/12/17 Zeo Raw Library Simple Callback Example
π 2011-12-17 01:01 in Linux, Osa
The MyZeo folks definitely deserve credit for releasing open firmware and instructions on how to interface with their bedside Zeo device via a custom made serial port:

Since I had been working on arduino, I happened to have one of those 3.3V FTDI USB-serial converters, and was able to make a cable that connects my bedside Zeo to my server closer via a custom cable going through my existing Cat-5 wiring.

The example code they gave is however, while very fancy, not that simple to borrow from for a more simple application that simply needs to keep track of the sleep stage.

So, after finding the relevant info, I compiled the code below, which I'm posting for others to use (you can also download it here: zeo raw data code sample).


# This is based off the Zeo Raw Data Library at the bottom of # # This script is a much simpler version of how to log basic data than the cool # and pretty GUI_Viewer from # This script is an easier example to steal from for simple logging/integration.

# By Marc MERLIN <> / 2011/12/17 # License: GPLv3.

#gandalfthegrey [mc]$ ./ # 2011-12-17 12:19:10: HeadbandDocked # 2011-12-17 12:19:15: HeadbandUnDocked # 2011-12-17 12:19:22: Sleep state: Undefined # 2011-12-17 12:19:52: Sleep state: Undefined # 2011-12-17 12:20:22: Sleep state: Undefined # 2011-12-17 12:20:52: Sleep state: Undefined # 2011-12-17 12:21:22: Sleep state: Undefined # 2011-12-17 12:21:52: Sleep state: Undefined # 2011-12-17 12:22:22: Sleep state: Undefined # 2011-12-17 12:22:52: Sleep state: Undefined # 2011-12-17 12:23:22: Sleep state: Undefined # 2011-12-17 12:23:52: NightStart # 2011-12-17 12:23:52: Sleep state: Awake # 2011-12-17 12:24:22: Sleep state: Awake # 2011-12-17 12:24:52: Sleep state: Awake # 2011-12-17 12:25:22: Sleep state: Awake # 2011-12-17 12:25:52: Sleep state: Awake # 2011-12-17 12:26:23: Sleep state: Awake # 2011-12-17 12:26:32: HeadbandDocked

# System Libraries import time import sys

# Zeo Libraries from ZeoRawData import BaseLink, Parser from ZeoRawData.Utility import *

# User customizable variables port = '/dev/ttyUSB0'

class Callbacks: def logtime(self): return time.strftime("%Y-%m-%d %H:%M:%S: ", time.localtime())

def SliceCallback(self, slice): if slice['SleepStage']: print self.logtime() + "Sleep state: " + slice['SleepStage']

def EventCallback(self, logtime, version, event): print self.logtime() + event

if __name__ = "__main__": link = BaseLink.BaseLink(port) parser = Parser.Parser()

callbacks = Callbacks()

# Add Callbacks and Start the Link link.addCallback(parser.update) parser.addSliceCallback(callbacks.SliceCallback) parser.addEventCallback(callbacks.EventCallback) link.start()

# Infinitely loop to allow the script to run continuously while(True): time.sleep(5)

2011/12/14 Interesting Stanford Sleep Study and comparing data with Zeo and personal SPO2 logger
π 2011-12-14 01:01 in Osa
My sleep has definitely improved this year. I do occasionally wake up for no good reason, or have nights that are shorter than they should be (wake up without an alarm and can't fall back asleep), but I would say that my issues of having 8H of sleep and waking up tired the next day are mostly gone.
This is good news from the OSA standpoint.

Now, because I need to wear a retainer every night anyway after I got my teeth moved, I figured I might as well get a sleep appliance again (think of a retainer with hardware that forces your bottom jaw forward) and improve my airway and room for my tongue when I sleep, just in case that helps further.

I was due for a sleep study at Standford, so we did a split night, first half withe sleep appliance and second half without it. While it's true that my sleep is not the same at the begining of the night vs the end, my sleep is usually deeper at the beginning of the night.

Apnea results

Long story short, my sleep was clearly worse with the sleep appliance than without. My AHI/RDI was 15.5 along with SPO2 drops with the appliance (That counts as apnea), while it went down to an almost normal 9 without SPO2 drops without the appliance.

So, there are 3 possibilities:

  • My sleep wasn't as good at the beginning of the night than the end, maybe because I wasn't doing well with all the wires and unnatural sleeping position (I remember dreaming a lot, which I never ever do in my first hours of sleep). My Zeo and the stanford report both showed I was in and out of deep sleep, and hit a good bit of REM around midnight. This means that if we had done the sleep study the other way around, the results could have changed. Still, the first part of the night does show desaturation and more SPO2 drops than the second part, both on the stanford graph and my own SPO2 recorder, and the stanford sleep graph really shows a bit of apnea (not hypopnea) for the first part of the night.
  • My sleep appliance *really* makes my sleep worse. It's unclear as to how since it's meant to do the opposite, but maybe my tongue isn't as happy with the little extra space it takes in my mouth.
  • However stanford computes the apnea score isn't that accurate or relevant to apnea. I don't think that's the case, their data looks very accurate and mostly matches the data I took separately from them. While I am pretty convinced by now that the Stanford test does influence the results, my own SPO2 sensor also seems to show that I may have gotten more consistent better SPO2 readings than they did. I'm not sure if their tech correctly excluded each and every reading anomaly on their graph vs my own recording which was much more consistent.
  • So let's have a look at the stanford graph, knowing that I removed the appliance around 03:00 but took almost 30mn to sleep again after that (and got up once to drink around 03:20):

    Clearly, things get better after 03:20, although my sleep was so disturbed around 03:00 that it shows a lot hypopnea without the appliance on, supporting my guess that the test itself is also messing with the results in my opinion.

    Stanford vs Zeo

    I brought my Zeo sleep monitor and the tech allowed me to wear it on top of their sensors to record the night on my phone while they were recording it themselves.
    Let's compare the two (note that the Zeo monitor which consolidates stages 1 and 2 as light sleep, and 3 and 4 as deep sleep):

    Having a quick look the Zeo does a reasonable job, even if not perfect:

  • it does consolidate data compared to the stanford graph, but for a home appliance, that's good enough.
  • it did however miss some period of awakeness at 02:30.
  • it also claims I was in REM around 03:10, but stanford's better sensors say I was in light sleep bouncing back to awake (which Zeo picks up afterwards. Generally Zeo is known not to do a super good job between light sleep and awake at times).
  • at 05:30, Zeo says I was in deep sleep for quite a while, Stanford disagrees, I apparently just barely touched stage 3 a few times.
  • Zeo has a quick explanation on their consolidated stages of sleep, and what each means and more articles on sleep stages.

    Verdict for Zeo? I'd say it wasn't bad considering, especially since it is designed to smooth and average data, while Stanford is meant to show raw data.

    Stanford vs Bluetooth Pulse Oximeter CMS50EW

    This brings us to my SPO2 saturation. I used a CMS50EW finger clamp SPO2 monitor which actually worked a bit more reliably than the stanford sensor which dropped signal a couple of times during the study.

    The drop around 03:20 is because I god unhooked, but the drops at 03:00 (to 60%?) and later around 06:00, look like monitoring issues. It seems that the tech who did the report did reject them as such.

    Here are the dumps from my own monitor for that night:

    My graph, first part of the night, with sleep appliance
    My graph, first part of the night, with sleep appliance

    Stanford graph
    Stanford graph

    My graph, second part of the night, without sleep appliance
    My graph, second part of the night, without sleep appliance

    Comparing the results, my monitor did show the drops at 23:35, 00:55, but it missed 01:25 and 03:00. I'm not sure who's right there, you'd think Stanford obviously has more sensitive equipment, but I also think it might be too sensitive. I think their sensor might show big drops when it'd bumped wrong, or the analog plug is touched.
    At 03:20, I was unplugged so that drop is expected. After that, the big drops around 06:00 seem to be bad data which my own monitor did not record.
    Because my own recorder was built in and did not rely on wires that would be messed with when I move, I actually think I got better SPO2 readings than they did. Too bad it's soo uncomfortable to wear and requires a good amount of tape to make sure I don't have it drop off my finger, or move enough to affect its readings.


  • My study is still very perplexing. While I am not fully certain that the stanford data recording was 100% accurate, at least for SPO2, I still agree that the data shows that the first part of the night was worst than the second, which is the wrong way around compared to expectations (I should have had less apnea the first part of the night with the sleep appliance/mouth piece).
  • The Zeo monitor did well enough compared to what I expected out of it. It gets a pass :) (and actually gets better than pass if you consider how unobtrusive it is).
  • The CMS50EW did really well. If only I could get its data wirelessly from linux, but its drivers suck so badly that it can barely talk to windows. What a shame...
  • I am feel like Schroedinger's cat, being observed at stanford definitely influences my night and therefore the results. They really should reconsider their apparatus for something simpler depending on what needs to be measured. If I'm only here for apnea, give me just the sensors for that and use a much smaller device (which should be wireless) and let me sleep on my tummy and turn around freely.
  • what a mess :)
    what a mess :)

  • I'm not sure if I can fully consider that my AHI/RDI is now under 10, but if so, great! :) Actually if stanford counted those SPO2 drops around 06:00, and they were wrong, then my score gets even a bit better. But really, it's hard to say. I feel like there could be a variance of up to 5 points doing the same study 3 nights in a row. That's not very feasible though since Stanford is the most expensive hotel I've ever slept at :)
  • This is why I've been working on my own recording at home so that I can get as much data as I can over several nights and average that out.

    More pages: December 2011 May 2011 March 2011 December 2010 August 2010 July 2010 January 2010 December 2009 July 2006 April 2006 November 2005 March 2004

    Contact Email