Search code examples
androidaccelerometersensorsandroid-sensors

Implementing a Pedometer: How to find a local peak?


I am trying to make a very simple Android pedometer, but so far it's failing pretty badly. I got some advice here and there on the internet, but nothing seems to be working.

I basically set an acceleration sensor and get the values of the x, y and z axis. After that I calculate their distance from the origin, which is basically: d = sqrt(x²+y²+z²) followed by the calculation of their moving average. My idea was whenever I find a local peak I should count as a step. The issue is, I have no idea how to find the local peak right away in order to count the step. I am sorry if this seems like a simple problem, but I really have no idea how to go on from here.

Thank you very much.


Solution

  • I tried to implement this and the approach you take is subject to substantial measurement errors. You should just accept it. The reasons are:

    • a phone can be in any location, not only the trousers' pocket
    • phone accelerators are not medically precise, and they can deviate and "flow" given exactly the same position in space
    • moving average is not the best known technique to do this, a better one would use some sort of waves and wavelet analysis
    • One step has two local maximums and two local minimums (if I remember correctly)
    • There is no strict definition of a "step" globally accepted, this is due to physiology, measurements and various techniques used in the research field

    Now to your question:

    • Plot the signal from the three axis you have, this will dramatically help you (signal vs time)
    • Define a window of a fixed (or slightly moving) size, moving window is required to detect people who walk slower, run or have disability
    • Every time you have a new measurement (usual frequency is about 20-30 Hz), put one to the tail of the window (your signal measurement's queue) and pop one from the head. In this way you will always have a queue with the last N measurements
    • Again for every mesurements recalculate your stuff and decide if the window contains one (or two!) minimums and count it as a step

    good luck!