IMU Calibration and Drift Management in Consumer Trackers
Introduction
Have you ever wondered how your pet's GPS tracker knows whether they're running, resting, or digging in the backyard? Or why sometimes the tracker seems to lose accuracy after a few weeks of use? The secret lies in a sophisticated component called an Inertial Measurement Unit (IMU)—a sensor that measures motion across nine degrees of freedom.
In this article, we'll explore the engineering challenges of IMU calibration using our EverSense pet tracker as a real-world case study. Think of IMU calibration like tuning a high-precision instrument—even the best sensors need regular adjustment to maintain their accuracy. Just as atomic clocks require environmental compensation, IMU sensors experience "drift" that compounds over time, affecting everything from activity classification to dead reckoning navigation.
The Tracker uses the ICM-20948, a 9-axis IMU combining a 3-axis accelerometer, 3-axis gyroscope, and 3-axis magnetometer. This sensor fusion architecture enables sophisticated motion analysis, but it also introduces complex calibration challenges that span mechanical, electromagnetic, and thermal domains.
Whether you're a hardware engineer designing IoT devices, a firmware developer implementing sensor fusion algorithms, or an embedded systems architect planning production calibration flows, this deep-dive will reveal the practical engineering solutions that keep thousands of pet trackers accurate across varying temperatures, electromagnetic interference, and months of continuous operation. We'll explore not just the textbook theory, but the real-world compromises, failure modes, and optimization strategies that emerge when you deploy IMUs at scale.
The Problem: Multi-Domain Error Sources in 9-Axis IMUs
The ICM-20948's 9-axis architecture provides rich motion data, but each sensor type exhibits unique error characteristics that interact in non-obvious ways. Understanding these error sources is critical for designing effective calibration strategies.
Accelerometer: Static Bias and Scale Factor Errors
The 3-axis MEMS accelerometer measures linear acceleration along X, Y, and Z axes. In an ideal world, a stationary sensor aligned with gravity would read [0, 0, 1g]. In reality, manufacturing process variations introduce:
- Zero-g offset: Bias present even in zero acceleration conditions, typically ±50-100mg between units
- Scale factor error: The sensitivity deviates from nominal 1g/LSB (least significant bit), usually 0.5-3%
- Cross-axis sensitivity: Acceleration along one axis creates false readings on perpendicular axes due to mechanical misalignment
- Nonlinearity: Response deviates from linear at high accelerations (>4g in the ICM-20948)
For pet tracking, accelerometer accuracy directly impacts activity classification algorithms. A 50mg bias error translates to roughly 5% error in activity intensity estimation—enough to misclassify "walking" as "running" or miss subtle behavior changes indicating health issues.
Gyroscope: The Drift Problem
The 3-axis gyroscope measures angular velocity around each axis. Gyroscopes are exceptional for tracking rapid orientation changes but suffer from integration drift—small errors compound exponentially over time:
- Rate noise density: The ICM-20948 specifies 0.015°/s/√Hz white noise, which manifests as angle random walk of approximately 0.15°/√hr
- Bias instability: The offset drifts even when stationary, typically 0.1-0.5°/s for consumer-grade MEMS gyros
- Temperature-induced drift: The gyroscope exhibits approximately 0.03°/s/°C sensitivity—a 30°C temperature swing (common when a pet moves from indoors to summer sun) introduces 0.9°/s of additional bias
Here's where the engineering gets interesting: integrate a 0.2°/s gyroscope bias error over one hour, and you accumulate 720° of heading uncertainty. This is why gyroscopes alone cannot maintain long-term orientation—they require continuous correction from complementary sensors.
Magnetometer: Hard-Iron, Soft-Iron, and Temporal Interference
The 3-axis magnetometer measures Earth's magnetic field (approximately 25-65 μT depending on location) to determine absolute heading. This is theoretically elegant but practically challenging in electronic devices:
- Hard-iron distortion: Ferromagnetic materials create constant offset fields. In the tracker, the Li-ion battery's steel can, PCB mounting hardware, and speaker magnets contribute 10-30 μT of constant bias
- Soft-iron distortion: Ferrous materials distort Earth's field non-uniformly depending on device orientation, requiring full 3×3 correction matrices
- Temporal interference: The ESP32-S3's Wi-Fi transmitter (up to 20dBm at 2.4GHz) and RFM95W LoRa radio (14dBm at 915MHz) generate dynamic electromagnetic fields that pulse with transmission bursts
The engineering challenge: the magnetometer must distinguish Earth's 50 μT field from the 30 μT constant offset plus 5-10 μT dynamic interference from radios located just 15mm away on a compact PCB. This requires both static calibration (ellipsoid fitting) and dynamic rejection (temporal filtering during known transmission windows).

Approach: Three-Tier Calibration Architecture
Rather than treating calibration as a one-time factory process, we've architected a hierarchical system that addresses error sources at different time scales and operational contexts:
1. Factory Calibration: Systematic Error Characterization
During production, each device undergoes parametric testing on a precision 6-DOF (degree of freedom) motion platform. The key insight: we're not just measuring current offsets—we're characterizing the transfer function of each sensor axis, including:
- Full 3×3 scale and cross-axis compensation matrices (not just diagonal scale factors)
- Temperature-dependent polynomial coefficients for gyroscope bias (measured at -10°C, 25°C, 45°C, 60°C)
- Magnetometer ellipsoid parameters (center offset and radii) in a controlled low-EMI environment
- Sensor timing calibration (accounting for group delay differences between accelerometer, gyroscope, and magnetometer sampling)
This comprehensive characterization captures 70-80% of systematic errors and establishes a device-specific baseline stored in the W25Q512JV flash's protected calibration sector.
2. Field Calibration: Installation and Environmental Adaptation
Factory calibration occurs in a controlled environment, but field deployment introduces new error sources:
- Mounting stress: The PCB flexes slightly when mounted in the collar enclosure, introducing mechanical strain on the MEMS die that shifts accelerometer bias by 20-40mg
- Local magnetic anomalies: Earth's magnetic field varies by location, and ferrous objects in the pet's environment (collar buckles, ID tags, magnetic latches) create local distortions
- Installation-specific hard-iron: The exact positioning of battery, antenna, and PCB creates unique magnetic signatures for each assembly
Field calibration adapts the factory baseline to these installation-specific factors through automated data collection during normal device usage.
3. Runtime Correction: Adaptive Drift Compensation
Even with excellent static calibration, sensors drift during operation due to:
- Temperature cycling (thermal hysteresis in MEMS structures)
- Component aging (stress relaxation in suspension springs)
- Temporal electromagnetic interference (Wi-Fi/LoRa transmission bursts)
Runtime algorithms continuously monitor sensor consistency, detect anomalies, and apply dynamic corrections without requiring user intervention. This layer is where the most sophisticated engineering happens—balancing computational cost, power consumption, and correction accuracy in a resource-constrained embedded system.
Process: Implementation Deep Dive
Factory Calibration: Beyond Simple Offset Correction
The naive approach to accelerometer calibration measures each axis pointing up and down relative to gravity, computing a simple offset and scale factor.
Instead, we perform 12-position testing that fully characterizes the 3×3 transformation matrix:
// Full 3×3 calibration matrix approach
typedef struct {
float scale_matrix[3][3]; // Accounts for scale + cross-axis
float offset[3]; // Zero-g bias
float noise_floor[3]; // Per-axis noise characterization
} accel_calibration_t;
// Apply calibration transformation
void calibrate_accel(float raw[3], float calibrated[3],
const accel_calibration_t *cal) {
// Remove offset
float temp[3];
for (int i = 0; i < 3; i++) {
temp[i] = raw[i] - cal->offset[i];
}
// Apply scale and cross-axis correction matrix
for (int i = 0; i < 3; i++) {
calibrated[i] = 0;
for (int j = 0; j < 3; j++) {
calibrated[i] += cal->scale_matrix[i][j] * temp[j];
}
}
}
This matrix-based approach corrects not just scale factors but also the 1-3% cross-axis sensitivity that simple calibration ignores. The result: accelerometer orthogonality error drops from 2-3° to <0.5°.
For gyroscope temperature compensation, we've implemented a second-order polynomial model rather than simple linear correction:
Bias(T) = b₀ + b₁·ΔT + b₂·ΔT²

Field Calibration: Exploiting Natural Pet Behavior
The engineering challenge with pet trackers is that we cannot ask users to precisely orient the device. Instead, we've designed algorithms that opportunistically collect calibration data during normal usage:
Magnetometer Ellipsoid Fitting: This is where the engineering gets particularly interesting. Hard-iron and soft-iron distortions transform the ideal sphere of magnetic field measurements into an ellipsoid offset from the origin. We collect magnetometer samples during periods of active motion (when gyroscope magnitude exceeds 10°/s) to ensure diverse orientations.
The algorithm fits a 3D ellipsoid to this point cloud:
(x-x₀)²/a² + (y-y₀)²/b² + (z-z₀)²/c² = 1
The center (x₀, y₀, z₀) represents hard-iron offset; the radii ratios (a:b:c) characterize soft-iron distortion. We've implemented a recursive least-squares approach that updates the ellipsoid parameters with each new sample, converging to <5% error after 200-300 samples (approximately 10 minutes of normal pet activity).
Runtime Correction: Complementary Filter Design
This is where the 9-axis architecture truly shines. Each sensor type has complementary strengths and weaknesses:
| Sensor | Strength | Weakness | Bandwidth |
|---|---|---|---|
| Gyroscope | High-frequency accuracy | Low-frequency drift | Fast (100Hz) |
| Accelerometer | Gravity reference | Motion noise | Slow (filter to ~1Hz) |
| Magnetometer | Absolute heading | EMI sensitivity | Slow (filter to ~1Hz) |
| GPS | Absolute position/heading | Latency, dropouts | Very slow (1Hz) |
We implement a complementary filter that fuses these sources with frequency-dependent weighting:
// Simplified complementary filter core
void update_orientation(float dt) {
const float ALPHA = 0.98f; // Trust high-freq gyro, low-freq accel/mag
// High-pass: integrate gyroscope (fast dynamics)
orientation[ROLL] += gyro[X] * dt;
orientation[PITCH] += gyro[Y] * dt;
orientation[YAW] += gyro[Z] * dt;
// Low-pass: gravity reference from accelerometer
float accel_roll = atan2f(accel[Y], accel[Z]);
float accel_pitch = atan2f(-accel[X],
sqrtf(accel[Y]*accel[Y] + accel[Z]*accel[Z]));
// Fuse with complementary weights
orientation[ROLL] = ALPHA * orientation[ROLL] + (1-ALPHA) * accel_roll;
orientation[PITCH] = ALPHA * orientation[PITCH] + (1-ALPHA) * accel_pitch;
// Magnetometer provides absolute yaw (heading)
if (mag_valid && gps_speed < 0.5) { // Only trust mag when stationary
float mag_yaw = calculate_tilt_compensated_heading();
orientation[YAW] = ALPHA * orientation[YAW] + (1-ALPHA) * mag_yaw;
} else if (gps_valid && gps_speed > 2.0) { // Use GPS heading when moving
orientation[YAW] = ALPHA * orientation[YAW] + (1-ALPHA) * gps_heading;
}
}
The key engineering detail: the complementary filter coefficient (α = 0.98) determines the crossover frequency. At 100Hz sample rate, this yields ~0.3Hz crossover—meaning the gyroscope dominates above 0.3Hz (fast motions), while accelerometer and magnetometer dominate below 0.3Hz (slow drifts).

Key Takeaways for Engineering Teams
1. Calibration is a control systems problem, not a one-time measurement: Effective IMU calibration requires feedback loops operating at multiple time scales—fast runtime correction (10-100Hz), medium-term environmental adaptation (hours to days), and slow predictive maintenance (weeks to months). Design your architecture to support all three layers from day one.
2. MEMS sensors exhibit non-ideal behaviour that simple calibration misses: Cross-axis sensitivity, nonlinearity, and temperature hysteresis are real effects that compound in production. Budget engineering time for full matrix characterization and polynomial temperature models—the 15% accuracy improvement is worth the extra complexity.
3. Electromagnetic compatibility is critical in integrated IoT devices: When your IMU shares a PCB with multiple radios, EMI mitigation must be baked into both hardware layout and firmware algorithms. Temporal blanking and outlier rejection aren't optional—they're essential for reliable magnetometer operation.
4. Sensor fusion transforms noisy measurements into reliable information: No single sensor maintains accuracy across all conditions. Complementary filtering with adaptive coefficients enables you to extract the best performance from each sensor while rejecting their individual failure modes. The mathematics is straightforward; the engineering lies in tuning crossover frequencies for your specific application.
5. Fleet-level analytics enable predictive quality: Traditional embedded systems operate in isolation. Modern IoT devices can leverage cloud analytics to detect degradation patterns, correlate failures across batches, and trigger proactive interventions. This transforms calibration from reactive troubleshooting into predictive maintenance—reducing support costs while improving user experience.
6. Design calibration UX for your actual users: Engineers instinctively design complex multi-step calibration procedures. Real users won't complete them. Invest in automatic background calibration that leverages natural device usage.
At Hoomanely, we're building intelligent monitoring solutions that enhance pet safety, health, and well-being. The tracker represents our engineering philosophy: sophisticated technology should work invisibly, reliably, and continuously without demanding user attention.
The calibration architecture described here ensures trackers maintain exceptional accuracy throughout their lifecycle—whether detecting subtle gait changes that indicate joint problems, distinguishing normal activity from distress behaviors, or providing reliable location tracking during critical moments. This technical foundation allows us to focus on what truly matters: translating raw sensor streams into meaningful health insights and safety features that strengthen the bond between pets and their families.
I hope this deep-dive provides practical value for your own IMU projects. The field is evolving rapidly—what seemed impossibly complex five years ago is now table stakes for consumer IoT. Let's keep pushing the boundaries of what's possible in resource-constrained embedded systems.