Calibrating and Filtering Acceleration Data for Wearable Sensor Analytics

Wearables are everywhere now – from fitness bands that count steps to smart shoes that warn of a stumble. All that promise hinges on one thing: clean, trustworthy acceleration data. If the numbers are off, your app might think you’re dancing when you’re actually sitting, and nobody wants a false alarm about a fall. In this post I’ll walk you through a practical way to calibrate your sensor and then filter the data so the analytics you build on top are reliable.

Why Calibration Matters

The simple truth about sensor drift

Even the best MEMS accelerometers have a tiny bias built into them. When the device sits still, the output should read 0 g on the X and Y axes and 1 g on Z (the pull of gravity). In reality you’ll see something like 0.02 g on X, –0.01 g on Y, and 0.98 g on Z. That small error is called bias, and it can creep over time as temperature changes or the chip ages.

If you ignore bias, every calculation that depends on the raw numbers – step detection, activity classification, or fall detection – will inherit that error. The result is a drift that looks like a slow walk when the wearer is actually standing still. Calibration is the process of measuring that bias and subtracting it out, giving you a clean baseline to work from.

A Step‑by‑Step Calibration Routine

1. Gather a reference motion

Find a flat, stable surface – a kitchen counter works fine. Place the wearable on the surface and make sure it is not moving. Record at least 10 seconds of data at your normal sampling rate (most wearables use 50–100 Hz). This gives you a snapshot of the sensor’s output when it should read 0 g on X and Y, 1 g on Z.

2. Compute the bias

For each axis, calculate the average of the recorded values.

  • biasX = average(X)
  • biasY = average(Y)
  • biasZ = average(Z) – 1.0

The subtraction of 1.0 on Z removes the constant pull of gravity, leaving only the sensor’s offset.

3. Store the bias

Save these three numbers in the device’s non‑volatile memory or in a configuration file on the host. Most micro‑controllers have a few bytes of EEPROM that are perfect for this.

4. Apply the correction in real time

Every new sample you read from the accelerometer should be adjusted:

Xcorr = Xraw - biasX
Ycorr = Yraw - biasY
Zcorr = Zraw - biasZ

Do this as early as possible in your data pipeline – before any high‑level algorithm runs.

5. Re‑calibrate when conditions change

Temperature is the biggest culprit for bias drift. If your wearable will be used in a hot gym and a cold office, schedule a quick re‑calibration each time the device powers up. A simple “shake‑to‑calibrate” gesture can be a user‑friendly way to trigger it.

Filtering the Raw Stream

Calibration removes a constant offset, but the data still contains high‑frequency noise from vibration, electrical interference, and the sensor’s own quantization. Filtering smooths those spikes while preserving the motion you care about.

Low‑pass filter basics

A low‑pass filter (LPF) lets slow changes pass and blocks rapid ones. The most common choice for wearables is a first‑order exponential moving average (EMA), also called a single‑pole IIR filter. It’s cheap to compute and works well for step detection.

The EMA formula is:

filtered[n] = alpha * raw[n] + (1 - alpha) * filtered[n-1]

alpha controls the cutoff frequency. A value of 0.1 works for 50 Hz data when you want to keep motions slower than about 5 Hz (typical human walking).

Implementing the filter

  1. Choose alpha. A quick rule: alpha = dt / (RC + dt), where dt is the sample period and RC is the desired time constant. For a 20 ms sample period and a 200 ms time constant, alpha ≈ 0.09.
  2. Initialize the filtered value with the first raw sample.
  3. Run the EMA equation on each new sample for X, Y, and Z separately.

Because the filter is recursive, it needs only the previous output, so memory usage stays minimal – perfect for a tiny wearable MCU.

When to use a band‑pass filter

If you need to isolate a specific frequency band – say, the 1–3 Hz range that corresponds to a person’s stride – you can cascade a high‑pass filter (to remove DC and very low drift) with the low‑pass filter above. The math is the same; you just apply two EMA stages with different alpha values.

Putting It All Together: A Real‑World Example

A few months ago I built a prototype smart shoe for a friend who loves trail running. The shoe had a 3‑axis accelerometer mounted on the insole. The first version gave wildly varying step counts when the temperature dropped below 10 °C.

I went back to the lab, ran the calibration routine on a cold morning, and stored the bias values in the shoe’s flash. Then I added an EMA with alpha = 0.08. The difference was night‑and‑day: the step count stayed within 2 % of a reference pedometer, and the fall‑detection algorithm stopped firing false alarms when the shoe hit a rock.

The lesson? A few lines of code for bias correction and a simple filter can turn a noisy prototype into a reliable product.

Quick Checklist

  • Record 10 s of still data on a flat surface.
  • Compute and store bias for X, Y, Z.
  • Apply bias subtraction to every new sample.
  • Choose an EMA alpha that matches your motion bandwidth.
  • Run the EMA on each axis before higher‑level analysis.
  • Re‑calibrate on power‑up or when temperature changes.

With these steps, your wearable’s acceleration data will be clean enough for most analytics – from simple step counters to sophisticated activity classifiers.

Reactions
Do you have any feedback or ideas on how we can improve this page?