# Sleep/Wake Detection Using Motionlogger and Vivosmart 4

Continuing our mission to see whether consumer-grade smartwatches can effectively replace medical-grade actigraphic devices, we reverse-engineered the algorithm for Motionlogger and found that we could replicate its results with affordable consumer wearables, such as the Garmin Vivosmart 4.

Dec 9, 2022
By Drs. Han-Ping Huang, Francis Hsu and Andrew Ahn

## Abstract

Motionlogger Sleep Watch (AMI, NY) is a popular medical-grade actigraphic device that can detect nighttime sleep/wake patterns and derive sleep parameters based on acceleration (ACC) signals. However, it is relatively expensive compared to consumer wearable devices, and thus not affordable to general users.

To evaluate whether an affordable consumer smartwatch, Vivosmart 4 (Garmin, Olathe, Kansas), can effectively replace Motionlogger, we reverse-engineered the algorithm for Motionlogger and applied the same algorithm to the raw-ACC data obtained from Vivosmart 4. The Vivosmart 4 does not routinely provide raw ACC data, but through our partnership with Garmin, a customized SDK was created to extract raw ACC signal from Vivosmart 4 and used to reproduce the sleep/wake patterns obtained from Motionlogger.

This post introduces the signal processing method of detecting nighttime sleep/wake patterns based on the acceleration signal. As described here, we found the sleep/wake patterns derived from Vivosmart 4 to be consistent with that of Motionlogger. In the following two posts, we will explore how Motionlogger derives sleep parameters from sleep/wake patterns, and compare the performance between Motionlogger and Vivosmart 4 with more sleep data.

## 1. Experiment Setup

Our experiment setup is shown in Figure 1. Motionlogger and Vivosmart 4 were worn simultaneously during sleep for comparison. Motionlogger is a piezoelectric accelerometer with a sampling rate of 10 Hz. Vivosmart 4 is a 3-axis MEMS accelerometer with a sampling rate of 25 Hz.

## 2. From Acceleration Signal to Sleep/Wake Detection

### 2.1 Zero-Crossing Threshold

According to the Motionlogger User’s Guide, the zero-crossing (ZC) mode is the suggested method of quantifying activity [1]. The zero-crossing count is a measure of movement frequency, which counts the number of times the acceleration signal crosses zero (or a preset threshold near zero). Noise is inevitable while measuring the acceleration signal, which implies that even if the accelerometer were placed on a static wooden desk, random fluctuation in the signal would still exist. To minimize the effects of noise on movement frequency measurements, the threshold should be set above the predominating noise range.

Figure 2 shows the ACC signals during 7 mins of steady sleep without any significant movements. The fluctuation in the signal is considered noise with a standard deviation (SD) of 2.84 mG. We set the ZC threshold as 4xSD = 11.36 mG. Assuming a normal distribution, less than 0.01% of data would fall outside the range of mean ± 4 SD. In our examples, there is only 1 data point among the 10500 points (7-min x 60-sec x 25-Hz) exceeding the threshold, and that data point contributes to 2 ZC counts.

### 2.2 Signal Processing

Figure 3 illustrates the signal processing method for deriving sleep/wake. The general idea of the method can be found in reference [1].

Figure 3(a) illustrates the acceleration signal from Vivosmart 4 in terms. The acceleration signal $a'(t)$ is derived from a two step calculation. First, we derive $a(t)=\sqrt{a_x^2(t)+a_y^2(t)+a_z^2(t)}$

In the equation, $a_x(t)$, $a_y(t)$, and $a_z(t)$ are the raw x, y, and z-axis acceleration data, respectively. Second,  $a'(t)$ is derived as at subtracting its moving average of window length 9 to eliminate the low-frequency variation.

Figure 3(b) illustrates the ZC count in every minute as ZC(n), where n is the epoch index with an epoch length of 1 min.

Figure 3(c) illustrates the Cole–Kripke score labeled as S(n), which is derived from ZC(n) as [1]:

Sn=0.0033× [1.06∙ZCn-4+0.54∙ZCn-3+0.58∙ZCn-2+0.76∙ZCn-1+2.30∙ZCn+0.74∙ZCn+1+0.67∙ZCn+2].

Finally, the epochs with S(n) below and above 1 are detected as sleep and awake period, respectively. Figure 3(d) illustrates the resulting sleep/wake patterns.

## 2.3 Comparison between Motionlogger and Vivosmart 4

As can be seen in Figure 3(d), the sleep onset to offset time is 1:20 to 7:37 with an interval of 377 mins. Table 1 lists the consistent and inconsistent results between Motionlogger and Vivosmart 4. The results from the two watches are perfectly consistent.

## 3. Conclusion

We reverse-engineered the full algorithm utilized in the Motionlogger to derive nighttime sleep/wake patterns from the raw acceleration signal. The sleep/wake patterns derived from Vivosmart 4 are perfectly consistent with that of Motionlogger in this sample case. In the following two posts, we will explore how Motionlogger derives sleep parameters from sleep/wake patterns, and compare the performance between Motionlogger and Vivosmart 4 with more sleep data.

### Get the Entire Actigraphy Collection!

Enter your email to access Labfront’s entire actigraphy collection in PDF format.

## 4. References

[1] D. Fekedulegn, M. E. Andrew, M. Shi, J. M. Violanti, S. Knox, and K. E. Innes, "Actigraphy-based assessment of sleep parameters," Annals of Work Exposures and Health, vol. 64, no. 4, pp. 350-367, 2020.

[2] Ambulatory Monitoring, Inc., “Motionlogger user guide,” Available at https://agingresearchbiobank.nia.nih.gov/studies/sof/documents/download/Protocols/Visit_8/Motionlogger.pdf/.

Last medically reviewed on
Dr. Han-Ping Huang, PhD

Research Lead (and Designated Plant Caretaker) at Labfront. Han-Ping is a researcher who seeks interesting phenomena, especially the interdisciplinary ones. His dream is to make all the riveting research be easily explored.

Dr. Francis Hsu, PhD