Skip to content
Back to skills

Imu Gravity Removal

ASecurity

Remove gravity component from raw accelerometer data using quaternion rotation to yield linear acceleration

  • 61 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 12, 2026
developmentpython

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill imu-gravity-removal --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Imu Gravity Removal?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Imu Gravity Removal
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-imu-gravity-removal/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-imu-gravity-removal)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: timeseries-imu-gravity-removal
description: Remove gravity component from raw accelerometer data using quaternion rotation to yield linear acceleration
domain: timeseries
---

# IMU Gravity Removal

## Overview

Raw accelerometer readings include gravitational acceleration (~9.81 m/s^2). Use the device's quaternion orientation to rotate the world-frame gravity vector into sensor frame, then subtract it. Essential preprocessing for any wearable/IMU activity recognition task.

## Quick Start

```python
import numpy as np
from scipy.spatial.transform import Rotation as R

def remove_gravity(acc_xyz, quaternions, g=9.81):
    """Remove gravity from accelerometer using quaternion orientation.
    
    Args:
        acc_xyz: (N, 3) raw accelerometer [x, y, z]
        quaternions: (N, 4) orientation [x, y, z, w]
    Returns:
        (N, 3) linear acceleration
    """
    gravity_world = np.array([0, 0, g])
    linear = np.zeros_like(acc_xyz)
    for i in range(len(acc_xyz)):
        rot = R.from_quat(quaternions[i])
        gravity_sensor = rot.apply(gravity_world, inverse=True)
        linear[i] = acc_xyz[i] - gravity_sensor
    return linear
```

## Key Decisions

- **Quaternion format**: scipy uses `[x, y, z, w]` — check your sensor's convention
- **inverse=True**: transforms world→sensor frame (not sensor→world)
- **Vectorized option**: `R.from_quat(all_quats).apply(gravity, inverse=True)` for speed

## References

- Source: [cmi25-imu-thm-tof-tf-blendingmodel-lb-82](https://www.kaggle.com/code/hideyukizushi/cmi25-imu-thm-tof-tf-blendingmodel-lb-82)
- Competition: CMI - Detect Behavior with Sensor Data

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…