 I assume you guys know that my name is Neon Rain, and the speech you're attending is, what speech are we attending now? Hacking Sleep, How to Build Your Own Homebrew Sleep Lab. So this is my partner in crime, Keith, and we would like to welcome you to the speech. This is my fourth time speaking here at DEF CON, and I'm actually quite excited about it, because when I started out talking about the human brain and brain-computer interfaces, everybody was kind of like, that's nice brain girl, but there's really been a lot of excitement lately with the stuff that they're up and coming up with. So, and also my team has gotten bigger as well. Keith and a couple of other people as well, like the projects I did in the beginning were quite tiny, but when you're building an entire sleep lab, you kind of need a bigger team. So it's kind of nice to have camaraderie. So, I guess we might as well just get this started. So basically, I've always been quite amused with the concept of hacking a system with a soul, because I mean, computers are cool at all, but the ego maniac I am, I find myself a little bit more interesting. So, every person in this room has at least a vaguely familiar notion of what sleep is, since it's something all human beings do, and we take it for granted. But even though sleep is something we're all intimately familiar with, understanding this quietly mysterious part of our lives isn't that simple. If you really think about it, we approximately spend one third of our lives, like really still and with our eyes closed, and then you wake up, and normally you don't remember what happened, so it's actually kind of a really amazing thing. Sleep is scientifically defined as a normal state of rest that's characterized by unconsciousness, reduced activity, and limited sensory responsiveness. So, a question I get asked a lot is what would be considered the difference between sleep and drug intoxication, or coma, or hibernation? So, the difference is sleep is considered sleep because it's spontaneous, it's periodic, and it's easily reversible. So, that would be what the difference is. So, the way to talk about sleep is usually best to contrast it with wakefulness. So, of course, the characteristics of wakefulness are the opposite of sleep. You're conscious, you have sensory responsiveness, and we like to think we're full of purposeful activity. Sleep is one of the least understood aspects of human and animal behavior, and for centuries, scientists thought that wakefulness was the brain's natural state, and that sleep represented a shutting down of brain activity, if you turned off a light bulb. But it's now known that sleep and wakefulness are active states controlled by specific groups of brain structures. So, one good way for us to figure out about sleep, and to learn more about sleep, is to figure out what happens if you don't sleep. So, I'm sure none of you at DEF CON have had problems with staying up all night, and I'm sure right now, seeing it early on Sunday, none of you have become reacquainted with either being any of the after effects like grumpiness, groggyness, irritability, or forgetfulness. After one night without sleep, concentration becomes difficult, and attention span shortens considerably. You have no idea how much is to focus on this, just for me. With continued lack of sufficient sleep, the part of the brain that controls language, memory, and planning, and sense of time is severely affected. In fact, 17 to 19 hours of sustained wakefulness leads to a significant decrease in performance. Recent experiments have suggested that impairments produced by moderate sleep deprivation results in cognitive motor performance, equivalent or worse to that that you'd experience with a blood alcohol level of 0.05. So, if you're a lightweight like me, that's equal to two glasses of wine. So, then you're kind of like singing we are the champions, or maybe that's just me. Wakefulness and sleep both involve complex physiological and psychological mechanisms. So, there's behavioral changes, such as the typical posture we take when we're sleeping, that is recognizable, and our lack of response to stimuli. And there are physiological changes which happens with our heart rate and breathing. And finally, there are electrophysiological changes that can all be measured with machines. So, these changes during sleep are quite profoundly different than we experience when we're awake, and it's these changes that define what exactly makes up an occurrence of sleep. So, we've been talking about sleep in humans. So, what about animals? Do you guys think animals sleep? Do all animals sleep? Well, a lot of people are quite surprised because this is a very tricky question and a very tricky microphone. You see, the brain sends out electrical signals that can be measured with machines while we sleep. So, it's these brain signals that we use to define whether or not it's sleep. So, if we look at a machine, the signals will change if a mammal or a bird falls asleep. But we never, ever really see the signals change when less highly evolved animals sleep, like fish or frogs. So, these animals kind of look like they're sleeping because they're not really moving and they're not really paying attention to what's going on around them. So, it does superficially look like they're sleeping. I need more hands. But scientists really aren't sure what's going on. They don't know if this is just simply a form of resting if it's ancestral form of sleep. So, they're not really sure even now. But sleep in its most evolved form is thought to have appeared first among birds about 100 million years ago. But sleep among birds is still very different than sleep among humans. But mammals such as rats, cats and monkeys do have a form of sleep where the various stages are more familiar to our own. So, how long animals sleep really depends on something that we call the danger factor. So, big eating mammals like lions aren't really in much danger. So, they'll sleep a lot, like 17 to 19 hours a day. Animals that sleep in really well protected places, they can clock in a lot of time too. Like bats and caves might snooze for 19 out of every 24 hours. Oh God, that must be nice. But when it comes to what we consider prey animals, it becomes critically important to maintain a state of permanent alertness to survive. So, it makes sense that these types of species like drafts would sleep for only brief intervals. Drafts really sleep more than a few hours a day. Now, when it comes to dolphins, just like other mammals, in a lot of ways, they're a lot like us. They're warm-blooded, they bear live young, they breathe air, and they require sleep. But land-dwelling animals like us, we have this really unique thing where we actually breathe involuntarily. This means you don't need to think about breathing and to do it. Our body will take in air automatically if we need it. But if you're living in an undersea environment, like dolphins, you actively need to decide whether or not to sleep, or you'll drown. So, the thing is, in order to make a conscious decision about whether or not you're going to breathe, you have to be conscious. And one of the defining characteristics of sleep is our consciousness. So, for a tired dolphin, the problem of both sleeping and breathing becomes a little more problematic than it does with us. So, dolphins do this amazing thing where they've adapted one half of their brain to sleep at a time. When brain hemisphere actually goes to sleep, well, the other one typically shows all the signs of being awake. They'll sleep with one eye open and keep the other eye closed to pay attention to what's going around. So, even though not all animals exhibit a state that means the scientific criteria of sleep and wakefulness, it seems that the ones that don't do go through some period of inactivity and rest, but presence of such a period cannot be assumed to be indisputable proof that they're experiencing what we think of as sleep. It's kind of astonishing to consider that the existence of REM sleep remained unknown to science to the second half of the 20th century. REM sleep was discovered in 1952 by a young graduate student in the University of Chicago while he was working on the world's first specialized sleep laboratory. He was monitoring the sleep of his own eight-year-old son when, to his surprise, he saw dramatic changes in the EEG reading. At first, the young graduate student just assumed that the equipment had a malfunction. Until he investigated the anomaly further and started to figure out what we were later to understand is the signatures of the onset of REM sleep. Now, convincing his research supervisor who would become the man that we considered the founder of modern sleep research about the seriousness of his finding would be a really hard sell because his supervisor was going by the theory that sleep was an essentially a passive state, which is what everybody believed at that time. So his discovery actually would disprove his supervisor's theory. So there was a lot of infighting because they didn't want to believe it. But as the evidence started to mount, there was no doubting that this young graduate student had discovered something that would turn all our previous ideas of sleep on its head. Now, the failure of scientists to notice REM sleep before 1952 is even more peculiar when you consider that discovery did not really require any sort of electronics. Thanks to the bulging human eyeball, the rapid movements that are characteristics of REM sleep are plainly visible if an observer had been looking. So why hadn't anybody been looking? Well, the reason that REM sleep was not seen for so long is it came down to a combination of a lot of things. It came down to the combination of the fact that we thought we knew everything that there was to know about sleep. We all sleep, right? So, you know, we just assumed that we knew what was going on. So, and also there just really wasn't any, you know, nobody really cared about sleep that time. They didn't care about researching it because why would we research a topic that we already knew everything about? And then there was also the fact that technology does not always keep pace with our ambition. Before the discovery of REM sleep, researchers always switched off their recording devices after the subject had been asleep for a while in order to save paper. Because you guys have to understand that in the early days of sleep research, measurements were recorded on continuous pen traces on a roll of rapidly moving paper. So a full night recording of eight hours of sleep could take half a mile of paper. So, before the invention of computers, the ability, you know, and our ability, we just take advantage that we can like store large amounts of data, right? You had to pay for this paper. You had to pay for the pens. So the ability, their want to economize made sense, you know, so of course they weren't looking. But unfortunately the first episode of REM sleep really happens after an hour. So the machines would have long since been turned off. So this is basically why they just didn't notice it. And if you really think about it, it kind of makes sense. But also we had a lot of misconceptions about sleep. We just assumed that it became largely dormant. You can tell that it doesn't. You know, we just assumed like a light bulb. We just, you know, like a quiet death. And now we're realizing that there's a whole lot that we don't know about sleep. So, I mean, our short-sightedness really makes sense. That they wouldn't, their belief system at the time just wasn't, they weren't going to look for it. But lucky for us, it was a super lucky accident. Because with the discovery of REM sleep came the further groundbreaking work that linked REM sleep to dreaming. And our whole concept of the cylindrical nature of sleep. Because this is an entirely new concept and it's really not that old. So, what we think of is sleep is actually made up of two wildly different states. So we just talked about REM, right? And then we have a different stage as well called N-REM. So, N-REM, which aptly named us just kind of like non-REM, right? Is actually divided into four different states that each have their own characteristic unique electrical brain pattern. So, as we know, I'm sure most people in this room know, it's cylindrical, right? You have like, it lasts about 19 to 110 minutes the entire cycle, right? So, the first stage is asleep, have relatively short REM. And then long periods of REM sleep. But later on the night, it actually changes. And the REM periods lengthen and N-REM time decreases. So, now I'm going to bore you and we're going to go through the sleep stages, hooray. So, a sleep one is actually quite light. You drift in and out of sleep and still can be awakened easily. So, basically in the first stage, your muscle activity slows, your eyes movement slows. Stage two is also a stage of light sleep. But your eye movements stop, you know, your muscles start to relax and your brain waves become slower with only an occasional burst of rapid brain waves that you can see as spikes. You spend about half your time sleeping in stage two. Stage three has extremely slow brain waves that are interspersed with small, faster waves. And in stage four, the brain now produces slow brain waves almost exclusively. Now, when people talk about deep sleep, they're usually talking about stages three and four. Because this is the time where it's difficult to awake someone. And if you wake them up, they become disoriented and tell you to go away, not so nicely. But an interesting note about deep sleep is this is when sleepwalking happens. So, and it doesn't, it's most likely to occur as anything in life you have to make broad generalizations. So, sleepwalking behaviors can range from harmless to inappropriate to potentially dangerous to the sleepwalker or to people around them. There's actually been several rare cases of alleged acts of homicide that have occurred while people were sleepwalking. So, early researchers actually called REM sleep paradoxical sleep. Because it really is paradoxical when you think about it. So, the electrical activity in your brain is similar to that of waking consciousness. So, if you look on an EEG, they look the same. But your muscles have stopped moving. And for all attention to those purposes, you are paralyzed. So, your brain is being bombarded with a stimuli while you lie there frozen. So, many areas of your brain become active but a lot become less active like your primary visual cortex. Because REM sleep is associated with dreaming, the areas involved in processing visual associations actually form a closed system. So, they're operating in isolation of sensory input and output that you normally connect your brain to the outside world, you know, thus dreaming. So, your eyes move rapidly, immersive activity underneath your closed eyelids. And your heart and your muscle are also not paralyzed because that would not be so much fun. Because they're actually connected to a separate part, a separate nerve system that allows them not to be paralyzed. So, as you can see, REM and NREM sleep in many ways are as different from one another as they are from wakefulness. But yet they're still grouped together in one category. So, sleeping and waking. So, virtually all our bodily functions exhibit a 24-hour cycle that's governed by an internal clock. And most obvious of all these clocks, of course, is our daily cycle of sleep and activity. But pretty much like it's not just sleeping and waking, almost every biological process can be measured by this clock, including immune function, hormone levels, digestion, even urine production. So, they all have these daily rhythms which I'm sure you've all heard as circadian rhythms, right? We've all heard of this, I'm not telling you something you already know. So, these are found in insects, plants, and even bacteria. It's been said that the 24-hour circadian rhythm evolved because the earth revolved. The biological clocks in humans and other species are built to run within a period of approximately 24 hours, but they're also responsible to environmental time cues. And they reset each day by those cues to ensure that they remain in close synchronicity with the physical world. So, there's a good biological reason why our eternal clocks are readjusting every day according to environmental time cues. The duration of daylight varies with the seasons and animals therefore must adjust their activity cycles so that they sleep and wake at the right time. But there's more to this story than going to sleep when it gets dark and waking again when it gets light. The sleep cycle stems from an interaction between two systems, the circadian clock, and a separate sleep-wake homeostatic process. Sleep occurs because of these two natural forces. There's actually a battle going on in your brain right now between the need to sleep due to a period of prior wakefulness of this weekend and the feeling of alertness that comes from being apart, that comes from the circadian rhythms. So, we start to accumulate something that they call sleep debt. From the moment we stop sleeping and that debt increases the longer we stay awake. If we don't sleep and reset the brain's balance, our sleep debt will increase in strength until sleep deprivation all but forces us to sleep. The two systems usually counterbalance each other, but however, they do operate independently and you've probably noticed this, that they become misaligned. If you've done shift work, if you've had jet lag, you'll notice that you're experiencing a signal to be wake up when you actually need to be asleep and vice versa. So, given the crucial importance of light cues, it should not come as a surprise that blind people actually have experienced larger problems with sleeping and waking than people who have sight, because since they don't have the sun on their retinas, they're unable to really be able to change their clock and synchronize with the outside world. So, but I mean, we have more factors than just this, than these two systems. We can also be influenced by drugs, willpower, scheduled social activities, stress, but in the end of it all, sleep will always conquer our best intentions, even though we try to stay awake. But if you ever did make the decision to stop sleeping entirely, it's not the sleeping and not sleeping that would kill you per se. Actually, it would be the stress on your immune system and eventually what would happen is that you'd reach a certain point of sleep deprivation that it would have so much wear and tear on your immune system that it would cause it to collapse and you would die painfully from widespread massive infections. Yay! So just in case you ever decide to try that little project, I wish you well. So now you've learned about the internal clocks that regulate sleeping and waking. It should help you understand more about when we obtain less sleep than we need, why we have a tendency to fall asleep, and why, when we get extra sleep, why we don't wanna sleep so much. This ensures that we have the same amount of sleep each day on average, so that it kinda makes sense. But when we stay in a state of wakefulness for a period of time, we experience what's called a sleep debt. So as a general rule, and I'm pretty much willing to go out and be beyond general on this, every single one of us in this room is carrying a sleep debt. But the thing is, you need to have a sleep debt because you need sufficient sleep debt in the day in order to fall asleep at night. But the problem is, the larger the debt, the stronger our tendency will be to fall to sleep. And the consequences of an overly large sleep debt is that we have difficulty responding to rapidly changing situations and making rational judgments. You'll also eventually experience the occurrence of this really neat little thing that we've just really learned more about in these last few years called microsleeps. And a microsleep is a short period of time that they usually define between 10 seconds in a minute they like to get a little loose on their definitions. Where the brain actually enters a sleep state regardless of what you are doing at the time. Doesn't matter. If you are tired enough, you will fall asleep. And so quite often the affected individual has been asleep for such a short period of time, they don't even know that a momentary blackout has occurred because in their memory they, you know, it's such a short period of time that they haven't noticed they've been asleep. So microsleeps combined with attention laps that they cause can become extremely dangerous when they occur during a situation where continual alertness is demanded, right? So sleep debt related problems are most predictable actually during certain times of the day because our physical and mental functions increase and decrease with the sleep wake cycle I just told you about. So, oh, there goes my attention span. So, yeah, so, oh yeah. So it's no surprise to you guys that we get tired from 1 a.m. to 4 p.m. And then 12 hours later, you guys have probably noticed after lunch you'll also become sleepy again from between 1 p.m. to 4 p.m. So a study by the U.S. National Commission on Sleep Disorders has determined that the direct cost of accidents resulting from sleep debt are 56 billion a year. As well in a single year there's approximately 25,000 deaths and 250,000 disabling accidents. Which really isn't a surprise that most of these accidents actually happen from car accidents because when you consider it only takes a car at 55 miles per hour. If you fall asleep for four seconds, you've crossed the length of a football field and you don't know and you won't hear the horn until it's too late. So this comes apart where you can kind of fall asleep. When I submitted my abstract, I was like, oh, we'll go through the current theories on sleep. And then I was like, wow, I totally forgot how boring they were. Because as I said that, really, we still don't know a lot about sleep. So these theories are kind of common, like they're kind of common knowledge. They're not going to be any surprise to you. The third theory is actually a newer theory. And they're actually not, it's kind of in dispute right now. So basically I'm not going to tell you anything you don't really know. So throughout human history, scientists and scholars have mused on theories about the purpose of sleep. But it's only recently researchers have discovered a way to study sleep in an objective way. We knew very little about sleep scientifically before the 1950s. And there wasn't even a standardized tool for measuring sleepiness until the 1970s. But now all we can investigate sleep with machines to give us a better view on the sleeping brain, we still are like, we don't know. So everybody has a bunch of theories why they think we sleep. So even with all our newest machines, we still have no idea. So the following are the three major theories on sleep. So number one is the repair and restoration theory on sleep, which suggests that sleep is essential for revitalizing, restoring physical processes that keep the brain and mind healthy for proper functioning. This theory suggests that N-RAM sleep is important for restoring physical functions. Well, REM sleep is essential for restoring mental functions. Now, the support for this theory is provided by research that shows that periods of REM sleep increase following periods of sleep deprivation. And I'm sure you guys have all noticed if you do a lot of strenuous activity, all you want to do is sleep. So it also during sleep, the body increases rates of cell division and protein synthesis. So this further suggests that this theory may be valid. Now the second theory is the evolutionary theory, which they also consider the adaptive theory of sleep. So we were talking about this before and it suggests that periods of activity and activity evolved as means of conserving energy. Because according to this theory, as we talked about, animals will sleep for different periods of time depending on how hazardous the situation is. So support for this theory comes from the comparative research of different animals. So animals that have less predators will sleep for a longer period of time and animals that have more predators will sleep for a less period of time. So, and there's a pretty big gap. Like you're talking from like 12 to 15 hours to like four to seven. So there's a pretty large gap. So the third theory is one that they've been talking about quite often recently, which is the information consolidation theory of sleep. So this is based on the fact that cognitive research says that we need to sleep in order to process and remember information that we've required during the day. So it argues that we need to sleep in order for our brain to sort through things to be ready for the next day to come. And the support for this idea stems from a number of sleep deprivation studies that demonstrate a lack of sleep as years impact on the ability to recall and remember information. And I'm sure you don't necessarily have all your labs at home yet, but I'm sure this is no surprise that if you've been up for a while, it's harder to remember things. So while there is research and evidence to support each one of these theories on sleep, there is no clear cut support for just any one single theory. It could be that all these theories are correct, part of these theories are correct, they could all be part of the proposal, or they could all be wrong. We just really don't know at this point. All we know that is that sleeping has many physiological, many different parts. And it's not within the realm of possibility that we'll discover in something entirely new that we never considered before. So it actually usually surprises people that there's actually more than 70 different types of sleep disorders. But lucky for us, they can easily be sorted into three categories. We have lack of sleep, disturbed sleep, and excessive sleep. And since we are very limited by time today, I'm just gonna cover some of the more common ones that you've probably heard about and have not really considered. But the reason we're covering it is it's gonna come up when we're talking about the sleep lab later, right? See, because you kinda have to know what problems and categories that fall in so you know what to look for. So insomnia is considered a lack of sleep disorder. And I've noticed that within insomnia, a lot of people are kind of confused about it. They don't really realize that it's not only having difficulty falling asleep, it's also staying asleep. And you can also be considered having insomnia if you think you're sleeping, but then you wake up and you're not really well rested. So, I mean, it's a pretty broad, generalized character category. But I'll talk to people and they'll say, well, I don't have insomnia because I can fall asleep. But just falling asleep isn't necessarily, like just because you can fall asleep easily doesn't mean that there's, if you're tired during the day, then there's a problem. So apnea comes up a lot. And it's an example of disturbed sleep disorder. And we really, with apnea basically, there's only two things that we can really do for it. Because it's an interruption of breathing during sleep, it's a mechanical problem, something happens with the windpipe. And so what happens is we really have two options right now. We have surgery or we have masks for people to wear at night. So, but it's a very, very common sleep problem. And we really, when you consider how long we've been at this, it's really not the best option. So there's also something called Restless Leg Syndrome and periodic limb movement disorder. And if you've ever slept beside one of these people, you know exactly what I'm talking about. So, but they will wake themselves up because they'll move their legs and their sleep or they'll move their arms in their sleep. And it will then cause insomnia. So you can have problems that cause other disorders. So, now narcolepsy is one that people talk about a lot. But there's not, a lot of people don't necessarily really understand narcolepsy. It's thought to be genetic, but they're not really sure. It could be brain damage. It could be, they just really don't know why. And it causes individuals to fall asleep uncontrollably during the day for a period of less than a minute to half an hour. And these sleep attacks can occur at any time. Doesn't matter. Generally, if you, and the worst part for narcoleptics is if it's an emotional thing, if you're feeling a lot emotionally, it'll happen. You can fall asleep during sex. You could be on stage, given a speech and you will fall asleep. And the most interesting thing about narcolepsies, you actually go straight into REM. Like, you skip everything else. So, it's quite interesting, especially when you think about what kind of a disorder that is that you would be able to skip everything else. So, okay. How are we doing for time? Am I ready to head to time now? Okay, woo! So, this is with sleep study. I guess most people know what sleep studies are or you wouldn't be here. So, but sleep clinics, sleep laboratories, they're all pretty much the same thing. So, you have a bunch of different sensors that are attached to you that monitor a bunch of different things. So, and we can monitor a lot of things like airflow, breathing, muscle tone, leg movement. They watch you on camera so they can figure out what's going on. So, but a lot of people will ask me like this year, they're always like, wow, you know, a sleep lab. That's pretty, pretty cool. That's a good idea, but why? Why would you want to make a homebrew sleep lab? I don't really understand. Well, for me the problem has come from the fact that this was definitely a very selfish project. I'm lucky enough that I seem to be genetically flawed and pretty much for a decade now I've had problems with fatigue that they can't figure out what is going on. So, of course they sent me to a sleep lab, right? And a lot of people don't understand with chemical sleep. I mean, we've talked about animals, we've talked about what sleep is. With sleeping pills, they only manage symptoms. They are not a cure, right? And as we've learned, just because you are unconscious doesn't mean you're going through a sleep cycle. This does not mean you're gonna wake up well rested. It just puts you to sleep. And if you've ever taken any sleeping pills there's a lot of side effects that aren't fun. But when I went to the sleep clinic they diagnosed me with having chronic insomnia. And they said, well, the only thing we have for you is sleeping pills. So, among the characteristics I think I've inherited from my mother other than her very short stature and her winning smile is the fact that in my family there's a little quirk that none of us really seem to be affected by tranquilizers. And the only way we can be affected by tranquilizers is in these eye popping amazing amounts. It's the lamest superpower ever that I have. Because it's like, I'll have an operation and they'll be like, you're gonna kill her if you give her any more morphine. And I'm like, blink, blink. It's kind of cool to freak out the nurses but lamest superpower, I don't recommend it. So, and also in my family we have this like grab bag of the wackiest side effects. Like you know when they're like, one in 10,000 people will start singing I'm a little teapot if they take this drug. That would be me, right? So I get the weirdest, weirdest side effects. So people don't really consider this when we talk about drugs, the fact that what suits one person may not suit another person. And that basically how drugs work is they're all side effects. They just happen to be a common side effect that happens to a lot of people, right? So an individual dosage, what works for one person isn't gonna work for another person. So I went back to that sleep clinic and saw the doctor over and over again for several months. And eventually someone who I loved said to me, you gotta stop, you gotta stop, it's killing you. It's killing your body, you can't think, you can't do anything, the side effects are brutal and you stopped. So it's been mentioned to me on more than one occasion, not by anyone in this audience, but that I come off as very anti-doctor. But I don't believe that. I don't believe that the doctors are the enemy. That's not what I believe at all. I'd like to officially go on record and say that. I would not want to live in a world that had no doctors and I wouldn't wanna live in a country that doesn't have socialized medicine, because I'm Canadian. So that is not what my problem is. I guess the point is I'm not universally educated. A lot of people like to call me a wetware hacker, they like to call me a bio hacker, they like to call me a transhumanist. But I really don't consider myself any of these things. For me, if I was gonna consider myself anything, I like to joke that I'm a neuro fight. Which, because one day, because I read so much neuro stuff, I was reading a book once, and I saw neo fight and I read it as neuro fight. I'm like, what the hell's a neuro fight? And then it occurred to me that it seemed like the most appropriate thing, because a lot of people have been talking to me about the fact like, they're like, don't you think there's an ethical question with whether or not you should be giving people medical devices that haven't gone to school? But to me, I don't think there's anything ethically wrong with taking personal responsibility and figuring out how your brain works. And there's nothing wrong with building machines to figure out what's going on with you. So you can better work with your doctor. Okay, so I'm getting flagged. So basically the world of science isn't for academics. We can all be scientists when it comes to the laboratory of our own bodies. And all that's needed is a little bit of knowledge in the right tools. So now hopefully Keith won't kill me because I've gone into his time. And he's gonna explain to you exactly how to build your own sleep lab. So everybody, this is Keith, he rocks the cast, but give him a warm welcome. Okay. Hey, accessory. So I will present to you today how to build your very own sleep lab, the execution. So first off, I'll start off and I'll explain what we do here. We are collecting data for later interpretation. It's very, very simple. Doesn't need anything fancy. We used a Pentium 300, 600 megahertz to collect all this data. And what we're doing is we have an EEG, a heart rate monitor, an eye sensor, and an IR webcam that's collecting all this and then we're collecting it. What we don't do is we don't measure breathing measurements. We don't measure skin response on the face. And why we don't is very simply, restless leg and apnea are symptoms that are very obvious to an outside observer. It's a really, really low tech problem. So why apply high tech to it? At the heart, it's a desktop PC. Again, not very powerful. We've hooked up the modular EEG implementation of the Open EEG project. All of this interfaces with the desktop via RS232. Simple protocol. Keep it simple. It's great. We have a homebrew microcontroller. It's an atmel at mega 128 to collect the heart rate monitor and eye movement sensor signals. And finally, a USB webcam. Up here is just a quick flow chart of how all these pieces fit together if you're a visual learner. And this is a quick overview of how the EEG is put together. There is a series of electrodes. They're sent to an analog board where the signals are amplified and then filtered and then finally provided for ADC conversion on a digital EEG board. Also an atmel microcontroller, but this one's even simpler. And finally, it goes off via RS232 to the desktop. Here is just an electrical level schematic of all of the different sensors and how they're wired. We put a simple amplifier on the heart rate monitor that we hacked and there's a small change to that. We added a 10 microfarad cap on the signal for the heart rate monitor coming in, but otherwise is identical to this. So let me tell you about the sensors that we chose here. We got the modular EEG from the Open EEG project. It's very, very cheap. It's well tested. You can buy PCBs and build it yourself. You don't have to pay someone else to build it for you. It's open source and we needed it to detect what stage of sleep the user of the machine is in. We grabbed a wireless heart rate monitor by Oregon Scientific off of eBay. We cracked open the front and took an O-scope to it and started looking for traces and we got a nice clean square wave, one volt peak to peak with the heart rate of the user. It was actually pretty easy to do. We're rather impressed. And we need this to verify that the monitored user is calm. They're not going through night tremors, anything like that. We also have the eye movement sensor. It's a Fairchild QRB 1134. It's very, very cheap. Costs about a dollar a piece in bulk. It's well documented. There's data sheets all over the net. It's also quite simple and we needed this to verify REM sleep. And basically how it works is it's an IR LED and a photo transistor that are placed very, very close to each other. It bounces an infrared light beam right off the back of the retina through the iris and then back to the photo transistor. And if the eye moves to the left or the right, the amount of light reflected back changes and we can measure that. So let me tell you about construction pitfalls. The first thing I have to say is if you're thinking about building an EEG yourself, unless you're that poor, don't bother. It's worth the extra hundred bucks to have someone else do it for you. There are many, many hours spent of cramped soldering. It was incredibly easy to get all those traces bridged together or shorted to ground and the IC sockets aren't necessarily well labeled. We put a couple in backwards, blew them, had to replace them and the power supply is not exactly seen by default. It's a do-it-yourself kit so they assume that you're going to build your own. Some highlights from our construction. We constructed op-amp circuits on the fly to boost our signal that we thought was five volts but really wasn't. We added first order filters to remove all the noise coming in on the heart rate monitor and we found an interesting use for a soldering iron in the construction of the eye movement mask. Quite literally is a cheap dollar store plastic sleep mask. It was made of plastic as was the IR LED photo transistor combo so we quite literally melted them together to keep them in place. So we plugged in the EEG and nothing caught on fire, it was great. We hooked it up, took this screen cap and asked our test subject about their favorite topic. Apparently they were quite excited about it. We plugged in our heart rate monitor and eye movement sensor, captured some initial data and made sure that it worked correctly and it did. We're rather excited about that. Before we get to the juicy bits, I just wanted to provide a disclaimer. Despite any appearances to otherwise, we are not doctors and we don't pretend to be. It is rare but possible to give yourself an electric shock with this equipment. There is no warranty explicit or implied with anything we provide here and we are not responsible for the consequences of anyone attempting to duplicate our efforts. So without any further ado, these are the EEG outputs that we collected in the various stages of sleep. It goes upper left, upper right, lower left, lower right and those are the four stages that we successfully captured. And what each of these windows shows is there's an oscope view on the top, it's kinda noisy, we got a lot of 60 Hertz EMI coming in but we filtered it through software. And below that is a time versus frequency graph of the signal coming in. And the four little colored bands on the left represent each of the four stages of sleep. The app we're using came with that already put in. And so you can see on the first one there's nice purple band at the top and then the green one there's mostly energy there and so on and so forth. So we're quite excited with the results we got here. So you're probably wondering, well what is all this great data tell me? The EEG and iMovement sensors, you put the two data sets together and we can verify that the user is entering all stages of sleep going from awake to stage one to two, three, four and REM. And you'll notice here that awake and sleep look identical. That's why we need the iMovement sensor. Once we've gotten the EEG data, we can also do a nice frequency and amplitude analysis on the data that comes in. We didn't have time to actually do this formally but you can see here that it's fairly easy to identify each of the stages of sleep that the user is in based on that frequency plot. So other things that we can show here, we have camera stills that will show fitful sleep, sleep walking and restless leg. Elevated heart rate can also indicate stress or night terrors. We also threw up here just a quick flowchart of how our capture software worked. We spawn a couple of threads, catting dev.tty.s0 and s1 to a file. We capture IR camera frames. We decorate our frames with the captured data and then we sleep for 60 seconds and loop if appropriate. And if we exit, we kill all the background threads and away we go. So I wanted to talk about future expansion on this. We haven't even scratched the surface on what's available here. There's so much more that we could be doing but I didn't even have time for. We could be doing muscle sensors on the face instead of the IR LEDs for the eye sensors. And actually we got some feedback from our test subject that we showed you who actually said that it was very, very uncomfortable to have that mask on and would prefer something simpler such as a muscle sensor. We could also be measuring volume and temperature of the airflow coming out of the lungs. And we could, obviously, this is actually a PhD study that I found on Google a while back, automatically identify and categorize all this EEG data that's coming in. The frequency information is there so it's just a matter of writing a computer program to automatically analyze all this data. So in closing, I wanted to give our shout outs and say thanks to Abend, dead addict, locked in dream, Lynn, MB, old Grover, psychedelic bike, and Tottenkopf who will be presenting here pretty shortly. And we've put detailed schematics and source code on defcon17sleeplab.googlepages.com for all you guys to check out. And thank you very much.