How does a phone πŸ“± count your steps? πŸšΆβ€βž‘οΈπŸšΆβ€β™€οΈβ€βž‘οΈ

Ryan Batubara, Isaiah Fang, Matt Tokunaga

Link to writeup

Link to physionet data

Link to original paper

If you saw a person walking,
you could visually count their steps.

But how does a computer count steps?

One idea is measuring movement as directionless acceleration, or acceleration magnitude.

But what does a step look like in acceleration data?

We have no idea what a step looks like in acceleration data.
We need acceleration data with steps that have been identified manually.

Once we have this, we can find the "shape" of a normal step.
Here's what that process might look like:

First, we start with data from a controlled scientific experiment.

Scroll to continue

We now have a step template!

Researchers used a similar process and found that this shape is an ideal template:

Then, counting steps becomes a similarity problem. That is, at what timestamps does the data most closely match the step pattern?

So, how is similarity calculated?

Take the graphs, multiply them, and find the area under the result:

Green = RedBlue

Similarity = Green

Example #1: A close match!

Example #2: Not a close match at all!

Our data is just like these graphs, just more complex!

Finding timestamps with high similarity

At each timestamp, let's find the similarity between the data and a step pattern.
On the left is the similarity plot, and on the right is our data:

You might have noticed that for some particular bad matches, our similarity is negative. But how is that possible? We have two strictly positive functions, shouldn't they multiply to get another strictly positive function, which would have a positive integral? The answer is yes! The step pattern on the graph is actually a scaled and translated version of the real thing. The real thing is centered on the origin and actually has mean zero. This is because if you don't impose this restriction, you could always get a step pattern that gives higher similarity by just translating your pattern upwards, since you would be integrating a bigger and bigger function.

So, how can we count the number of steps?

A peak occurs in the similarity plot when the similarity is high - that is, when a step occurs! So our similiarity problem becomes a peak counting problem.

Here's an easy way to count peaks: Take the biggest data point in some interval around itself. Wider intervals ignore subsequent peaks and smallest ones capture even local minimums:

To find the peaks in our similarity plot, we use our step pattern width (1 second). Here's the result:

These peaks in similarity correspond to the following 10 steps:

Notice how the end of one step generally lines up with the beginning of the next step!
This is exactly what we want, since walking is cyclic and steps are discrete.

And we're done! There are 10 peaks, so we have 10 steps!
We've successfully counted the number of steps!

Now you know a little about how computers count steps!

We hope you enjoyed learning about how your phone counts steps! Here's a quick summary:

  1. Acceleration magnitude is collected by sensors.
  2. Similarity scores are calculated with a step template.
  3. Peaks are found in the similarity scores.
  4. Count peaks in the similarity scores to get the number of steps!

To learn more, see our writeup, data, and the original paper:

Link to writeup

Link to physionet data

Link to original paper

We welcome your feedback!
If you have any questions or comments about this visualization, please feel free to reach out.

Thank you for exploring this interactive visualization with us!