The aim of this work is to develop a low-cost comfortable body sensor for monitoring heart rate, activity, body temperature and blood oxygenation level, that could be used to identify sleep stages and diagnose sleep disorders like insomnia, apnea, periodic limb movement, Restless Leg Syndrome or sleep walking. 

Poor sleep quality due to sleep deprivation or fragmentation

Everyone experienced or will experience sleep problems at some point in their lives.

Poor sleep quality due to sleep deprivation or fragmentation may be the main cause for symptoms like reduced vigilance, memory deficits, fatigue and difficulty in maintaining equilibrium. Untreated sleep disorders have been linked to hypertension, heart disease, stroke, depression, diabetes and other chronic diseases.

According to the American Academy of Sleep Medicine, there are over 80 known sleep disorders so far, which can take many forms and can involve too little sleep, too much sleep or inadequate quality of sleep.

Currently, the gold standard in terms of sleep disorder diagnosis is overnight polysomnography (PSG). The main disadvantages with PSG are the high monitoring costs per patient, the scarcity of beds available and the uncertainty of whether the results are representative of a normal nights’ sleep. These are the main reasons why low-cost home diagnostic systems are likely to be advantageous. They aim is to reach a larger population by reducing the number of parameters recorded.

There are many monitoring modalities that have been explored for home sleep diagnostic systems which are based on analysis of EEG, ECG, body movement, oxyhemoglobin saturation level, blood pressure, respiration, temperature, audio and video recordings. Most of the times, the proposed systems combine two or more of this monitoring modalities to achieve better accuracy.

Monitoring devices designed as patches(e.g. Metria, ePatch) and textile technology(mainly by use of conductive fibers) were proposed as innovative tools for the development of comfortable devices for monitoring a variety of vital signs like ECG, bioimpedance, skin resistance, respiratory frequency.

Telemedicine is also a fresh field which raises a lot of interest in the scientific community because it promises to overcome the disadvantages of home monitoring systems( data loss mainly) and keep the advantages of in-lab monitoring(complete accurate sleep study). Telemedicine uses grid technology for analysis and recording.


The Master Thesis is tutored by Prof. Dr. Ralf Seepold (HTWG Konstanz - Germany, UC-Lab). The thesis is executed during an ERASMUS+ stay at HTWG Konstanz, Ubiquitous Computing Laboratory (UC-Lab).


Continue reading
Rate this blog entry:
4209 Hits 0 Comments

Sleep, vital signals during sleep and sleep disorders

Many definitions for sleep, like the one given by The Columbia electronic encyclopaedia, characterize sleep as being a “resting state in which an individual becomes relatively quiescent and unaware of the environment. During sleep, which is in part a period of rest and relaxation, most physiological functions such as body temperature, blood pressure, and rate of breathing and heartbeat decrease. However, sleep is also a time of repair and growth, and some tissues, e.g., epithelium, proliferate more rapidly during sleep."

Although the phenomenon is not completely understood by scientists, it is clear from the EEG measurements that it can be divided into NREM and REM stages.

In REM sleep, the main feature is muscle paralysis which blocks the neuronal connection between the brain and most muscles. Muscle paralysis prevents the awake-like brain activity from causing movement of the body during sleep. It is also during this stage that the brain is more active and dreaming is more frequent and vivid, although dreaming does occur also during NREM sleep [1].

In 1968, Rechtschaffen and Kales based on EEG changes, divided NREM sleep into four further stages: N1, N2, N3, N4. In 2007 was published, the AASM Manual for the Scoring of Sleep and Associated Events resulting in some changes, with the most significant being the combining of stages N3 and N4 into one stage N3.The stage N1 represents the drowsy state between wake-fullness and sleep, and the depth of sleep is progressively increased in stages N2 and N3 [2].

To better visualize these general patterns, researchers use a type of graph called a hypnogram. A hypnogram is nothing more than a minute-by-minute graphic record of a night’s sleep, as captured by an EEG. The hypnogram thus shows not only the sequence in which the various stages of sleep occur, but also the times at which each stage starts and ends.

By analyzing a typical hypnogram such as the one shown in Figure 1.1, we see that a few minutes after falling asleep, we slip deeper and deeper into non-REM sleep: first into light non-REM sleep (stages 1 and 2), and then into deep non-REM sleep (stages 3 and 4).

sleep hypnogram example

            Figure 1.1: An exemplary hypnogram of a healthy young adult [3]

Another striking feature of the hypnogram is the recurrent cycles in which the various stages of sleep follow one another, somewhat like a series of waves: 1-2-3-4-3-2-1-REM-1-2-3-4-3-2-1-REM, etc. Thus each descent into deep non-REM sleep is followed by a climb back up directly into a period of REM (or paradoxical) sleep. [3]

train sleep stages

            Figure 1.2: The “train” of a night of sleep comprises many “cars” that are linked to one another in a specific order to form 4 or 5 major cycles [3]

NREM and REM sleep are known to alternate in cycles, each lasting approximately 90–110 minutes (min) in adults, with approximately 4–6 cycles during the course of a normal 6–8 hour (h) sleep period. However, these timings change depending on the length of time asleep, age, medication, physical health and mental health. Furthermore, brief micro-arousals can occur, lasting (by definition) from 1.5–3 seconds (s) and short awakenings (defined to be longer 15 s). [4]

The Table 1.1 shows a summary of how the effects of the different stages can be seen in heart rate, respiration, temperature and movement activity. The middle column shows how sleep stages affect movement, heart rate, respiration and the electrophysiological features of sleep stages, listed in column one [5].


Sleep Stages Effects Features
Wakefulness Much movement
Stable respiration
EEG: Alpha activity(8-13 Hz) for >= 50% of the epoch
NREM N1 Little movement
Decreased HRV
Instability in respiration amplitude
EEG: Alpha activity for < 50% of the epoch
Low-voltage mixed-frequency activityVertex sharp waves
EOG: Slow eye movements
NREM N2 Little movement.Decreased HRVStable respirationBody temperature decreases EEG: Slow-wave activity (0.5-2 Hz) for <20% of the epochSleep spindles or K-complexes
NREM N3 Little movementDecreased HRVVery stable respiration EEG: Slow-wave activity for >= 20% of the epoch
REM Movements during phase REMIncreased HRV and blood pressureUnstable respirationFluctuations in body temperature EEG: Low-voltage mixed-frequency activitySaw-tooth waves (2-6 Hz)EMG: Low activityEOG: Rapid eye movements

Table 1.1: The different effect of each sleep stage on vital signals

Sleep disorders are changes in sleeping patterns or habits. Signs and symptoms of sleep disorders include excessive daytime sleepiness, irregular breathing or increased movement during sleep, difficulty sleeping, and abnormal sleep behaviours. A sleep disorder can affect one’s overall health, safety and quality of life.

According to AASM [6], there are over 80 known sleep disorders and they can be classified into seven categories, each with the characteristics described below. Additionally there is the 8th group called "isolated symptoms, apparent normal variants and unresolved issues".


Difficulty initiating or maintaining sleep, early awakening or poor sleep quality characterize this category. It frequently coexists with medical, psychiatric, sleep, or neurological disorders and is characterised by a reduction of total sleep time and latency for REM sleep, an increase in spontaneous micro-arousals, a reduction of slow-wave sleep and an increase in rapid eye movements [7].

Sleep-related breathing disorders           

Symptoms for this category include: abnormal respiration during sleep, chronic snoring, upper airway resistance syndrome, apneas and obesity hyperventilation syndrome.       When an apnea occurs, sleep usually is disrupted due to inadequate breathing and poor oxygen levels in the blood. Sometimes the person wakes up completely, but sometimes the person comes out of a deep level of sleep and into a more shallow level of sleep. A hypopnea is a decrease in breathing that is not as severe as an apnea. The apnea-hypopnea index (AHI) is an index of severity that combines apneas and hypopneas [8].

Central sleep apnea (CSA) occurs when the brain does not send the signal to the muscles to take a breath and there is no muscular effort to take a breath.

Obstructive sleep apnea (OSA) occurs when the brain sends the signal to the muscles and the muscles make an effort to take a breath, but they are unsuccessful because the airway becomes obstructed and prevents an adequate flow of air.

Mixed sleep apnea, occurs when there is both central sleep apnea and obstructive sleep apnea.

Hypersomnias of central origin           

This is a separate category for hypersomnias of central origins which are not due to circadian rhythm sleep disorders, sleep related breathing disorders or other cause of disturbed nocturnal sleep. It includes only those disorders in which the primary complaint is daytime sleepiness and abnormal REM sleep. Narcolepsy is the most common disorder in this group. [6]               

Circadian rhythm sleep disorder

These are disruptions of the circadian time-keeping system that regulates the (approximately) 24h cycle of biological processes. The circadian pacemaker in humans is located mainly in the suprachiasmatic nucleus, which is a group of cells located in the hypothalamus. Circadian rhythms affect sleep and wake cycles, cortisol release, body temperature, melatonin levels, and other physiologic variables and can be (non-pathologically) disturbed by shift work, time zone changes (jet-lag), medications and changes in routine.


Parasomnias are disorders that intrude into the sleep process and are manifestations of central nervous system activation producing nonvolitional motor, emotional, or autonomic activity. Most parasomnias are associated with a specific type of sleep (rapid eye movement [REM] or non-rapid eye movement [NREM] sleep). [6]

Parasomnias usually associated with REM sleep include nightmares and sleep paralysis and the ones associated with NREM sleep are night terrors, enuresis nocturnal, bruxism, sleepwalking and confusional arousals. [6]

Sleep-related movement disorders 

Sleep related movement disorders are characterized by simple, stereotypic movements that disturb sleep. Movements that occur during sleep but do not adversely affect sleep or daytime function are not considered a sleep related movement disorder. Classic sleep related movement disorders include restless legs syndrome, periodic limb movement disorder, sleep related leg cramps, sleep related bruxism(teeth grinding), and sleep related rhythmic movement disorder. The most common is the Restless Leg Syndrome which is a neurological disorder and causes an irresistible urge to move the legs to relieve an uncomfortable sensation deep within the legs during non-REM sleep. [9]

Other sleep disorders

In this group alcohol abuse-related or psychiatric disorders are listed.



[1] T. Hori, Y. Sugita, E. Koga, S. Shirakawa, K. Inoue, S. Uchida, H. Kuwahara, M. Kousaka, T. Kobayashi, Y. Tsuji, M. Terashima, K. Fukuda and N. Fukuda, "Proposed supplements and amendments to ’A Manual of Standardized Terminology, Techniques and Scoring System for Sleep Stages of Human Subjects’, the Rechtschaffen & Kales (1968) standard", 2001.
[2] C. Iber, S. Ancoli-Israel, A. Chesson and S. F. Quan, "The AASM manual for the scoring of sleep and associated events: rules, terminology and technical specifications", 2007.
[3] "The brain from top to bottom," [Online]. Available: Retrieved on 2014.
[4] S. Martin, H. Engleman, R. Kingshott and N. Douglas, "Microarousals in patients with sleep apnoea/hypopnoea syndrome", 1997.
[5] P. R. G. Ribeiro, "Sensor based sleep patterns and nocturnal activity analysis," 2014.
[6] American Academy of Sleep Medicine, "The international classification of sleep disorders," 2005.
[7] S. Maria, G. Pereira and A. Smith, "Diagnostics methods for sleep disorders," 2005.
[8] "MedicineNet," [Online]. Available: on 2014.
[9] L. a. Panossian and A. Y. Avidan, "Review of sleep disorders", 2009.




Continue reading
Rate this blog entry:
9531 Hits 0 Comments

ECG monitoring and sleep disorders

The gold standard for sleep monitoring and sleep disorders evaluation is PSG (Polysomnography). In this technique, the patient sleeps in a laboratory while his physiologic parameters are measured.

There is a rich diversity of PSG systems available, classified by AASM(American Academy  of Sleep Medicine) in two levels: level 1 for the standard PSG and level 2 for portable PSG.

For a sleep study both levels must accommodate the minimum of seven channels:

  • EEG(Electroencephalogram): to determine arousals from brain activity;
  • EOG(Electroculogram): to detect REM sleep;
  • EMG(Electromyography) submentonian: to look for limb movements that cause arousals;
  • ECG(Electrocardiogram): for heart rate calculation
  • ChestWall monitors: to document respiratory movements;
  • Thermistor and/or nasal cannula: to nasal and oral airflow measurements;
  • Oximetry: to measure oxyhemoglobin saturation(SpO2).

In terms of PSG home sleep testing, there are some solutions in the market. Somté PSG [1]implements a fully PSG home sleep testing. It has twenty five available channels and a software for data analysis.

Although offers a complete sleep study, such modality is not comfortable and is invasive for person in study as well as expensive, time-consuming and complex.

 Recent studies have shown that heart rate alone has the potential to be a reliable mean for identifying sleep stages and diagnosing some sleep disorders. For example, it is a known fact that episodes of OSA are accompanied by a characteristic HR pattern consisting of bradycardia during apnea followed by abrupt tachycardia on its cessation [2], which can be used to detect OSA. 

The electrocardiogram or ECG is a major diagnostic tool for the assessment of the health of the heart. It is a measurement taken at the surface of the skin which reflects the electrical phenomena in the heart when the SA (sinoatrial) node triggers the electrical sequence that controls heart action.


Figure 1- Schematic representation of normal ECG


Normal heart beat consist of a P wave, a QRS complex and a T wave, Figure 1.

The P wave is the electrical signature of the current that causes atrial depolarization.

The QRS complex corresponds to the current that causes contraction of the left and right ventricles. This contraction is much more forceful than that of the atria and involves more muscle mass, thus the resulted ECG deflection is greater.

The T wave represents the re-polarization of the ventricles.

ECG signal is governed by autonomous nervous system. This is the reason why the ECG signal is well correlated with breathing [3] and can be source of the correlation with the different sleep stages [4] [5].

There are many methods for the processing of ECG signal. The four most documented methods are  Heart Rate Variability (HRV) , Detrended Fluctuation Analysis (DFA) , Progressive Detrended Fluctuation Analysis (PDFA), Heart Rate Morphology ,Multi-scale Entropy Analysis, Information-Based Similarity.

There are some few difficulties in processing of the ECG signal which are imposed by its biological origin : Heart rate has many individual components and is driven by competitive forces (sympathetic and parasympathetic) and more over there are more of regulation mechanisms. This causes the creation of complex fluctuations. These fluctuations are not simply the result of responses on external factors, but they are persistent during physical load, rest and sleep. This non-stationarity is common for stochastic processes and therefore imposes that similar methods of processing may be used.

Recent studies have shown that HRV has the best results in the sleep disorders field.

HR(heart rate) can be derived directly from the ECG, or indirectly from other physiological waveforms, such as the PPG signal [6]. Analysis both in time domain and frequency domain are possible.

In a study from 2006 [7], HR variation was used to estimate REM and N-REM sleep durations, given that HR variation is well correlated with the sleep cycle [8] . A concordance of 88.8% was obtained for the estimated REM Sleep compared to actual REM sleep detected with EEG, EOG and EMG.

HRV(heart rate variability) is a black box with HR as the output. A study from 2011 [9], reviewed the ways in which HRV can be applied to understand autonomic changes during different sleep stages.It has also been applied to understand the effect of sleep-disordered breathing, periodic limb movements and insomnia both during sleep and during the daytime. HRV has been successfully used to screen people for possible referral to a Sleep Lab. It has also been used to monitor the effects of continuous positive airway pressure (CPAP).

A novel HRV measure, cardiopulmonary coupling (CPC) has been proposed for sleep quality. Evidence also suggests that HRV collected during a PSG can be used in risk stratification models, at least for older adults. Caveats for accurate interpretation of HRV are also presented. Conclusions of the study [9] clearly demonstrate the relevance of HRV analysis to clinical sleep medicine. At the same time, it states that clinical applications of HRV to sleep are still in their infancy.

Another study from 2008 [10] described an analysis algorithm of the ECG signal that is capable of diagnosing SBD by detecting episodes using CVHR(cyclic variations in heart rate). Applying the algorithm to 35 polysomnographic recordings provided by MIT Apnea Database the authors achieved a diagnostic accuracy of 77%.Using the ECG signal for detecting episodes of sleep disordered breathing seems reasonable as this events are known to be associated with autonomic reactions such as increases in blood pressure or frequent CVHR [11], but further improvements on the algorithm are needed.

The analysis of dynamic changes in ECG morphology using sophisticated algorithms enables the derivation of respiration from the ECG by tracking the amplitudes of the prominent R-wave. The derived respiratory curve is called ECG-derived respiration and correlates reasonably well with respiratory effort based on inductance plethysmography.

The combination of EDR(ECG-derived respiration) and sleep apnea related HRV has the potential to be a good and reliable detection tool for sleep apnea, but high-quality,empirical evidence on this subject is so far lacking [12].



"COMPUMEDICS," 2014. [Online]. Available:


C. Guilleminault, R. Winkle, S. Connolly, K. Melvin and A. Tilkian, "Cyclical variation of the heart rate in sleep apnoea syndrome: mechanisms, and usefulness of 24 h electrocardiography as a screening technique," 1984.


S. R. Heinrich, F. Becker, S. Havlin, A. Bunde, J. W. Kantelhardt and T. Penzel, "Breathing during REM and NREM sleep: correlated versus uncorrelated behaviour," 2003.


J. W. Kantelhard, T. Penzel, J. Hermann, J.-H. Peter, A. Bunde, S. Havlin and K. Voigt, "Correlated and uncorrelated regions in heartrate fluctuations during sleep," 2000.


H. Becker, J. Peter, A. Bunde, T. Penzel and J. Kantelhard, "Detrended fluctuation analysis and spectral analysis of heart rate variability for sleep stage and sleep apnea identification," 2003.


J. Allen, "Photoplethysmography and its application in clinical physiological measurement," 2007.


M. Yaso, S. T. A. Nuruki and K. Yunokuchi, "Detection of REM sleep by heart rate," 2006.


M. Koki, M. Yaso, S. Tsujimura and K. Yunokuch, "Detection of the period of the REM sleep using HR in real time," 2005.


P. K. Stein and Y. Pu, "Heart rate variability, sleep and sleep disorders," 2011.


S. Canisius, T. Ploch, V. Gross, A. Jerrentrup, T. Penzel and K. Kesper, "Detection of Sleep Disordered Breathing by automated ECG analysis," 2008.


J. H. Peter, U. Koehler, L. Grote and T. Podszus, "Manifestations and consequences of obstructive sleep apnoea," 1995.


N. Collop, S. Tracy and V. Kapur, "Obstructive sleep apnea devices for out-of-center (OOC) testing: technology evaluation," 2008.

Continue reading
Rate this blog entry:
8057 Hits 0 Comments

HowTo: change service UUIDs using BlendMicro

For the Body Sensor project, I needed to change the default service UUID that a BlendMicro board was advertising. If you are here, it probably means you also want to get this done. I hope you will find this tutorial useful.

The Bluetooth Low Energy(BLE) connection will be established between an Intel Edison board  (central device) and a BlendMicro peripheral. 

  1. First things first! Install the required software:

    On the BlendMicro side you will need :

               Install the Arduino IDE.

               Extract your downloads and copy the Hardware folder from the Add-On package in                    your Arduino folder.

               Copy the BLE folder from the nRF8001 SDK in the Libraries folder.

               Do the same for the nRF8001 Library.

               In the end your folders should look like this:



           For programming the Intel Edison I am using:

            Make sure you have Bluetooth working on your Edison. You may find the new Bluetooth Guide from Intel useful.

     2. Edison code

         Now that we have all the tools, we can proceed with writing the code for the Edison.Our aim is to discover the BlendMicro and to printout the advertising service UUID.  


var noble = require('noble');
var devices = new Array();

console.log('Try to find BLE devices...');

noble.on('discover', function (peripheral) {
    peripheral.connect(function (error) {
        if (error) {
        } else {


setTimeout(function () {
    console.log("Stop discovery \n");
}, 10000);

var reportDevices = function (listOfDevices) {
    for (var idx in listOfDevices) {
        console.log(' ' + idx + ' uuid: ' + listOfDevices[idx].advertisement.localName);
        console.log("\tLE: " + listOfDevices[idx]);
        console.log('\tConnected to peripheral: ' + listOfDevices[idx].uuid);

         Next, we load the "SimpleChat" example from the RBL_nRF8001 library on the BlendMicro.


         When running the code on the Edison, we can see that by default the BlendMicro advertises service 180b.


     3. Using nRFgo Studio

  • Load your RBL_nRF8001.xml file (under C:\Users\uc-office\Documents\Arduino\libraries\RBL_nRF8001) into the nRFgo. 


         Check what service is being advertised. You will find this information in the GAP Settings tab, under Service Solicitation and Local Services.


    • Change UUID base from 180b to 180a,  click OK and go to File -> Save


                                     Now your .xml file is updated.

    • Generate the files used by RBL_nRF8001 library. Select the same destination folder where RBL_nRF8001.xml file is found.


         The following files will be generated:




    • Rename services.h to RBL_services.h and save the old one under a different name


    • Upload the SimpleChat example again and when finished, RESET the BlendMicro board (!!! Don’t forget this step)

          Now the service UUID should be updated to 180a:


           Thanks for reading!

Continue reading
Rate this blog entry:
20500 Hits 0 Comments