Member-only story

Real-Time Signal Processing on the Apple Watch: Counting Exercise Repetitions

Anmol Parande
10 min readJan 6, 2021

--

Photo by Victor Freitas on Unsplash

Given a particular task, how do you design discrete filters to solve the problem through the lens of signal processing? If you are working on an embedded device, you might have several constraints. For one, your code must work in real-time rather than on a signal you have already collected many seconds of samples from. You may also be constrained in how much memory your device has or how much power you want your algorithm to consume.

The purpose of this article is to be a case study that demonstrates how you might go about designing a digital signal processing system. In particular, we’ll approach the task of designing an Apple Watch application that can count, in real-time, how many repetitions of an exercise a user has completed. The user should be able to calibrate the application to count any exercise they want.

As we go about doing this, you will learn two things.

  1. How to choose linear and non-linear filters to achieve a particular goal.
  2. How to implement these filters to operate in real-time with minimal delays and memory.

Along the way, you’ll see how to access the motion data on the Apple Watch and learn how to build a detector that the user can calibrate with just 5 repetitions of an exercise of their choice.

You’ll find this article most useful if you have some familiarity with the basics of signal processing. Throughout the article, I will be referencing this GitHub repository which is the code for the Apple Watch app (and its iPhone companion app) that implements the system I describe. I’ll highlight the most relevant pieces of signal processing code, but you can always view the source for the full picture.

The Sensors

The first step in designing our system is to figure out which signals will provide the most relevant data. On the Apple Watch, our signals will come from the array of sensors installed on the device. For counting repetitions of an exercise, the most useful ones will probably be those related to motion and orientation: the accelerometer and the gyroscope.

As its name implies, the accelerometer tells us how much the watch is being accelerated. Part of this…

--

--

Written by Anmol Parande

Flight Software Engineer at Astranis Space Technologies

No responses yet

Write a response