You are on page 1of 5

Non-Intrusive Sleep Analyzer for Real Time

Detection of Sleep Anomalies

Krasimir Tonchev1, Pavlina Koleva2, Agata Manolova3, Georgi Tsenov4, and Vladimir Poulkov5
Faculty of Telecommunications and Faculty of Automatics
Technical University of Sofia
Sofia, Bulgaria
Email: {k_tonchev, p_koleva, amanolova, gogotzenov, vkp,}@tu-sofia.bg

Abstract—Solutions for caring for the elderly both efficacious electroencephalogram (EEG), the electrooculogram (EOG), the
and cost-effective are given by Ambient Assisted Living (AAL) electromyogram (EMG), respiration data, etc. The system
systems that combine the research fields of intelligent systems proposed by Rechtschaffen and Kales (R&K) [4] is accepted as
and communication technologies. These systems are promising standard for visual scoring of human sleep. The amount of
for the improvement of the quality of life of elderly and disabled time an adult needs to sleep each night varies from person to
people. One important characteristic of health and well-being is person, and probably has to do with genetics. But the National
sleep. While sleep quantity is directly measurable, its quality has Institutes of Health suggests that adults get between 7 and 8
traditionally been assessed with subjective methods such as hours of sleep each night. To keep with current health demand
questionnaires. In this paper, we propose a non-intrusive sleep
from people with different needs, a number of smartphone
analyzer for real time detection of sleep anomalies, part of an
effective AAL system. The proposed solution is based on
apps, wearable tech and different home sensors on the market
combination of non-invasive sensors and an algorithm for sleep claim to track sleep patterns that aim to help users understand
analysis with two stages – low and high level reasoning. It also what might lead to a bad night's rest, so the triggers for bad
offers the opportunity to include third party devices. Using the sleep can be avoided.
analyzer we can monitor basic sleep behavior and to detect sleep Generally, there are three types of sleep gadgets on the
anomalies, which can serve as an important indicator for both market. The first are the fitness trackers that have sleep-
mental and physical health.
tracking capabilities. Most of these gadgets involve a wearable
Keywords—Sleep Monitoring, Context Awareness, Sleep
wristband or sensor that tracks the user’s body movements as
Anomaly Detection, REM, NREM, HMM he or she sleeps. Some research is done over the capabilities of
such sensors and the modalities they measure to estimate
accurately sleep quality [5, 6]. The authors prove that wrist
I. INTRODUCTION devices yield accurate and valid data for sleep estimation. The
Sleep is an important part of health and well-being. The second category is smartphone apps, which use the
importance of sleep quality often manifests itself when there is accelerometer that is built into the user’s phone to capture his
a disturbance: the lack of quality sleep has immediate movements. One research [7] uses the Best Effort Sleep (BES)
consequences in the form of reduced daytime functionality, and model to develop a smartphone sleep monitoring system. This
long-term consequences affecting both mental and physical model estimates only sleep duration via phone activity. Even
health. The study of sleep disorders has for a long time been though according to the authors the model proves to be
confined to clinical environments, and patients have had to accurate enough, sleep data collected by on-body sensors is
endure cumbersome procedures involving multiple electrodes more reliable. The third category is different types of bed
placed on the body. Recent developments in sensor technology sensors that offer sleep measurement in an unobtrusive way. A
as well as data analysis methods have enabled continuous, lot of products are currently present on the market and a lot of
unobtrusive sleep data recording in the home environment. research is done on the data that can be gathered by these
This has opened new possibilities for studying various sleep sensors [8, 9].
parameters and their effect on the quality of sleep [1].
The main contribution of this paper is to present a non-
Although the human sleep still remains a largely unknown intrusive sleep analyzer by monitoring in real time several
area, it is proven that this process is not homogeneous. It events for detecting sleep anomalies, using a combination of
consists of two broad types: rapid eye movement sleep (REM) sensors as bed pressure sensor, microphone and accelerometer.
and non-rapid eye movement sleep (NREM) [2]. The sleep This sleep analyzer can also incorporate third party devices that
quality is considered to be mainly a subjective phenomenon can offer additional measurements not only for sleep pattern
[3], however the total sleep duration and the amount of time analysis but for other everyday health monitoring.
spent in each mentioned stage are important for diagnosis of
The rest of the paper is organized as follows: the next
most of the sleep disorders. The stages in sleep can be inferred
section describes the overview of the system including the
from some well-known physiological signals: the
algorithm for the sleep analyzer incorporated in the EU project
This work was supported in part by the Grant Agreement No: 610658,
eWALL: eWall for Active Long Living” of the EU Seventh Framework
Programme. The authors wish to thank the invaluable help received from all
the consortium members.

978-1-5090-1288-6/16/$31.00 ©2016 IEEE 400 TSP 2016


“eWALL” (http://ewallproject.eu). Section III introduces the TABLE I. NECESSARY MEASUREMENTS FOR SLEEP ANALYSIS
implementation details and illustrates the experimental results. Measurement Description
The final section draws the conclusion and suggests the scope Time in bed
of future work. This is the total time user was in bed.
(TB) in hours
Total Sleep time The total sleep time is calculated by accumulating
(TST) in hours the time user is asleep for particular night.
II. SLEEP ANALYZER DESCRIPTION Sleep efficiency This is the ratio of the total time user was asleep
(SE) over the total time in bed.
A. Non-invasive sensors Sleep latency
The time needed for the user to fall asleep.
AAL applications have special architectural requirements, (IM)
Snoring time
including low power consumption, low intrusiveness and low (SNR)
The total time user spent snoring.
computing power [10]. Based on these requirements we have This is the Pittsburgh Sleep Quality Index (PSQI),
selected the three main hardware components of the sleep PSQI
standard for measuring sleep quality [12].
analyzer’s current implementation: bed pressure sensor, O2 statistics
Min, Max and average value of the O2 saturation
microphone, and accelerometer. measurements conducted while user was asleep.
Number of times the user woke up during the
Woke-ups count
One of the important modalities delivering important night.
information about user’s activity and movements in bed during
sleep is the accelerometer. Our system monitors how many B. Algorithm description
times a person tosses and turns during the course of the night In Fig. 1 is illustrated the algorithm, implemented in two
and how many times the person leaves the bed. In this way, the stages. The first one performs low level reasoning and extracts
frequency of movements can help in determining whether a the sleep events described in the previous subsection. The
person is asleep or not. Frequency of movements is also second stage performs high level reasoning described in Table
different for different sleep stages and thus can be related to the 1 and delivers the information to the users or the caregivers.
sleep stage a person is currently in. Transitions between
different sleep stages also correspond to change in frequency of
body movements. The sleep events that are measured by this
sensor in the system are: body movement shorter than 15 sec.
or longer than 15 sec.
The bed pressure sensor delivers a Boolean type of
information, whether or not the user is on or off bed. Although
in some sense this information overlaps with the one from the Fig. 1. Sleep Analyzer reasoning stages
accelerometer, fusing both modalities can improve the
inference and reduce errors. The sleep events that are measured The reason for this two stage implementation is primary for
by this sensor in the system are: in and out of bed, morning exit implementation and optimization. Performing the low level
and out of bed during the night. reasoning requires the component to be positioned “close” to
Another modality, which is utilized to evaluate the user’s the database where high level rates of data are required. Also,
sleep, is audio. The sound waves produced on account of the algorithm runs constantly, inferring the different sleep
inhalation and exhalation are used to monitor the respiration states the user is in. On the other hand, the high level reasoning
rate. We use a microphone sensor to capture the breath sounds. requires the data of the previous night to be already collected,
The sounds produced during inhalation and exhalation is given i.e. the low level reasoning to be finished for the night. The
as input, the voltage variations produced by it are amplified and synchronization between the two stages is simple. The high
integrated to obtain a consolidated pattern. The microphone is level reasoning starts after receiving the woke-up event.
used to measure snoring. Snoring is usually the major signal Additional reason for such division is the integration with Fitbit
indicating obstructive sleep apnea (OSA), which is (https://www.fitbit.com). As can be seen from the Fig.1, Fitbit
characterized by repetitive upper airway obstruction during is a third party component, which delivers partially low level,
sleep, causing total or partial cessation of airflow (apneas and partially high level reasoning. This information has to be
hypopneas) [11]. The recorded signal shows a voltage signal further processed before consumed by the applications and this
close to zero for a long period due to absence of respiration, is done by the high level reasoning stage.
after which there is increase in amplitude due to deep The low level reasoning consumes the data delivered by the
inspiration after apnea. The interval gives the apnea duration, sensors which were introduced in the previous sub-section.
time interval and nature of apnea. The sleep events that are Based on this data an estimate of user’s sleep activity is
measured by this sensor in the system are: snoring, breathing performed. The used set of events is: the person is out of bed
levels – fast, slow and normal. and thus does not sleep; the person is in bed, but does not
Using the described modalities the system can extract sleep; the person is in bed and sleeps; the person starts snoring;
important information about the user’s sleep states. An expert the person stops snoring. This set of events, excluding the
work group within the eWALL consortium decided upon the snoring event, requires dynamical analysis over time of the
most relevant information using the sensors described above. input sensory information. Analyzing the information in static
Based on their analysis, the measurements selected for manner i.e. on a sample basis can provide erroneous results.
implementation are given in Table 1. Since the sleep events follow a natural pattern, a better

401
approach would be to perform time dependent analysis. ' - ( P )q ( 1* $
1 1

Avoiding additional complications the best solution is the first % - ( P )q ( 2 * " (3)
order Hidden Markov Model (HMM). In the model prior !(% 2
" 1

% "
probabilities which reflect the common belief of the sleep % "
pattern could also be included. This is rather useful in cases &- ( PN
)q ( N *# 1 N !1

where there is no, or very small amount of data. Block diagram


of the low level reasoning of the Sleep analyzer is depicted in The sequence of observation is represented as a matrix
Fig. 2 a). As input, the low level reasoning receives Moving O=(o1,o2,…,oT), arranged from feature vectors
Average indicators (IMA) values, which are accumulated o t ( .o1t , o2t ,..., oDt / ,1 + t + T , where T is the number of
T
absolute values of accelerometer data per 10 seconds and bed
pressure sensor data. The HMM is split in two: probabilities observations and D is the feature vector dimensionality. The
buildup and Viterbi decoder. statistical dependence between o and a state q = j = 1, 2, … N
is given by a set of characteristics B ( 0b j )o *1N which are
j (1

Gaussian Probability Density Functions (PDF) with mean


vectors "j and covariance matrices #j. Each bj(o) is calculated
according to:

1 ,
1
)o ," j *T # j )o ," j *
,1
(4)
b j )o * ( e 2

)2- *
D
) *
det # j

The Prior probability depicted on the figure is also Gaussian


with high variance and it represents our belief on when the
user is most probably to be sleeping. The full HMM
description is denoted with ! = (A, B, !). The generative
a) b)
nature of the HMM is illustrated on Fig. 3: the model starts
with selecting an initial state j from the vector of the initial
Fig. 2. a) Block diagram of Sleep analyzer’s low level reasoning and b) High state distribution !, an observation is generated from the state j
level reasoning of Sleep analyzer by the distribution bj(ot), the new state is generated from the
transition probability matrix, move to the next state t = t + 1
The HMM itself is a probabilistic model used to describe the and so on.
statistical dependency between “hidden” sequence of states q
and the dependency between a given state qt and the directly
observable feature vector ot (an observation) as well (t
denotes the time step). The HMM can be regarded as
description of a double stochastic process. The statistical
dependency between states is given by the transition
probability matrix A:

'a 11
a 12
! a1N $
%a a ! a " (1)
A(% 21 22 2N
" ,
% " " # " "
% "
&a N1
a N2
! aNN # N !N

where N denotes the number of states. Each element in A: Fig. 3. The generative nature of a HMM with two states

a ( P)q ( j | q ( i *,1 + i, j + N (2) The “optimal” states sequence q* is the most probable one
ij t t ,1
given the observations and model parameters:
is the probability the model is being in state j given the
previous state i. In the given context the transitions from q * ( arg max 0P )q | O, 2 *1 (
q
nonconsecutive states are impossible, so a13 = 0 and a31 = 0 (5)
(see Fig.3). The information about the state in the first time 8 p )q, O | 2 * 5
( arg max 7 4(
step t = 1 is given by the vector of the initial state distribution q 6 p )O | 2 * 3
!: ( arg max 0P )q, O | 2 *1
q

A computational efficient solution for (5) is the Viterbi

402
algorithm. It exploits the likelihood "t(i) of the most probable time in the bed. This value is in %
sleepLatency The time in minutes it takes for the user to fall asleep.
state sequence for the first t observations and the sequence
frequencyWakingUp How many times the user woke up
finishes with state i at time t. The Viterbi algorithm consists of snoringTime The total time in minutes the user was snoring
the following steps: timeInBed The total time in minutes the user spent in the bed
1. Initialization of the first phase. Set t = 2; calculate remTime The time in minutes, user was in REM state
"1(i)=#1bi(o1) and set $1(i) = 0; Psqi The PSQI index
2. Induction. Calculate 9 t )i * ( max09 t ,1 ) j *a ji 1bi )o t * and the
O2 The average value of the O2 saturation measurements
measured during the course of sleep
1+ j + N
bedOnTime Timestamp in milliseconds the user went on bed
state that maximizes "t(i) i.e. : t )i * ( arg max 09 t ,1 ) j *a ji 1 ; bedOffTime Timestamp in milliseconds the user went out of bed
1+ j + N

3. Move to next time step. Set t = t + 1. If t + T , go to step


2, otherwise go to step 4; IV. CONCLUSION
4. End of the first phase and initialization of the second In this paper we present a non-intrusive sleep analyzer for real
phase. Calculate qT* ( arg max 09 T )i *1 and set t = T - 1; time detection of sleep anomalies based on HMM and Viterbi
1+i + N
algorithm. The Sleep Analyzer component is implemented as
5. Decode the current state. Calculate an IDSS reasoner and is fully functional. The design and
) *
qt ( : t ;1 qt ;1 ,1 + t + T , 1 ;
* * architectural definition of this hardware and software
component, together with its deployment model is operational
6. Move to the previous time step. Set t = t - 1. If t < 1 , go
and ready for end-user testing. To date the analyzer is installed
to step 5, otherwise terminate the procedure.
as part of the eWall smart home monitoring system in target
The output of the algorithm is the inferred sleep event patients’ homes and measurements of its performance will be
which is exposed to the rest of the system via REST endpoint. obtained in real life conditions. Using the analyzer we can
monitor basic sleep behavior and how to detect sleep
Once the sleep events are available and collected during anomalies, which can serve as an important indicator for both
the night a high level reasoning is performed. The high level mental and physical health of patients with COPD and MCI.
reasoning is depicted on Fig 2 b). After the sleep The utilization of PSQI index will be described in future work.
measurements are calculated, they are stored in the database
and are further exposed by REST endpoint. The high level
reasoning can take two inputs. One from Fitbit, while the other REFERENCES
from the low level reasoning. When the input is from Fitbit, [1] Carskadon, M.A., & Dement, W.C. (2011). Monitoring and staging
simple data re-formatting and re-calculation is performed in human sleep. In M.H. Kryger, T. Roth, & W.C. Dement (Eds.),
Principles and practice of sleep medicine, 5th edition, (pp 16-26).
order to meet eWALL requirements. When using sleep events,
[2] S. Benbadis, Sleep: A Comprehensive Handbook. John Wiley & Sons,
the sleep measurements from Table 1 are easy to calculate. Inc., 2005, pp. 989–1004.
[3] D. Buysse, C. Reynolds-3rd, T. Monk, S. Berman, and D. Kupfer, “The
III. IMPLEMENTATION TECHNIQUE pittsburgh sleep quality index: a new instrument for psychiatric practice
and research,” Psychiatry Res., vol. 28 (2), pp. 193–213, May 1989.
The sleep analyzer module is done in a way to reflect the
[4] A. Rechtschaffen and A. Kales, A Manual of Standardized Terminology,
two stages of reasoning. The low level reasoning is Techniques and Scoring System for Sleep Stages of Human Subjects.
implemented as a part of the Physical Activity Service brick, Washington DC, US Government Printing Office, 1969.
part of the eWall architecture, while the high level reasoning is [5] Jean-Louis, G. et al. (2001). Sleep estimation from wrist movement
done as an Intelligent Decision Support System (IDSS) quantified by different actigraphic modalities. J.Neuroscience Methods,
reasoner. The IDSS module leverages instantaneous situational 105(2), 185-191.
information to make inference on the current status of an end [6] Jean-Louis, G., Kripke, Cole RJ, Assmus JD, Langer RD, (2001). Sleep
user and to provide motivational messages and suggestions to detection with an accelerometer actigraph: comparisons with
polysomnography. Journal of Physiology & behavior 72 (1), 21-28.
take actions. In this respect, it is used to anticipate immediate
[7] Chen Z. et al., "Unobtrusive sleep monitoring using smartphones,"
or long term action, proactively offer situation-aware and Pervasive Computing Technologies for Healthcare, 2013 7th
usable content. The reason for including the low level International Conference on, 145-152, 2013.
reasoning as part of a service brick is the need for quick access [8] Juha M Kortelainen, Mark van Gils, and Juha Parkka, “Multichannel bed
to the IMA values. Since the service brick is already reading pressure sensor for sleep monitoring”, in Computing in Cardiology,
this data, and to avoid double reading, the low level reasoning IEEE, 2012, pp. 313–316.
is re-using it. Both, the low level reasoning and the high level [9] Paalasmaa, J., Waris, M., Toivonen, H., Leppäkorpi, L. & Partinen, M.,
reasoning expose endpoints. In Table II the response 2012. Unobtrusive Online Monitoring of Sleep at Home. 34th Int. Conf.
parameters from the sleepData endpoint are described. IEEE Engineering in Medicine and Biology Society (EMBC'12).
[10] Universal Open Platform and Reference Specification for Ambient
Assisted Living: http://www.universaal.org/
TABLE II. DESCRIPTION OF THE „SLEEPDATA“ ENDPOINT PARAMETERS [11] Oliveira CBG, Silva DGV, Moriya HT, Skomro R, Alencar AM,
Lorenzi-Filho G., Snoring: the silent signal in sleep medicine., Sleep Sci.
sleepData
2011;4(1):21 -27.
Parameters Description
Username The name of the user issuing the call [12] Mollayeva, T. et al. (2015). "The Pittsburgh sleep quality index as a
Timestamp The timestamp of the recorded measurements screening tool for sleep dysfunction in clinical and non-clinical samples:
totalSleepTime The total amount of hours the user slept in hours A systematic review and meta-analysis.". Sleep medicine reviews.
sleepEfficiency The total amount of sleep over the total amount of doi:10.1016/j.smrv.2015.01.00

403
404

You might also like