Nivedit Majumdar Nivedit Majumdar

The Science behind Sleep Tracking

[Continued from Sleep Tracking pt. 1]

With the Quantified Self movement and Lifelogging gaining a momentum and popularity like never before, sleep tracking has become all the more important in a fast paced world. A simple process of tracking sleep data through wearables and other Lifelogging devices goes a long way in telling the user the trends in his/her sleep patterns.

But then, we know all this. What is actually interesting is how Sleep Trackers work: What kind of machine learning algorithms do they use, what is the sleep cycle all about, and what is Actigraphy. In this article, I dive deep into the science behind sleep tracking!

 

SLEEP TRACKING REVISITED

I’ve already covered most of the terminologies involved in my article on Sleep Trackers here, but to understand how they work, I’ll briefly go over the basics again.

Before we learn about the types of sleep trackers, it is important to understand the types of sleep patterns. There are three types of sleep patterns: deep, light and REM.

emberify_types_of_sleep

In a nutshell, Deep Sleep is responsible for refreshing the body, Light Sleep denotes the transition between deep and REM and the REM Sleep phase is the stage where vivid dreams occur.

Now with these phases, it is also interesting to learn about the sleep patterns. I won’t go into much of the details (sleep study is a vast science which is extremely fascinating by its own right!), but I’ll skim over the basics.

THE SLEEP CYCLE

Sleep by itself is a very intricate affair, and it comprises of various stages, as shown in the following figure.

emberify_stages_of_sleep

So the ‘three types of sleep’ I spoke about earlier can actually be divided into five different phases of sleep.

STAGE 1 denotes the light sleep, STAGE 2 is a transition between Light to Deep Sleep, STAGE 3 is the actual Deep Sleep, STAGE 4 is the phase where the body is completely at rest and the muscle activity gets limited, and STAGE 5 – the REM sleep – denotes the transition from deep to light sleep to finally waking up.

Now these stages occur over multiple hours, as illustrated in this figure:

emberify_sleep_cycle_1

All these patterns play a major role in studying the hours of sleep earned. Sleep doctors and polysomnograms bank on these very patterns to gather trend patterns about sleep. And unsurprisingly enough, wearables too use this very data.

THE ROLE OF THE WEARABLE

Sleep trackers are already extremely popular among hardcore Lifeloggers for a long time now, but they have become more mainstream in recent times owing to the popularisation of cheap and efficient fitness-cum-sleep trackers. This has in turn encouraged more people to get acquainted with the processes involved in Lifelogging.

Sleep trackers are a topic that I’ve touched upon previously, but again, here’s a recap.

emberify_types_of_sleep_detectors

ACTIVE TRACKERS

These kind of trackers have a button which the user must press to enable sleep tracking on the fitness monitor. Needless to say, this feature comes bundled with most fitness trackers capable of tracking sleep.

PASSIVE TRACKERS

Here, there is a software element involved, where a particular time frame is defined as the ‘sleep time’ (typically between 12am and 6am). The tracker will sense for sleep only in this defined period, and this feature has the advantage of saving the battery power.

The key component in either case is the accelerometer, and the process of Actigraphy that is involved in measuring sleep.

ACTIGRAPHY EXPLAINED

One of the most challenging hurdles for fitness tracker corps is to make the tracking devices as non invasive as possible, and in this regard, actigraphy plays a major role.

A tiny sensor – generally called an actigraph unit – monitors the human rest or activity cycle. In the case of sleep trackers, it measures the sleep patterns and circadian rhythms over a long period of time and then intelligently assesses the sleep / wake behaviour of the individual.

In fact, the components of the Actigraph unit are pretty cool to know about. There’s a piezoelectric accelerometer, a low-pass filter to reduce the influence of external vibrations, a timer to stop and start the actigraph unit at various times, a memory to store the data and an interface – in recent times, this interface comes in the form of Bluetooth LE.

THE MACHINE LEARNING ALGORITHMS INVOLVED

Actigraphy, accelerometers, sleep trackers – all these depict mainly one aspect of the picture of sleep tracking, the hardware. The complex (and brilliant) stuff out here is done from the software side.

Sleep Tracking takes into use a few machine learning algorithms as well. I will be honest, I really can’t specify which sleep tracker utilises which machine learning algorithm, but here is a generalised overview.

emberify_machine_learning_algorithms_used_in_sleep_Tracking

 

C4.5 DECISION TREE ALGORITHM

The Decision Tree Algorithm is perhaps one of the most important algorithms involved in sleep tracking, and it generally involves mapping observations about an item to conclusions about the item’s target value (Source: Wikipedia). C4.5 in particular handles a large number of both continuous and discrete attributes, and is overall a very memory and resource efficient algorithm.

BAYESIAN NETWORK

This is a machine learning algorithm that is already widely in use in the medical field – to correlate diseases and their symptoms. Within this algorithm are included a gamut of more learning algorithms, which come into use while monitoring and tracking sleep patterns.

ARTIFICIAL NEURAL NETWORKS

And finally, how can we measure a trait of the human body without a machine learning algorithm that is directly inspired from the brain? Artificial Neural Networks model complex relationships between inputs and outputs to find generalised patterns in the data, and this is how sleep trackers can differentiate between the deep and light sleep patterns!

emberify_sleep

TO CONCLUDE

There’s been a lot of discussion on QS forums regarding how to utilise the sleep patterns to maximum use, and the key would be to maintain a lifestyle which would incorporate more hours of deep sleep in the patterns. The machine learning algorithms and the hardware will help you to keep a track of the hours slept, but it really depends on how well the user can analyse the patterns and make appropriate changes in his/her lifestyle.

Overall, sleep trackers might seem tiny, inconspicuous little devices, but in reality they harness a lot of power in both hardware and software aspects!

(Cover image is the author’s own sleep pattern from a regular Friday night.)

Sign up for our monthly mailing list