Skip to main content

Heart rate spectrum analysis for sleep quality detection


To evaluate the quality of sleep, it is important to determine how much time was spent in each sleep stage during the night. The gold standard in this domain is an overnight polysomnography (PSG). But the recording of the necessary electrophysiological signals is extensive and complex and the environment of the sleep laboratory, which is unfamiliar to the patient, might lead to distorted results. In this paper, a sleep stage detection algorithm is proposed that uses only the heart rate signal, derived from electrocardiogram (ECG), as a discriminator. This would make it possible for sleep analysis to be performed at home, saving a lot of effort and money. From the heart rate, using the fast Fourier transformation (FFT), three parameters were calculated in order to distinguish between the different sleep stages. ECG data along with a hypnogram scored by professionals was used from Physionet database, making it easy to compare the results. With an agreement rate of 41.3%, this approach is a good foundation for future research.

1 Review

Sleep is an important part of our lives as we spend on average one third of it sleeping. Not only is it the part of the day when the body rests and regenerates, sleep is also relevant for our physical and mental health in many ways [1]. Both quantity and quality of sleep are important to stay healthy. In our fast-paced, 24-h modern society, the amount of sleep-related disorders are increasing, amongst others because many people are not achieving the required amount of sleep they need (e.g., due to night shift work). For the diagnosis of sleep disorders, the investigation of the sleep structure during the night is an important aspect. Up until today, the gold standard in sleep investigation is a sleep study or an overnight polysomnography (PSG). Multiple electrophysiological signals are recorded to determine the sleep stages. These signals are the electroencephalogram (EEG), electrocardiogram (ECG), electrooculography (EOG) or eye movement, pulse oximetry (SpO 2), and electromyography (EMG) as well as muscular activity. On the basis of these signals and of specific rules established by Rechtschaffen and Kales [2], a sleep structure curve, divided into 30-s windows (epochs), is provided. Figure 1 shows an example of such a diagram. The use of 30-s windows is based on the fact that, when the body signal curves were printed to paper, one page equated to 30 s.

Fig. 1
figure 1

Hypnogram of a healthy adult

But PSG is extensive: It is an 8–12-h investigation, which requires the patient to stay at a special laboratory. The patient has to stay for several nights as most of the time, during the first night, his normal sleep cannot be observed because the environment is too unfamiliar. Furthermore, he has to “suffer” extensive wiring which often disrupts or impedes sleep even more. Both the application of all the sensors beforehand as well as the evaluation of the acquired data is time consuming and has to be done by specialists in order to give correct results. It is obvious that there is a demand for a way of automatic (computer-assisted) sleep analysis that is cheaper, less obtrusive, and furthermore easy to be used by ordinary persons at home. The ECG signal on its own is easy to conduct, requiring only 2–3 electrodes which can be placed correctly even without being specially trained. Another advantage is that during the night, the ECG signal is relatively stable as movement artifacts are quite rare. Also, the patient benefits from this less intrusive method compared to PSG.

1.1 Motivation

The purpose of this experiment is to first review existing sleep staging methods that use the heart rate signal as a classifier. In order to test whether ECG alone can be used for accurate sleep stage classification compared to PSG, one algorithm was selected and implemented within a desktop application. Different parameters are computed from the heart rate signal to distinguish between the different sleep stages. The reason for choosing the algorithm described in the paper [3] by Canisius was that it was only using the heart rate as a discriminator, looked detailed and quite accurate (57.5% agreement). The question that came up was if it would be possible to reproduce the result by using a pre-scored recording of the ECG. For the algorithm development, the ECG data from the “Sleep Heart Health Study PSG Database” available on the Physionet database was used [4]. It comes with annotations from a prescored hypnogram by specialists using the entirety of all 11 channels of the record. Therefore, this record is applicable for an evaluation of the developed algorithm.

1.2 State of the art

The area of sleep tracking and sleep quality estimation became more and more interesting in the public interest over the last years. Not only research in the scientific area, also the industry are targeting the area and investigate new ideas to handle this area. Different approaches and products of the private consumer market are described in this section.

1.2.1 Publication overview

Nowadays, sleep literature is abundant in scientific papers presenting algorithms for sleep stages classification using a reduced number of parameters compared to the method used by PSG. The authors in [5] try to detect sleep and wakefulness using a combination of ECG, actigraphy, and respiratory signals. With an automated Bayesian classifier, they achieved an accuracy of 86.8%. Willemen et al. [6] used the same body signals to distinguish between wake, REM, light (NREM1/2), and deep (NREM3) sleep applying a support vector machine (SVM) classifier. The work presented in [7] investigates if their subjects wake up more comfortably when awoken during REM sleep instead of deep sleep. They used only the heart rate to distinguish between REM and non-REM sleep. Seventy-nine percent of the actual and estimated REM was quite similar and 80% of the test subjects felt better when woken up during REM sleep instead of NREM sleep. Murugappan [8] developed an algorithm to assess five human emotions (sadness, happiness, fear, disgust, neutral) from the heart rate variability (HRV). They achieved an average agreement of 74.82%. Vanoli et al. [9] analyze HRV of healthy subjects and such that had a myocardial infarction (MI) to see if a risk of subsequent diseases can be identified. Komatsu and Kurihara [10, 11] propose methods to estimate sleep stages only with heart rate and body movement. The body signals are measured by the non-invasive, pneumatic method using a special mattress with a sensor in it. Zhang et al. [12] built a portable real-time automatic sleep system (“RASS”) which uses only the heart rate as a sleep stage discriminator achieving about 84% agreement.

1.2.2 Commercial devices

There is an increasing amount of commercial products addressing the customer’s fitness which also track its sleep. Fitbit®; sells several wristbands/watches that track quality and quantity of your sleep The results can be viewed via smartphone or computer [13]. Jawbone UP and UP2 are fitness trackers that are also worn around the wrist. It addition to sleep tracking, it wakes you up at the proper moment of a sleep cycle, which is considered to be during the REM phase [7]. It also gives you suggestions to maximize your sleep. UP3 will be even able to track different sleep stages [14].

The product ‘Peak’ sold by BASIS (shown in Fig. 2) does, in addition to a complete sleep scoring, movement tracking during sleep to show your restlessness [15]. All these products are not open source and access to the gathered raw data and the algorithms is not granted. Therefore, it is difficult to review how accurate the results are. In the following section, the corresponding experiment will be explained in detail.

Fig. 2
figure 2

Basis peak fitness tracker

1.3 Proposed experiment

In 1953, Dement and Kleitman classified sleep into one REM (Rapid Eye Movement) phase and four NREM (Non-REM) phases (NREM 1-4) [16]. Rechtschaffen and Kales developed standardized criteria on sleep staging in 1968, using different electrophysiological signals [2]. In 2004, the American Association of Sleep Medicine (AASM) reviewed the sleep stage model, combining NREM3 and 4 into NREM3 [17]. One simplification that was made for this work is to combine NREM1 and NREM2 into one sleep stage (NREM1/2) and NREM3 and NREM4 into NREM3/4. Within the spectrum analysis of the RR intervals, usually three wave bands are analysed: the very low frequency (VLF), the low frequency (LF) and the high frequency (HF) band. The LF and HF bands are of special interest because their ratio is considered as an expression of the sympathetic and parasympathetic balance of the autonomous nervous system (ANS). The peak frequencies within the HF band (0.15-0.4 Hz) are considered to represent activity of the Nervus vagus, the main parasympathetic nerve, while the power of the LF band (0.04-0.15 Hz) [18] is presumed to be influenced by sympathetic activity [19]. Busek et al, investigating the HRV in sleep [19], showed that during REM sleep, the LF band power is significantly increased compared to NREM sleep. In contrast, the HF band power shows higher values in NREM sleep in comparison to REM sleep.

1.3.1 Description of the algorithm

As a first step, the heart rate signal is derived from the ECG signal:

  1. 1.

    R-peaks are detected at positions where the value of the ECG signal is above a threshold of 0.35 mV and greater or equal than its predecessor and greater than its successor. For this threshold, several values were tested and 0.35 was most appropriate.

  2. 2.

    The mean RR interval (mean value for one minute of two consecutive R peaks) is then calculated as shown in (1), whereas n is the number of R peaks of an ECG signal during minute m and r i is the timestamp of interval i in minute m. One value for every 0.25 seconds is stored.

    $$ \text{RR}_{m} = \frac{1}{n} \sum (r_{i} - r_{i-1}) $$

The second step is to obtain the frequency spectrum. A fast Fourier transformation (FFT) with a sampling frequency of 4 Hz and a sample size of 4096 samples (according to 17 min 4 s) is performed. Thereby the frequency spectrum of time t is calculated using the heart rate values from RR t to RR t+4096, as consequence for the last 17 min and 3.75 s (1023.75 s) of the recording no sleep stage determination can be done. An example of signal LF/HF ratio is illustrated in Fig. 3 with data obtained from Physionet.

Fig. 3
figure 3

Diagrams of the calculated parameters. From top to bottom: LF/HF ratio; relative power of the HF band; variability of the HF band. On the x axis: seconds since the start of the recording

Busek explains in [19] that the LF band power is increased during REM sleep and wakefulness whereas the HF band power is increased during deep sleep. This happens due to different grades of activity of the sympathetic and parasympathetic nervous system during the different sleep stages. The breathing rate is normally quite regular during NREM sleep. Therefore, high HF peak power values are observed and the HF band power is concentrated in a narrow frequency range. In REM sleep, a high variability in the respiratory rate can be monitored. In consequence, the spectral power induced by respiration is spread over a wider frequency range. Taking this into account, we expect a low HF peak power and a high variability in the HF band during REM sleep.

Due to this information, three different parameters were extracted from the band power signals (also see Fig. 3):

  • The LF/HF ratio of low to high frequency (i.e., the quotient of LF and HF band power) to differentiate deep sleep and REM or wakefulness.

  • The relative peak frequency power in the HF band (i.e., the quotient of the maximum frequency power in the HF band and the sum of all frequency powers within the HF band) as a substitute of REM sleep or wakefulness.

  • The variability within the HF band (i.e., the distance between the highest and the lowest value in the HF band) as a discriminator between REM sleep and wakefulness.

1.3.2 Sleep stage classification

For every parameter previously described, a set of threshold values was defined in order to be able to distinguish between sleep stages. These threshold values are distributed over the whole range of each parameter and every permutation of threshold values was tested to see which one would end up with the hypnogram that has the most accordance with the pre-scored one. The sleep stage classification includes the following steps:

  1. 1.

    At first, the whole record is scored as NREM1/2, since on average, more than 50% of the night is spent in this sleep stage.

  2. 2.

    Two thresholds t1 and t2 (t1 > t2) are applied to the LF/HF power ratio signal. If the parameter value is above t2, the corresponding segment of the hypnogram is marked as wake or REM. If it is below t1, it is assigned to NREM3/4.

  3. 3.

    In the next step, the remaining NREM1/2 episodes are reclassified as REM if the corresponding value of the relative power in the HF band is above the threshold.

  4. 4.

    The last step is to distinguish between REM sleep and wakefulness. Therefore, the variability in the HF band is analysed: If the value is above the threshold, the corresponding segment of the hypnogram is assigned to REM, otherwise wake.

1.4 Results

The algorithm processes the recorded ECG data applying the method which was described in the previous chapter and which is received from Physionet as a simple text file. The results of the sleep stage classification are compared to the data of Physionet database.

To get the results, 30-s windows (so called epochs) were chosen as the time window for comparison as the prescored annotations are also arranged in 30-s epochs in compliance with the rules of Rechtschaffen and Kales [2]. Each epoch is assigned to the sleep stage that occurs most frequently during the time window of that epoch. While comparing the calculated hypnogram with the prescored hypnogram from Physionet database, an agreement of 41.3% could be reached.

To achieve the result of 41.3%, the misdetection of each epoch has to be compared to the prescored annotations of Physionet. Assuming that the scores in the Physionet database are precise, we see that 41.3% of the detection agreed with the scores of Physionet and a misdetection of 58.7%.

The mean agreement of 41.3% is lower than the targeted 50% agreement but still a fine result only using ECG data for detection. The complete sleep studies in the Physionet databases use 11 sensors. These can be used for development of more portable and mobile systems that use less sensors and reduce less the comfort by the patient. For medical use, the system still has to be improved.

2 Conclusions

The sleep quality has a major impact on the health state of every human being. Sleep is maintaining physical and mental recovery affected during the day. Therefore, new methods are necessary to estimate the sleep quality. An algorithm for the differentiation of sleep stages was developed. Only parameters derived from the ECG signal were used. The approach shows a promising result which should be pursued in future researches. A possible improvement to the algorithm can be the use of the VLF band (0.003–0.04 Hz) to help differentiating between the sleep stages, as, e.g., proposed by Baumert et al. [18]. Furthermore, a greater number of data sets can be used to improve threshold values. It is also possible to use an improved detection of RR intervals and an improved calculation of the heart rate, i.e. as proposed by Kesper et al. [3] For future applications, it is intended to receive the data directly from a sensor.


  1. Lung National Heart, Blood Institute, Your guide to healthy sleep. U.S. Department of Health and Human Services, Booklet 11-5271 (2011).

  2. A Kales, A Rechtschaffen, LA University of California, N. N. I. N. (U.S.), English A manual of standardized terminology, techniques and scoring system for sleep stages of human subjects. (A Rechtschaffen, A Kales, eds.) (U. S. National Institute of Neurological Diseases and Blindness, Neurological Information Network, Bethesda, 1968).

    Google Scholar 

  3. C Canisius, T Ploch, T Penzel, A Jerrentrup, D Krefting, K Kesper, in Proceedings of Biosignal 2010. Classifying sleep stages using the heart rate spectrum-comparison and feasibility in healthy subjects and sleep apnea patients, (2010).

  4. AL Goldberger, LAN Amaral, L Glass, JM Hausdorff, PC Ivanov, RG Mark, JE Mietus, GB Moody, C-K Peng, HE Stanley. PhysioBank, PhysioToolkit, and PhysioNet: components of a new research resource for complex physiologic signals. Circulation. 101(23), e215–e220 (2000)., doi:10.1161/01.CIR.101.23.e215..

    Google Scholar 

  5. S Devot, R Dratwa, E Naujokat, in Engineering in Medicine and Biology Society (EMBC), 2010 Annual International Conference of the IEEE. Sleep/wake detection based on cardiorespiratory signals and actigraphy, (2010), pp. 5089–5092.

  6. T Willemen, D Van Deun, V Verhaert, M Vandekerckhove, V Exadaktylos, J Verbraecken, S Van Huffel, B Haex, J Vander Sloten, An evaluation of cardiorespiratory and movement features with respect to sleep-stage classification.BioMed. Health Inf. IEEE J. 18(2), 661–669 (2014).

    Google Scholar 

  7. Y Masao, N Atsuo, T Sei-ichi, K Yunokuchi, in Proceedings of The First International Workshop on Kansei. Detection of rem sleep by heart rate, (2006).

  8. M Murugappan, S Murugappan, BS Zheng, Frequency band analysis of electrocardiogram (ECG) signals for human emotional state classification using discrete wavelet transform (dwt). J. Phys. Therapy Sci. 25(7), 753–759 (2013).

    Article  Google Scholar 

  9. E Vanoli, PB Adamson, Ba-Lin, GD Pinna, R Lazzara, WC Orr, Heart rate variability during specific sleep stages: a comparison of healthy subjects with patients after myocardial infarction. Circulation. 91(7), 1918–1922 (1995).

    Article  Google Scholar 

  10. E Komatsu, Y Kurihara, K Watanabe, in SICE-ICASE, 2006. International Joint Conference. Sleep stage estimation by non-invasive bio-measurement, (2006), pp. 1494–1499.

  11. Y Kurihara, K Watanabe, ‘Sleep-stage decision algorithm by using heartbeat and body-movement signals. Syst. Man Cybernet. Part A Syst. Hum. IEEE Trans. 42(6), 1450–1459 (2012).

    Article  Google Scholar 

  12. J Zhang, D Chen, J Zhao, M He, Y Wang, Q Zhang, in Real-Time Systems Symposium (RTSS), 2012 IEEE 33rd. Rass: A portable real-time automatic sleep scoring system, (2012), pp. 105–114.

  13. Fitbit Inc, Fitbit Surge, Fitness Super Watch. Accessed 26 June 2015.

  14. Jawbone, Buy U3 by Jawbone, The most advanced tracker known to man. Accessed 26 June 2015.

  15. Basis an Intel company, Front page - Basis. Accessed 26 June 2015.

  16. W Dement, N Kleitman, Cyclic variations in eeg during sleep and their relation to eye movements, body motility, and dreaming. Electroencephalogr. Clin. Neurophysiol. 9(4), 673–690 (1957).

    Article  Google Scholar 

  17. C Iber, S Ancoli-Israel, ALJ Chesson, SF Quan, The AASM Manual for the Scoring of Sleep and Associated Events; Rules terminology and Technical Specification (IL, Westchester, 2007).

    Google Scholar 

  18. M Baumert, J Smith, P Catcheside, RD McEvoy, D Abbott, P Sanders, E Nalivaiko, Variability of qt interval duration in obstructive sleep apnea: An indicator of disease severity. SLEEP. 31(7), 959–966 (2008).

    Google Scholar 

  19. P Busek, J Vankova, J Opavsky, J Salinger, S Nevsimalova, Spectral analysis of heart rate variability in sleep. Physiol. Res. 54:, 369–376 (2005).

    Google Scholar 

Download references

Authors’ contributions

All authors read and approved the final manuscript.

Competing interests

The authors declare that they have no competing interests.

Author information

Authors and Affiliations


Corresponding author

Correspondence to Wilhelm Daniel Scherz.

Rights and permissions

Open Access This article is distributed under the terms of the Creative Commons Attribution 4.0 International License (, which permits unrestricted use, distribution, and reproduction in any medium, provided you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license, and indicate if changes were made.

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Scherz, W.D., Fritz, D., Velicu, O.R. et al. Heart rate spectrum analysis for sleep quality detection. J Embedded Systems 2017, 26 (2017).

Download citation

  • Received:

  • Accepted:

  • Published:

  • DOI: