-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom.xml
114 lines (85 loc) · 9.37 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Fig's Blog</title>
<link href="http://alexfig.github.io/atom.xml" rel="self"/>
<link href="http://alexfig.github.io/"/>
<updated>2015-01-10T10:46:24-08:00</updated>
<id>http://alexfig.github.io</id>
<author>
<name>Mark Otto</name>
<email>markdotto@gmail.com</email>
</author>
<entry>
<title>Testing for Sleep Apnea</title>
<link href="http://alexfig.github.io/2015/01/10/testing-sleep-apnea/"/>
<updated>2015-01-10T00:00:00-08:00</updated>
<id>http://alexfig.github.io/2015/01/10/testing-sleep-apnea</id>
<content type="html"><script src="/public/audiojs/audio.min.js"></script>
<script>
audiojs.events.ready(function() {
var as = audiojs.createAll();
});
</script>
<p>I&#39;ve had problems with daytime sleepiness since I was a teenager. I used to attribute it to having a poor sleep schedule and just being a heavy sleeper. However I began to realize that even when I slept for 8+ hours, I would still get sleepy in the middle of the day. At the time, I was exercising regularly and had a fairly healthy diet so I couldn&#39;t think of a reason why I would get so tired. A couple years ago I woke up in the middle of the night, almost choking and struggling to breathe. I was only half awake so I didn&#39;t realize what was happening at first, but as soon as I did I just started breathing normally again like nothing happened and went back to sleep. This happened a few times more times afterwards, but then stopped occurring so I didn&#39;t think much of it. </p>
<p>Recently though, I stumbled upon the wiki page for a sleep disorder called <a href="http://en.wikipedia.org/wiki/Sleep_apnea">sleep apnea</a>, which is characterized by difficulty breathing during sleep. As soon as I read the description, it hit me that this might have been what I was experiencing in the past. I scheduled an appointment with a physician, but since it&#39;s not for a couple week, I wanted to see if I could build something to monitor my breathing while I slept. I had a couple microcontrollers collecting dust, so this gave me a reason to put one to use.</p>
<h2>Breath Monitor</h2>
<p>First I needed to find a sensor I could use to monitor my breathing. I tried searching for sensors that could measure airflow, but all I could find were either expensive, medical grade equipment or devices I wouldn&#39;t be able to use while I slept. Fortunately, I stumbled upon a <a href="http://forum.arduino.cc/index.php?topic=157802.msg1335958#msg1335958">forum post</a> describing how you can use a temperature sensor to monitor your breath. The poster had success with a DS18B20 digital thermometer so I just went with that. I ended up buying the waterproof version out of convenience, since it came prewired and I didn&#39;t have the materials to wire one myself. </p>
<p>Next I had to think of something that could hold the sensor in front of my nose/mouth while I slept. My initial idea was to just poke the sensor through a dust mask and wear that. While looking for dust masks to buy, I found some that had exhalation valves and figured they would probably be a better choice since the valve can be used to direct air over the sensor. I decided on <a href="http://www.amazon.com/3M-Particulate-Respirator-8233-N100/dp/B00OTZETMC/">this mask</a> because it looked the most comfortable and I needed to be able to sleep while wearing one. </p>
<h2>Putting It Together</h2>
<p>After receiving everything, I first wanted to test the sensor to make sure it was sensitive enough to detect whether I was inhaling or exhaling. The DS18B20 is a digital sensor and communicates using the 1-Wire protocol, so reading its output isn&#39;t as simple as it would be with an analog sensor. Luckily there are libraries that implement everything needed to use the sensor on an Arduino board, making things a lot easier. A tutorial that explains everything can be found <a href="http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html">here</a></p>
<p>To test the sensor, I continuously printed its output to the serial port. Initially it wasn&#39;t sensitive enough to detect my breath, however this was because of the waterproof casing. After removing the casing it was able to monitor my breath fairly accurately. When I inhaled, the temperature would drop, and when I exhaled, it would increase, even when my breath was shallow. </p>
<p>Finally, I had to figure out how to attach the sensor to the mask. After a bit of trail and error, the solution I came up with was to just twist tie it to the inside of the valve housing, as seen below. This forces the valve (the yellow flap) to stay open, which make it easier to breathe and lets air flow over the sensor when inhaling. If you allow the valve to close, then it won&#39;t cool down quick enough to detect when you inhale. </p>
<p><strong>Sensor attachment</strong>
<img src="/public/sleepdata/sensor.jpg" alt="Sensor Attachment"></p>
<p><strong>Putting everything together</strong>
<img src="/public/sleepdata/final.jpg" alt="Final Product" title="Final Product"></p>
<p><br></p>
<h2>Collecting and Analyzing the Data</h2>
<p>To collect the data I had my laptop log everything the Arduino printed to the serial port. I had the Arduino print out two columns of data, the time elapsed and the temperature. Here is the main loop of my code:</p>
<div class="highlight"><pre><code class="language-text" data-lang="text">void loop(void)
{
time = millis();
sensors.requestTemperatures();
Serial.print(time);
Serial.print(&quot;,&quot;);
Serial.println(sensors.getTempC(thermometer));
}
</code></pre></div>
<p>To analyze the data I used Octave. A plot of the raw data, as shown below, doesn&#39;t really tell us anything. We have to convert the data to something more useful. According to wikipedia, a common metric for determining an apnea is the time interval between breaths. An interval of 10 seconds or greater can be considered an apnea. </p>
<p><strong>Plot of raw data</strong>
<img src="/public/sleepdata/rawdata.jpg" alt="Raw Data Plot" title="Plot of raw data"></p>
<p>Measuring the interval between breaths is relatively simple since the output of the sensor is free of noise (i.e., temperature only increases when exhaling and decreases when inhaling). We can iterate through the temperature data and if the temperature is increasing we know were exhaling and if it decreasing, were inhaling. This most likely wouldn&#39;t work with an analog sensor. I wrote a function that iterates through the data, calculating the time between every inhale.</p>
<div class="highlight"><pre><code class="language-text" data-lang="text">beginInhaleTime = data(1,1);
currentTemp = data(1,2);
inhaling = true;
for i=2:size(data,1),
if(inhaling)
if(data(i,2) &lt; currentTemp)
currentTemp = data(i,2);
elseif(data(i,2) &gt; currentTemp)
inhaling = false;
currentTemp = data(i,2);
end;
else
if(data(i,2) &gt; currentTemp)
currentTemp = data(i,2);
elseif(data(i,2) &lt; currentTemp)
inhaling = true;
breathIntervals = [breathIntervals; data(i,1) - beginInhaleTime ];
timeOfBreath = [timeOfBreath; beginInhaleTime];
beginInhaleTime = data(i,1);
end;
end;
end;
</code></pre></div>
<p>With the breath intervals calculated, I then plotted the data along with a couple more metrics to help determine the quality of my sleep.</p>
<p><strong>Breath interval plot</strong>
<img src="/public/sleepdata/plot.JPG" alt="Breath Interval Plot" title="Final Plot"></p>
<p>Looking at the plot, there seems to be evidence that I have sleep apnea. According to wikipedia, 5 - 14.9 events per hour of sleep is considered mild. The data shows I had around 6.8 so that&#39;s on the low end, however there is a cluster of 15 apneas at the 5-hour mark. </p>
<h2>Further Analysis</h2>
<p>To gain some more insight on how I was breathing and confirm that the monitor was accurate, I placed a small mic under the mask to record myself while I slept. Using the plot I found the time at which one of the longer apneas occurred and listened to the audio to see if I was actually having trouble breathing. Here&#39;s what it sounded like:</p>
<p><audio src="/public/sleepdata/apnea1.mp3" preload="auto" /></p>
<p>It starts off with a normal breath and then you can immediately hear me start struggling to get a breath out. At around the 20 second mark I stop breathing completely for almost 40 seconds, before moving around and then finally exhaling. So it&#39;s looking like I may have sleep apnea. Hopefully I can get a sleep study done to confirm and pinpoint the cause of it. </p>
</content>
</entry>
</feed>