Vibrations All Around Us 6: Crude Pedometer

In this blog post, we will be building a Crude Pedometer using the Nicla Sense ME. By the end of this blog post you’ll be able to measure how many steps you’ve taken with the Nicla on your shoe and how far you traveled, emulating a wearable device. For this lab I’ll simply be sticking the Nicla on top of my shoe as shown below. It should be as rigidly attached to your shoe as possible so it picks up on the impact of your shoe as it strikes the floor on each step

To get some inspiration for how we might build the pedometer, let’s first record some data with the Nicla on my shoe. I’ll go for a short walk with some pauses and turns in the middle. I took a total of 36 steps over the course of the experiment.  Recall that resultant acceleration is calculated by taking the magnitude of the vector formed by adding the 3 acceleration components, for more information refer to our previous post to post #2 on Tools Setup.

Let’s zoom in on 3 steps that I’ve taken on my right foot, or 6 steps in total with both feet.

The first spike comes from picking my foot up off the ground and accelerating it forward in front of me (orange), the second spike is the impact of my foot striking the ground (purple), and in between these 2 events there is a slight ‘weightlessness’ while my foot slows down and falls before making contact with the ground (yellow). Finally, while my left foot is in contact with the floor and my right foot is taking a step, the resultant acceleration is very small (light blue). Intuitively, we could write an algorithm that identifies periods of high activity (green), then check that the waveform in this period of activity looks like how we expect a “step” to look. Let’s write some pseudo code for this that will work in real-time, I’m going to be using variance to measure stillness (see Blog 5 for a refresher on this):

  1. Wait for a period of high activity (wait for the windowed variance to exceed a threshold).
  2. Wait for the foot to leave the ground (wait for the resultant acceleration to exceed a threshold). 
  3. Wait for 0.25 seconds.
  4. Wait for the foot to impact the ground (wait for the resultant acceleration to exceed another threshold). Step count += 2 and return to step 1.
  5. Wait for a period of low activity (windowed variance dips below a threshold).

I’m going to use the Moving Average Filter from Blog 4 in this series to smooth out the high frequency noise, which will make the waveform in the previous graph look like this:

From looking at the time series data, a safe acceleration threshold should be 2 m/s^2. We can also assume that 0.2 seconds of wait time after the foot-leaving-the-ground impulse is enough for the resultant acceleration to return below the threshold. I’ll be using the moving variance window from the previous blog for this implementation, so please refer to that if you haven’t done so already. To manage the decision making process of our algorithm I’m going to be utilizing a state machine structure. For a more complex system, where lot’s of other processes might be running, a state machine makes for a very readable program structure and allows us to easily scale and increase the complexity of our pedometer with few changes to the main running loop. Using a state machine allows us to identify key characteristics of each footstep such as foot liftoff and foot impact events.

In this example, the program reads 32 steps, meaning we missed 4 steps that were taken. The misses came during periods of odd movements such as turning steps or stopping steps. For someone going for a walk in the park these “special” steps are going to represent a pretty small number of the fraction of total steps taken, giving our algorithm pretty good performance. For someone who is walking in a more hectic environment we might need to such as a busy city we might need to improve our algorithm. Of course, in a wrist-worn device, like a Fitbit, more advanced algorithms are used to intelligently separate steps from background noise. In fact, many smart wearables have been adapted to count steps including wrist trackers, wrings and headwear! If you are building this type of product, please Contact us and we can expertly tailor a step-counting algorithm towards your application!

Not too bad! In the next lesson we’ll be going over the Frequency domain and Fast-Fourier Transform.

Leave a Reply

Your email address will not be published. Required fields are marked *