Design and development of a method for detecting sleep roll-over counts using accelerometer ADXL335

Received Apr 23, 2019 Revised Aug 29, 2019 Accepted Aug 30, 2019 Sleep plays an important role as it helps human body to rejuvenate, boosts mental function and manage stress. Sleep is restorative function which enhances muscle growth, repairs tissues, maintains health and make physical appearance look or feel better. The lack of sleep in human body can increase the risk of diseases which are asthma, diabetes, depression. For healthy physiological function, sleep is essential and has strong relation to mental condition. Easy way of sleep management is considered for maintaining good mental health. Numerous scientists, doctors and researchers have proposed various ways to monitor sleep, some of those best tests are polysomnography test and actigraphy test. However, taking sleep test covering the whole body with wires and electrodes which is polysomnography test is uncomfortable for patients, and sensors used for different approaches like this are costly and often require overnight treatment and expert monitoring in clinics. Therefore, easy way of detecting roll-over movements which is convenient for patients to wear is proposed. Accelerometer ADXL335 sensor is taped on socks during sleep which is comfortable for patients to wear and do not cause any inconvenience during sleep. Algorithm is proposed to read the dataset and count the roll-over during the sleep based on threshold. Resulting the number of roll-over detected during a sleep period.


INTRODUCTION
Sleep assists us to refresh our-self from mental and physical exhaustion. Mental and restorative function are the two important aspects which helps a human body to recover, learn and think in daily life. Reduction in mental concentration, improper restorative function, bad immunity, high caffeine intake, stress, migraine, irregular sleep schedules are some examples which are affected because of lack of sleep or not getting quality sleep time. Thus, quality sleep time is essential for mental and physical activity for all aspects of daily routine.
The Times of India [1] has found 93% Indians are sleep-deprived. Sleep deprivation causes depression, sleep apnea, obstructive, hormone imbalance and chronic illness. According to National sleep Foundation (NSF) 2015 recommendation for appropriate sleep duration for Adults (18-64 years) is 7 to 9 hours. In Lucknow city in India, the number of sleep disorder which has affected patients is nearly 40 lakhs, says doctors at King George's Medical University. Further, the study says that 72% of Indian's population are waking up one-three times per night. Therefore, physical and mental condition are essentially related to sleep. Mental and physical health management is considered important as it depends on how well the sleep was. Preventing mental disorders is done by early detection of sleep disorders in order to assist well. During the sleep mode of an individual, the simplest method to check sleep duration is comfortably done by sleep home management. There is also accurate test which can be undertaken by overnight polysomnography test, which has various measurements such as respiration, body movement, physiological measurements, electromyogram (Muscle), electroencephalogram (Brain activity) and electrocardiogram (Pulse). Although, this test is needs complex and large system, and experts to monitor the whole test like well experienced Doctors. It's uncomfortable to take a test for any individual as Polysomnography (PSG) test has electrodes, sensors and wires all over body. As sleep is a daily routine which makes a person healthy. Any mental disorder affects for few days or weeks. Isolated polysomnography test will not record any signs of inconvenience in sleep, due to mental deprivation or restlessness causing during sleep. Further, an accelerometer sensor is used to measure movements, which measures and shows the acceleration of limbs. This is used continuously to measure the sleep activity over the whole time period of sleep. Here, accelerometer cannot measure sleep depth, sleep stage or sleep quality as it measures the acceleration and duration of a person asleep. Thus, the proposed method is to measure sleep roll over counts using acceleration data using accelerometer. The proposed method is a comfortable way to measure sleep roll over counts while the patient is asleep, this method is comfortable for patients to wear and it does not disturb or cause inconvenience to the patients during sleep.

THEORETICAL BACKGROUND 2.1. Stages of sleep
There are usually five stages of sleep, where every sleeper passes through: Stage 1, Stage 2, Stage 3, Stage 4, and REM (rapid eye movement). These are the stages having progress cyclically, from Stage 1 to Stage 2 and the Stage 2 to Stage 3 till REM and then over again it begins from stage 1. Average complete cycle is of 90 to 110 minutes, each stage lasting around 5-10 minutes ( Figure 1). a) Stage 1: This stage is light sleep where a person drift in and out of sleep and can be awakened easily.
The eyes move slowly and muscle activity reduces in this stage. b) Stage 2: In this stage eye movements stops and brain waves becomes gentle with only occasional burst of rapid brain waves. c) Stage 3: When a person enters this stage, the brain waves are extermely slow which are called delta waves scattered with smaller and faster waves. This stage is deep sleep. Parasomnias are the behaviors which occurs in this stage that a person may experience night terrors, talking during sleep, sleepwalking and bedwetting. Mostly, tend to occur during the transitions between non-REM and REM sleep. d) Stage 4: In this stage deep sleep is continued as the brain produces delta waves almost exclusively. People aroused from this stage feel perplexed for few minutes. e) REM (rapid eye movement): In this stage brain waves mimic activity during the waking state.
Eyes remains closed but moves rapidly side to side, relating to intense dreams and activity occuring during this stage.

Sleep cycle
Sleep cycle depends on the period of time an individual takes to progress through all stages of sleep. It's not possible for one to go directly from deep sleep to REM. A sleep cycle progress through stages of non-REM sleep from light to deep sleep, then reverse order from deep to light sleep, ends with time in REM sleep before it starts over in light sleep.

LITERATURE REVIEW
The researchers Nico Surantha et al., [2] did a review about sleep quality and monitoring, sleep disorder like Insomnia, narcolepsy, restless legs syndrome, sleep apnea is described in order to understand how sleep disorder can affect to human's mental ability, physical ability, health and well-being. Physiological parameters are monitored during sleep in order to have get insight about patient's sleep quality. Polysomnography is described briefly where Brain activity is measure with electroencephalogram (EEG), eye movement with electrooculogram (EOG), muscle activity with electromyogram (EMG), heart activity and blood oxygen level are the detail parameter that is recorded by polysomnography. The authors of this research method talks about the IoT system design, where researchers have designed the system which are having four main components used to monitor sleep, and the workflow of the system which are the four components in architecture. Those four components are data collection/acquisition, data concentrator, cloud storing and monitoring application.
The Author Priyanka Madhushri et al., [3] has proposed distributed sleep monitoring system using wireless inertial sensors SP-10C by Sensoplex in-order to represent the architecture for distributed monitoring considering ease of deployment and configuration. The synchronization technique with pulse generation is proven to be accurate and very precise. Periodic Leg Movements can be monitored by two inertial sensors on the toe and ankle which is convenient to the user. They have got 96.51% of Periodic Leg Movement detection accuracy, which was tested five different experiments of simulated PLM. Author mentions that periodic leg movements can be monitored using two inertial sensors on toe and ankle which is comfortable and convenient to the users.
Author David Claman et al., [4], polysomnographic study examining relationship of periodic leg movements (PLMS) to sleep architecture and waking of sleep in women, they have found that leg movements are common is elderly women. Home PSG was performed including identical measurements of leg movements. Total number of leg movements per hour of sleep and the number of leg movements causing arousals per hour of sleep were computed.
The author Yu-Wei Liu et al., [5] proposed core sensor Bed-Centered Telehealth System (BCTS) which uses a bed as a center to collect health data for telehealth system implemented in homes and nursing homes. The BCTS is a soft motion sensing mattress, it facilitates bed related time monitoring, collects signals of physical activities in bed which classifies on/off bed, movement counts, sleep posture, and respiration rate. About the rapid growth of population and decline in birth rate, there is huge demand in telehealth services. For older adults leaving at home or nursing homes the bed is an important part of their daily lives. The author has proposed a system which makes comfortable and convenient for patients to take up the test while compared to polysomnography test.
Author Yunyoung Nam et al., [6] proposes a sleep quality monitoring system. A sleep quality monitoring is a system which determines the state of sleep, sleeping pose, REM sleep, and non-REM sleep stage. In this paper they have proposed a system using three-axial accelerometer and a pressure sensor which measures acceleration and pressure sensor which measures movement of the body, without any need for a large system, such as the Polysomnography. Further, in addition to such sleep stages, there are numerous ways to monitor sleep. Since, complex and larger system with overnight test in labs, with experts monitoring the sleep are costly approaches and cause discomfort to patients while sleeping, the proposed system measures the quality of sleep by estimating depth in sleep. Experimental results demonstrated the physiological factors of sleep quality is effective while measured.
Researchers Vincenzo Natale et al., proposed a method [7] to deeply understand the suitability of the smartphone in assessing sleep, future studies should necessarily use polysomnography. As it costly and is uncomfortable while taking tests. This paper presents monitoring sleep with smartphone accelerometer, the present pilot study aimed to compare sleep estimation with a smartphone accelerometer to that of an actigraph accelerometer in healthy adults. 13 volunteers (4 females; mean age 22.97 3.44) simultaneously wore actigraphs, actiwatch and putting smartphone close to the pillow for at least four consecutive overnight recordings. As in actigraphy, they found to get the best solution was to calculate the sleep onset latency independently of any sleep algorithm. Since a recent study has shown a better accuracy for a 5-min rule than the default 10-min rule, they decided to adopt and explore both criteria. The agreement between the two devices was satisfactory. As researchers came up that actigraphy, detection of acceleration is important to monitor sleep and is an essential component that results the motion and movement of the person. There are so many methods presented in the state of the literature [8][9][10][11][12][13][14][15][16][17][18][19][20][21][22][23][24][25], which presents the sleep and health related research methods.

SENSOR ON LIMBS
Overnight sleep monitoring in labs/clinics are very uncomfortable for patients to take sleep test. So, continuous sleep monitoring should be convenient and minimal impact to physical activity. System like this should also be easy to use. Therefore, considering state of the art literature methods, in this proposed research work Accelerometer ADXL335 sensor interfacing with Arduino Nano board is used. It is a triple axes accelerometer, which is a sensor worn on the limbs and taped on the socks. This measures acceleration in three axes. Data is collected, stored in a .txt file, which is used to see movements. The number of rollovers are measured when the subject is undergoing physical movements. Although, sensor acquires physiological data and appends data in every 2000 milliseconds (2 seconds). The ADXL335 triple axis accelerometer can see in Figure 2.
The ADXL335 is a accelerometer sensor with small, thin, low power, complete 3-axis accelerometer with signal conditioned voltage outputs, this sensor measures acceleration with a minimum full-scale range of ±3 g. User can select the bandwidth of the accelerometer using the Cx, Cy, and Cz capacitors at the XOUT, YOUT, and ZOUT pins. On earth, 1g means acceleration of 9.8 m/s 2 . Accelerometer can be used for tilting-sensing applications and also dynamic acceleration resulting from motion, shock or vibration. The output signal of this sensor are analog voltages that are equivalent to the acceleration. Here, all three bandwidths of the accelerometer are used to check the movement in every axis. The algorithm runs on each axis separately and give the results, it takes the first axis and checks the acceleration and then goes to another axis. All three axis are checked to see the motion in every axis are nearly same or average when compared. The movement of the person in all three axes is checked. This sensor uses single supply of 1.8V-3.6V, also its very reliable.

ROLL-OVER DETECTION 5.1. Definition of roll-over
Generally, roll-over is defined as unconscious motions during sleep such as rotational body movements. In this paper, we defined roll-over as a series trunk motion from static state to rational motion during sleep.

Detection algorithm
The algorithm is designed to count the total number roll over in the period of sleep and it is implemented using python. In this proposed algorithm the threshold value is empirically determined as 3 units. a.
Step 1: Reads dataset which are x, y and z axis of accelerometer, using csv.reader function. b.
Step 2: Loop is used to read rows and apply the algorithm on one row. Here, there are three rows which are axis X, Y and Z shown in Figure 3, and algorithm applied in each row separately shown in Figures 4-6. Roll over or movement of the patient is checked on every axis separately. Step 3: If the current row > 1 and X axis >= threshold or X axis <= threshold, increment the total number of rollover counts. d.
Step 4: Repeat step 3 procedure for Y axis and Z axis.  The proposed method captures input data from the readings of accelerometer ADXL355 sensor. The collected data has three rows (X, Y and Z) of data. To carry out this research article, the data used is raw analog voltages. There is no conversion of analog voltages to g units. This alogrithm reads the raw analog voltagaes which is equivalent to acceleration of each axis, resulting the motion or roll-over found using the proposed method. Further, the proposed method also determines duration between two roll-over counts. Duration between two roll-over counts is in form of MM:SS:MS. The duration between two roll-over counts shows the time between two roll-over as shown in Figure 4, Figure 5 and Figure 6. To show duration between two roll-over we need to store two variable with two different timings respectively. First time, the time stored is when the data hits the threshold and counts roll-over. Second time, the time stored is when the data hits the threshold again. Both variable stores two timings or difference between two roll-over counts. Further, the difference is used to record the duration between two roll-over counts. Figure 6. Total number of roll-over Z-axis

Threshold
The proposed method initiates a loop, which counts all the units from the first value of the first column to last value of first column (X-axis). For the current study, to identify the motion from accelerometer dataset it is neccessary to keep a threshold value which results the roll-over counts. A level, point, or value above which something is true or will take place and below which it is not or will not is a threshold. The threshold value is set to 3 units empirically, because if there is a minimum motion then the acceleration data increases or decreases by 1-2 units. It is a very slight motion which cannot be considered as a roll-over. If the movement is more or sudden, the unit can change to maximum and increase or decrease up to 6-7 units. Therefore, total number of rollover counts stores the movements only if the unit is greater than or less than threshold value of 3 units. Further, it repeats the procedure for Y-axis and Z-axis respectively. The collected dataset is presented in Figure 3. The dataset plot of Day one presented in Figure 7. Roll-over is detected based on the threshold. Here, each unit is checked with the threshold (3 units), if the appending data is less than 2 unit the threshold is not considered because it is very modest. The rollover count is considered only when the unit is more than threshold. Proposed algorithm runs on checking the variation with each unit of all three axis. The proposed method detects the variation based on the threshold as shown in Figure 4, Figure 5 and Figure 6. The dataset is automatically appended per 2000 milliseconds (2 seconds) in the time of data collection. As soon as the unit appends it checks if the unit which is appended has increased or decreased by 3 units from previous unit. These three figures show the roll-over detection for each axis, Axis-X, Y and Z and duration between two roll-over counts.

RESULT AND DISCUSSION
At the heart of every actigraphy device is something called an accelerometer. Using Microelectromechanical systems (MEMS) technology, these tiny components act as sensors, converting movement into electrical signals. The proposed algorithm is used to detect roll-over counts from the dataset. Henceforth, the results obtained by using the algorithm on dataset is total number of roll-over counts for X, Y and Z axis. To show the results, the total number of roll-over counts in all three axes is listed in Table 1, data collected and represented here is for 5 hours and 30 minutes when the subject was sleeping. Hence, based on the total number of roll-over counts there is a bar plot representation, shown in Figure 8, which shows total number of roll-over counts obtained from day 1 dataset. Results in Table 1 determines triple axis with total number of roll-over counts and total number of hours during sleep. To count the total number of roll-over we set a threshold, based on the threshold roll-over is detected and increments the roll-over counts. Further, the duration between two roll-over counts is also obtained, which determines that the subject is moving in between these duration. This results are based on one subject.

CONCLUSION
Sleep analysis is a prime study because it relates to the health of human being. Feeling refreshed, good memory, healthy heart, clear skin and less stress are all depends on the amount of sleep and rest a person takes daily. In this paper, the roll-over detection algorithm is proposed and implemented using accelerometer ADXL335 sensor. The sensor is taped on socks during sleep period of a subject, then acceleration reading of limbs where captured and stored in the database. The proposed algorithm detects the roll-over based on threshold and records the duration between roll-over counts. Finally, the proposed algorithm is used to count roll-over counts from each axis to see whether the roll-over counts between all the axis are showing the average results. Here, roll-over counts does not specify the sleep quality of the person. In future work, would like to clarify the relationship between sleep quality, stages of sleep and other physiological signals with respect to proposed algorithm.