PebbleOS v4.47.0-327-g7753e801d
Loading...
Searching...
No Matches
van Hees

Sleep classification from the wrist angle (van Hees et al., 2015). More...

Data Structures

struct  pbl_vanhees_sample
 Accelerometer sample, in mG. More...
 

Macros

#define PBL_VANHEES_SAMPLE_HZ   25
 Accelerometer sampling rate expected by the algorithm, in Hz.
 
#define PBL_VANHEES_ANGLE_THRESHOLD_DEG   5
 A larger angle difference between successive epochs is a posture change, in degrees.
 
#define PBL_VANHEES_TIME_THRESHOLD_M   5
 Minimum time without posture change of a sustained inactivity bout, in minutes.
 
#define PBL_VANHEES_LAG_M   (PBL_VANHEES_TIME_THRESHOLD_M - 1)
 Minutes between the end of a minute and its verdict.
 

Functions

uint32_t pbl_vanhees_state_size (void)
 Get the size of the algorithm state.
 
void pbl_vanhees_init (struct pbl_vanhees *state)
 Initialize the algorithm state.
 
void pbl_vanhees_analyze_samples (struct pbl_vanhees *state, const struct pbl_vanhees_sample *samples, uint32_t num_samples)
 Analyze accelerometer samples.
 
bool pbl_vanhees_minute_update (struct pbl_vanhees *state, bool *inactive)
 Classify the minute that ended PBL_VANHEES_LAG_M minutes ago.
 

Detailed Description

Sleep classification from the wrist angle (van Hees et al., 2015).

The algorithm processes accelerometer samples at PBL_VANHEES_SAMPLE_HZ in 5 second epochs. Each epoch gives the angle of the Z axis (perpendicular to the skin) to the horizontal plane, computed from the per-axis median. A posture change is a difference of more than PBL_VANHEES_ANGLE_THRESHOLD_DEG between successive epochs, and a sustained inactivity bout is a period of at least PBL_VANHEES_TIME_THRESHOLD_M minutes without one.

It only classifies minutes: building sleep sessions out of them is left to the caller.

The caller owns the state, of size pbl_vanhees_state_size():

struct pbl_vanhees *state = malloc(pbl_vanhees_state_size());
// For every batch of 25 Hz samples
pbl_vanhees_analyze_samples(state, samples, num_samples);
// Once a minute
bool inactive;
if (pbl_vanhees_minute_update(state, &inactive)) {
// The minute that started PBL_VANHEES_LAG_M + 1 minutes ago was inactive, or not
}
free(state);
void pbl_vanhees_init(struct pbl_vanhees *state)
Initialize the algorithm state.
bool pbl_vanhees_minute_update(struct pbl_vanhees *state, bool *inactive)
Classify the minute that ended PBL_VANHEES_LAG_M minutes ago.
void pbl_vanhees_analyze_samples(struct pbl_vanhees *state, const struct pbl_vanhees_sample *samples, uint32_t num_samples)
Analyze accelerometer samples.
uint32_t pbl_vanhees_state_size(void)
Get the size of the algorithm state.

Data Structure Documentation

◆ pbl_vanhees_sample

struct pbl_vanhees_sample

Accelerometer sample, in mG.

Data Fields
int16_t x
int16_t y
int16_t z

Macro Definition Documentation

◆ PBL_VANHEES_ANGLE_THRESHOLD_DEG

#define PBL_VANHEES_ANGLE_THRESHOLD_DEG   5

A larger angle difference between successive epochs is a posture change, in degrees.

◆ PBL_VANHEES_LAG_M

#define PBL_VANHEES_LAG_M   (PBL_VANHEES_TIME_THRESHOLD_M - 1)

Minutes between the end of a minute and its verdict.

A minute at the very start of a bout is only known to be in one once the rest of the bout has been seen.

◆ PBL_VANHEES_SAMPLE_HZ

#define PBL_VANHEES_SAMPLE_HZ   25

Accelerometer sampling rate expected by the algorithm, in Hz.

◆ PBL_VANHEES_TIME_THRESHOLD_M

#define PBL_VANHEES_TIME_THRESHOLD_M   5

Minimum time without posture change of a sustained inactivity bout, in minutes.

Function Documentation

◆ pbl_vanhees_analyze_samples()

void pbl_vanhees_analyze_samples ( struct pbl_vanhees *  state,
const struct pbl_vanhees_sample *  samples,
uint32_t  num_samples 
)

Analyze accelerometer samples.

Samples are buffered until a full epoch is available.

Parameters
stateState passed to pbl_vanhees_init().
samplesSamples, in mG, at PBL_VANHEES_SAMPLE_HZ.
num_samplesNumber of samples in samples.

◆ pbl_vanhees_init()

void pbl_vanhees_init ( struct pbl_vanhees *  state)

Initialize the algorithm state.

Parameters
stateState, of pbl_vanhees_state_size() bytes.

◆ pbl_vanhees_minute_update()

bool pbl_vanhees_minute_update ( struct pbl_vanhees *  state,
bool *  inactive 
)

Classify the minute that ended PBL_VANHEES_LAG_M minutes ago.

Called once a minute. A minute without samples discards the history.

Parameters
stateState passed to pbl_vanhees_init().
[out]inactivetrue if the whole minute lies in a sustained inactivity bout.
Returns
true if there is enough history for a verdict, false otherwise (inactive is then false).

◆ pbl_vanhees_state_size()

uint32_t pbl_vanhees_state_size ( void  )

Get the size of the algorithm state.

Returns
Size of the state, in bytes.