Opening the Black Box: Publishing Pebble’s activity-tracking algorithms

When I started my study of bipolar disorder, I spent an inordinate amount of time comparing different devices, each differing in ease of use, reliability, battery life, remote access, and cost. What eventually led me to Pebble was my need to know exactly what was being calculated.

After reviewing dozens of commercial and clinical devices, I determined the most important variables to measure and designed two algorithms to capture the most salient motion characteristics. After months of validation in collaboration with Pebble and the Stanford Wearables Lab, I am making these two algorithms available to the public to encourage the use of a standard set of measures.

The first algorithm is for a general measure of motion called VMC. My version is a variant on an algorithm called Proportional Integrating Mode (PIM), which researchers in sleep and sports medicine have used for years. The clinical devices that use this algorithm, such as those produced by Actigraph Corp and Respironics, have been used in hundreds of studies. Even though the specifics of the algorithm used in each device is different, most clinical devices use the same PIM method.

The PIM algorithm takes the raw acceleration data for each minute on each X,Y, and Z axis and performs a bandpass filter from 0.25 to 2Hz. This process filters out movements that are slower than about 0.25 Hz and faster than 2Hz to focus on the range of movement most associated with exercise.

With the filtered data, the PIM integrates the absolute value of each sample over the length of a minute on each axis. Then it takes the Euclidean norm of the three integrals, one for each axis, which gives the Vector Magnitude Counts Per Minute: this is the VMC measure output in the Pebble Health API. In equation form, the VMC is calculated like this:

This algorithm runs quickly and represents not just linear acceleration, but also rotation thanks to the gravity vector.

The second algorithm for step counting is slightly more complex. I designed it with Ron Marianetti specifically for the Pebble.

Walking and running are both highly rhythmic activities and happen usually in a small range of frequencies. If we could measure the specific frequency of motion and strength of that rhythmicity, then we could tell how likely the wearer was walking or running.

Specifically, the step counting algorithm looks at five-second chunks of acceleration data and transforms the data on each axis by an algorithm called the Fast Fourier Transform (FFT). The FFT is a discrete version of the Fourier transform and calculates the strength of each frequency component of a vector of numbers. The more rhythmic the signal is at a certain frequency, say 2Hz, the larger the FFT coefficient for that frequency.

Looking at the FFT output for each axis, we can pick out the frequency with the largest coefficient. By comparing against the coefficients of all the other frequencies, we can come up with a measure of strength of rhythmicity. Most activities are pretty jumpy with little rhythmicity, but walking or running will cause the rhythmicity to jump suddenly above a threshold.

If the five-second period is above the rhythmicity threshold and above a given VMC threshold, then that period is counted as walking or running. The most significant frequency of that five-second period determines the number of steps that we estimate have taken place. The algorithm can be described as:

From these scores we calculate the Euclidean norm across all axes. If the VMC and the score exceed a threshold value for a given five-second interval, and the median measured Hz within the 0.25Hz and 2.5Hz range, then that period is counted as stepping, and the median Hz is taken as the step count.

With applications such as sleep measurement, calorie counting, habit modification, and perhaps even mood detection, wearables combined with other mobile technologies promise us a new window into human behavior and health.