Home Algorithm

Technical Information - Algorithm

This page contains descriptions for the algorithm behind the Actigraphy Sleep Toolkit's sleep detection.

Time-series actigraphy data is stored in fixed length epochs of typically 15, 30 or 60 seconds. Each epoch is summarised into a single figure representing the activity intensity (counts) and the environmental light level (Lux).  

In traditional actigraphy, these summaries are calculated on the device, or with an off-line algorithmic script when modern accelerometry is converted to be backwardly compatible.  

Classifying an Epoch as Sleep or Wake  

Each epoch within the data is assigned a classification of sleep or wake based on its weighted activity count (Table 1). For a given epoch, the weighted sum is calculated by considering the activity counts in relation to the target epoch (labelled e in the table below). The calculation incorporates activity counts two minutes on either side of the target epoch. For a 60s epoch file, this means looking two epochs ahead and two epochs behind. When working with epoch periods of less than 60s, the number of epochs that make up two minutes is adjusted accordingly.   

The activity count calculation assigns a specific and predetermined weighting to each minute relative to the target epoch:   

  • The sum of activity counts one minute before and one minute after the target epoch are multiplied by 0.2.
  • The sum of activity counts two minutes before and two minutes after the target epoch are multiplied by 0.04.  
  • The activity count of the target epoch itself is normalised to represent one minute. This would mean, for a 15-second epoch, its activity count is multiplied by 4. Similarly, for a 30-second epoch, its activity count is multiplied by 2. No adjustment is required for a 60-second epoch. 

Table 1 Breakdown of weights for activity count calculation in relation to target epoch.

Consider the following 60s epoch example:

Table 2 Example 60s epoch.

The overall activity count for the epoch at time 10:30 would be: 

0.04(65 + 60) + 0.2(78+62) + 1(75) = 5+28+75 = 108  

On default analysis options, the wake threshold is set to 40. As 108 is greater than this threshold, this would effectively class the epoch at 10:30 as Wake.   

Sleep Detection Algorithm  

A rest start and end time are added to the analysis using a participant diary or visual scoring by a sleep clinician. These define the rest interval and, when added, the associated sleep interval is automatically detected within the defined period. The start and the end of the sleep interval is determined by two user-defined parameters.

Changing any of these two parameter values will alter the sleep interval within the rest period:

  • The activity count threshold that classifies an epoch as either Wake or Sleep. An activity count below the threshold classifies the epoch as Sleep. An activity count equal to or above the threshold classifies the epoch as Wake. The default threshold is set to 40 counts.
  • The number of consecutive sleep epochs that define the start and end of the sleep interval. A more detailed explanation of this parameter is provided below. The default number of consecutive sleep epochs is set to 5.    

Sleep Interval Detection using Consecutive Sleep Epochs 

Within the rest interval, wake classifications associated with movement are typically interspersed between periods of consecutive sleep epochs. Each sleep period separated by a wake period is referred to here as a sleep cluster. The sleep detection algorithm looks for the first and last sleep clusters longer than a predetermined length of time. To mark 5 minutes of consecutive sleep as the start of sleep, this equates to 20 epochs for a 15s epoch file. The sleep start time is marked by the time of the first sleep epoch in the first cluster. Similarly, sleep end time is the time of the last sleep epoch of the last cluster.   

Example data period with 5 minutes of consecutive sleep for a 60s epoch file: 

References
Fekedulegn 2020 

Fekedulegn, D. (2020) Actigraphy-Based Assessment of Sleep Parameters, Annals of Work Exposures and Health, 64(4), pp. 350-367. DOI: 10.1093/annweh/wxaa007 

Gao 2022 

Gao, C. (2022). Actigraphy-based sleep detection: Validation with polysomnography and comparison of performance for nighttime and daytime sleep during simulated shift work. Nature and Science of Sleep, 14, 1801 1816. DOI: 10.2147/NSS.S373107

Oakley 1997 

Oakley, N. R. (1997). Validation with Polysomnography of the Sleepwatch Sleep/Wake Scoring Algorithm Used by the Actiwatch Activity Monitoring System. Bend: Mini Mitter, Cambridge Neurotechnology 

Paquet 2007 

Paquet, J. (2007). Wake detection capacity of actigraphy during sleep. Sleep, 30(10), 1362-1369. DOI: 10.1093/sleep/30.10.1362 

Patterson 2023

Patterson, M. R. (2023). 40 years of actigraphy in sleep medicine and current state of the art algorithms. npj Digital Medicine, 6, Article 51. DOI: 10.1038/s41746-023-00795-x

Roomkham 2019

Roomkham, S. (2019) Sleep monitoring with the Apple Watch: comparison to a clinically validated actigraph, F1000Research, vol. 8, p. 754. DOI: 10.12688/f1000research.19341.1

An unhandled error has occurred. Reload 🗙