# On-the-Fly Sleep Scoring Algorithm with Heart Rate, RR Intervals and Accelerometer as Input
###### Abstract  
In many applications, recognizing the depth of sleep (e.g., light, deep, REM sleep) while the subject is sleeping enables innovative features. For instance, in SAE Level 4 autonomous driving, a driver may need to takeover the vehicle control in case the autopilot is exiting its operational design domain. Depending on the depth of the sleep, the subject may need time to takeover effectively; hence, it is particularly relevant to know in which sleep stage the subject is (e.g., light sleep, deep sleep, and REM sleep), and possibly initiate actions to prevent the subject to remain in those sleep stages that lead to longer takeover time. Sleep stage classification can be achieved through an on-the-fly algorithm, which generates output in response to each input portion without knowledge of future inputs, unlike an off-Line algorithm that provides output just after receiving the entire input sequence. Various studies have analyzed algorithms or devices that identify sleep stages during the night; however, these typically require electroencephalography (EEG), which is obtrusive, or specialized devices. This study describes the development of an on-the-fly sleep-scoring algorithm using Heart Rate (HR), RR intervals, which is the distance between two consecutive heartbeats, and accelerometer data from a smartwatch, widespread, non-invasive, and affordable but accurate device. The subjects involved in our study wore a commercial off-the-shelf wearable device during a full night's sleep, and were also monitored using a reference medical device to establish the ground truth by means of a full polysomnography (PSG) analysis. The on-the-fly sleep scoring algorithm based on smartwatch data was tested against PSG-based scoring, achieving 88.46% accuracy, 91.42% precision, and 93.52% sensitivity in sleep-wake identification. Deep sleep was correctly identified 69.38% of times, light sleep in 50.62%, REM sleep 62.02% and wakefulness 73.48% of times. wearable devices; smartwatch; sleep scoring; on-the-fly algorithm +
Footnote †: journal: Sensors  
0000-0001-1001-199X/00/0000-0001-199X/0000-0001-199X/0000-0001-199X/00  
is suffering from sleep disorders, such as respiratory disturbances, which could prevent sufficient energy recovery during the night and lead to daytime drowsiness [5]. The medical gold standard for the study of sleep is polysomnography (PSG), a medical examination in which electroencephalogram (EEG), electrocardiogram (ECG), electromyogram (EMG), electrooculogram (EOG), nasal flow, and movements during the night are monitored. Data collected are analyzed by a physician who does the sleep scoring and finds any sleep disorders [6; 7; 8]. Sleep scoring is the identification of the subject's stage of sleep. During the night, light sleep (NREM1 and NREM2 phase), deep sleep (NREM3 phase), and REM sleep alternate. Light sleep is characterized by a slowing of cardiac and respiratory activity. Deep sleep consists of minimal Heart Rate (HR) and slow brain waves. REM sleep is distinguished by rapid eye movements (REM is, in fact, an acronym for Rapid Eye Movements) and by a higher HR [9; 10]. The advantage of polysomnography is the ability to analyze several physiological parameters, including EEG, in order to obtain the most accurate scoring and reporting of disturbances. However, the disadvantages of this procedure are cost and invasiveness. A less invasive technique used to monitor sleep is actigraphy, which involves scoring through the study of movements detected by means of a wearable device [11; 12]. Thanks to the improvements that wearable technology sensors have undergone, more and more devices have emerged that are capable of scoring using HR, Heart Rate Variability (HRV), and 3-axis acceleration [13; 14]. Sleep is strongly related to the Autonomic Nervous System (ANS), which regulates many of the involuntary body functions, such as breathing, digestion, HR, and blood pressure.