Click here to download SleepBoost (for Android)

One of the things I got sucked into researching last week (following an interesting post on the /r/nootropics forum) is the benefits of artificially enhancing slow waves during sleep.

If you’re not familiar with the sleep literature, slow waves are a type of electrical oscillation that occur in the brain during the deepest phases of sleep, so named because they are slow and large enough to actually produce a very distinctive visual pattern. Recently, we’ve discovered that these electrical waves are not just a product of a certain sleep stage, but also play an important role in cognition, especially memory. Generating artificial slow waves (using pulsed electrical stimulation) during sleep can actually enhance memory function.

What’s most interesting, however, is that enhancing these electrical oscillations doesn’t seem to require anything as exotic as electricity applied to the head. The brain’s intrinsic slow waves can actually be enhanced and entrained by simple sensory stimuli which occur at approximately the same frequency as the natural oscillations (about 0.1 to 1 Hz)

Since studies have shown that this (extremly noninvasive) type of stimulation can increase slow wave activity generated by the brain during sleep and might increase learning, there’s actually been a little bit of commercial interest in it. Phillips has sponsored a lot of the research, and just last month a company called Ultradia received a bunch of money on Kickstarter to make a “smart pillow”, which is apparently a pillow with a rechargeable device that contains motion sensors (to detect when you enter deep sleep), a speaker (to generate auditory stimuli), and bluetooth and data logging capabilities to analyze your sleep patterns.

Wait a minute. Isn’t that just a stripped-down smartphone?

It turns out that smartphones actually have pretty much all the capabilities needed to do this type of sleep enhancement. (in fact, there are a number of apps which use phone accelerometers to track sleep cycles already). Based on this, I decided to to take a crack at writing an app to replicate some of these experiments.

Incidentally, how would you do this? A number of researchers who work in this field recently recommended controlling the audio pulses based on feedback from an EEG system, which provides a signal that can be automatically analyzed to determine (1.) if you are in the correct phase of sleep to deliver pulses, and (2) modulate the volume of stimuli based on the brain’s response to deliver an effective “dose” without waking the person sleeping.

Unfortunately, EEG equipment is still far too expensive and uncomfortable for most people to use regularly. The alternative is to use motion sensing, which is more limited (it can’t distinguish between deep non-REM sleep and REM sleep, for instance) but does provide some limited insight into sleep cycles and has been successfully implemented in phones before. Importantly, this method supports both objectives outlined by the researchers: motion can be used both to estimate the current sleep stage and also to monitor for any disturbance triggered by the auditory stimuli (indicating that the volume is set too loud).

About a week (and several nights of sleep interrupted by waking up to adjust variables) later the result is Sleep Boost, an app designed to enhance slow-wave sleep by playing rhythmic bursts of pink noise at 0.8 Hz when the user enters deep sleep.

How it works

The basic flow of SleepBoost is pretty simple. When you start the app you can set four parameters: the duration that SleepBoost will generate sound for, how long it will wait before it starts generating sound (some research indicates that starting the pulses immediately when going to bed can increase sleep latency, therefore a delay might be desirable), and the “aggressiveness”, which controls the sensitivity of the motion sensor, how fast the volume increases during deep sleep, and how long the app will stop generating sound when motion is detected. The final option is a “double-blind” control—if checked, 50% of the “runs” with the app will be sham runs, which means that the device will generate sound for 10 minutes after the onset delay and then stop for the rest of the night. Whether a particular run was sham or real is both shown on the screen after the run finishes and logged in the app’s log file (more on that later) to facilitate running experiments.

Once you set the settings, the app will ask you to place the phone face down on your bed (near your pillow) and remain still for a few seconds (this is done to calibrate the sensor and prevent electronic noise or ambient vibration from triggering the motion sensor)

Once the app calibrates and the amount of time specified in the onset delay passes, the app begins active sleep monitoring. The algorithm here is pretty simple: volume of the pink noise pulses generated increases gradually at a constant rate until it reaches the maximum limit set by the user in the initial setup or the phone detects motion, in which case the volume immediately drops to 0 and the app waits several minutes before resuming ramping up the volume.

Despite its simplicity, this algorithm lets us do two things:First it can tell the difference between light and deep sleep( in light sleep there is enough motion that the volume is constantly reset, preventing sound from activating during this phase) and second it can detect motion triggered by the sound pulses (probably an indicator that the volume is too high) and compensate accordingly.

The issue that I discovered after a couple of nights is in the details. Without carefully selecting values for things like the rate at which volume increases or the minimum motion necessary to trigger stopping, the app tends to end up in one of two states:either ignoring all the motion (because the threshold is set too high) and playing sound all the time, or never allowing sound to play at all. It turns out it’s just really hard to figure out what the reasonable parameter values to accurately track sleep stages are before hand.

Rather than make users guess, the app recalibrate its motion sensitivity every 90 minutes to achieve a “activation target” of between 10 and 67 percent (that is, if sound is playing for less than 10 percent or more than two thirds of the time in any block the motion sensitivity will be adjusted up or down). This provides a way to make sure that the parameter values are at least within a reasonable range; though fine tuning still relies on the aggressiveness setting.

Logging and experiments

Another feature in SleepBoost is the ability to perform experiments using the “double-blind” mode. When this mode is activated half of the runs will the sham runs; the app will operate normally for 10 minutes after the onset delay but then cease generating sound. Whether a run was a sham or normal run is shown both on the “run complete” screen and logged in the log file.

The log file is located at the root of the device’s shared storage called “sleeplog.csv” The columns of this file correspond to data logged each second while the program is running, and, from left to right correspond to

Seconds since sleep monitoring began

Current volume(as a percentage of configured maximum volume)

Backoff time (the time (in the same format as the first column) when the app will resume generating pulses after it detects motion. If this value is greater than the first column (occurs in the future) no pulses will be generated, if it is less the app will generate pulses. This value is incremented by a certain amount (depending on agressiveness) every time a motion event occurs.

Scale factor. The threshold value is multiplied by this prior to comparing it to the amplitude of detected motion. If the detected motion is larger, pulse generation stops and the app enters backoff mode. The scale factor is controlled by the aggressiveness setting.

Threshold. The maximum motion detected during the calibration period.

Sham status. True if this trial is a sham trial, false if it is not.

Raw motion magnitude. This value is computed every time the reported acceleration changes (though it is only logged once per second) and reflects the difference between the current accelerometer reading and the previous accelerometer reading ((x+y+z)-(oldx+oldy+oldz))

Date.

Current time.

Try it out!

While I’ve used this app a few nights, I should point out that I’m far from having hard data that this kind of stimulation will actually make you better at anything (It’s an experiment, not a product). That said, if you’d like to try it out you can get the app from the Google Play store here.