Skip to main content
BMC Research Notes logoLink to BMC Research Notes
. 2026 Oct 1;19:370. doi: 10.1186/s13104-026-08032-w

Research note on gravity artifact reduction in IMU signals using Madgwick orientation estimation

Moritz Toppmöller 1, Urs-Vito Albrecht 1,✉
PMCID: PMC13632254  PMID: 42823703

Abstract

Objective

Gravitational artifacts bias Inertial Measurement Unit (IMU) signals, complicating applications such as Seismocardiography (SCG). This study aimed to validate a gravity-artifact reduction algorithm using Madgwick orientation estimation in a controlled, physics-based simulation.

Results

A computational phantom was developed using the PyBullet physics engine to generate paired datasets of gravity-free acceleration and simulated IMU signals (with gravitational artifacts). The Madgwick Attitude and Heading Reference System (AHRS) filter was applied to estimate the sensor orientation, followed by a low-pass-filtered gravity projection to subtract artifacts. The gravity-removed acceleration closely matched the gravity-free reference across all axes. Absolute mean differences were consistently below 0.006 m/s2, and Pearson correlation coefficients exceeded 0.98. Cross-correlation analysis revealed zero temporal lag, while Bland-Altman analysis showed no proportional bias. The highest precision was observed along the gravitational z-axis. These simulation-only results represent an upper bound under idealized conditions. Experimental validation remains necessary before practical deployment.

Keywords: Orientation, Gravity, Madgwick, IMU

Introduction

Modern Ballistocardiography (BCG) and Seismocardiography (SCG) rely on Inertial Measurement Units (IMUs) to capture subtle physiological movements. However, accelerometers measure both translational acceleration and a gravitational component. Sensor rotations change their projection onto the individual axes, creating orientation-dependent artifacts that can bias signal interpretation [1].

Accurate orientation estimation helps separate these components. Complementary filters are simple, whereas Extended Kalman Filter (EKF)-based methods require more computational effort and noise-covariance tuning [2, 3]. Direct quaternion integration of gyroscope measurements can suffer from drift without corrective fusion [3, 4]. A prior robotic-arm validation supported the Madgwick filter [5] for its accuracy and computational efficiency, motivating its use for gravity removal [6].

Beyond orientation estimation, accelerometer-only filtering or norm subtraction can separate gravity without gyroscope measurements, but loses accuracy under continuous reorientation [7]. Combined accelerometer–gyroscope approaches estimate orientation and project gravity accordingly, with applications in cardiac motion measurement [8] and smartphone seismocardiography [9]. However, validation through physiological endpoints makes it difficult to establish the accuracy of gravity removal itself.

Obtaining a gravity-free reference from physical IMU measurements remains challenging [4]. To address this, the present study uses a physics-based computational phantom to evaluate the accuracy, temporal alignment, and agreement of the Madgwick-based gravity-removal pipeline [6] against simulated gravity-free acceleration.

Methods

Simulation framework

PyBullet [10], a physics engine used in robotics [11], was used to record synchronized angular and linear velocities. The simulation ran in direct mode without Graphical User Interface (GUI) visualization.

Simulation parameters

The simulation ran for 30 s at 1000 Hz, matching sampling rates used in SCG applications [1, 12]. Earth gravity was 9.81 m/s2 in the negative world-frame z-direction. A cubic IMU mounting object (0.25 m, 0.25 kg) was dropped onto deformable cloth suspended at its corners between two anchor boxes (Fig. 1). Random external forces were applied to one anchor box during alternating 1 s forcing and resting intervals. This scenario combines non-periodic, multi-axis translation with continuous reorientation, testing gravity removal when both translational acceleration and gravitational projection vary. Scenario selection was constrained by the need to generate physically plausible motion within the physics engine’s numerical limits. The deformable suspension was chosen to provide compliant contact while reducing the risk of numerical artifacts. Peak translational acceleration during analysis was approximately 1.34 m/s2. The scenario was not designed to reproduce a specific physiological waveform.

Fig. 1.

Fig. 1

Simulation environment. The left panel shows deformable cloth suspended between two anchor boxes, with the cubic IMU mounting object resting on it and the world coordinate frame shown for reference (x = red, y = green, z = blue). The right panel shows a close-up of the mounting object on the cloth

Sensor modeling

A TDK InvenSense ICM-42688-P [13] IMU was modeled with the following specifications:

  • Accelerometer range:  ± 2 g ( ± 19.62 m/s2)

  • Accelerometer resolution: 16384 LSB/g

  • Gyroscope range:  ± 31.25∘/s

  • Gyroscope resolution: 1048.6 LSB/(∘/s)

Raw values were quantized and clipped to the measurable range. No stochastic noise, bias instability, temperature effects, or long-term drift were modeled (see Limitations).

Signal generation

Linear acceleration was derived from world-frame velocity (aworld = Δv/Δt). The simulated accelerometer signal is obtained by adding gravitational force to the linear acceleration. Since gravity acts in the negative world-frame z-direction, this adds a positive force in the z-direction. The body-to-world rotation matrix R gives

graphic file with name d33e304.gif 1
graphic file with name d33e308.gif 2

Additionally, the angular velocity was saved.

Gravity removal

The Madgwick Attitude and Heading Reference System (AHRS) filter estimates orientation as q = [w, x, y, z]T, initialized to q0 = [1, 0, 0, 0]T. Orientation is propagated using angular velocity ω (rad/s) and corrected using normalized acceleration a. The gyroscope-derived quaternion rate is

graphic file with name d33e352.gif 3

where  ⊗ denotes quaternion multiplication. Gradient descent aligns predicted and measured gravity directions. The gradient of f(q, a) = q* ⊗ ez ⊗ q − a is  ∇ f = JTf, where J is the Jacobian and q* the conjugate quaternion. The combined rate is

graphic file with name d33e402.gif 4

where β weights the gradient-descent correction relative to gyroscope integration. The filter was used with β = 0.05 at 1000 Hz. Orientation is updated by integration and renormalization as

graphic file with name d33e414.gif 5

The quaternion defines R. The gravitational impact factor fimpact is the projection of the positive world-frame z-axis unit vector ez into the body frame,

graphic file with name d33e448.gif 6

The gravity magnitude is estimated from the world-frame vertical acceleration as

graphic file with name d33e453.gif 7

A 4th-order Butterworth low-pass filter (cutoff 0.5 Hz, zero-phase forward-backward filtering) isolated the quasi-static gravitational component (gfiltered). The gain β = 0.05 was adopted from prior validation [6]. Smaller β reduces sensitivity to translational acceleration but slows convergence and weakens correction of gyroscope-induced tilt errors. Larger β accelerates correction but increases sensitivity to accelerometer disturbances [5]. The 0.5 Hz cutoff suppresses dynamic contamination of the world-frame vertical acceleration. Lower cutoffs smooth this estimate more strongly. Higher cutoffs retain faster variations, allowing more translational acceleration to be mistaken for gravity and subtracted. Cutoff sensitivity is assessed in Sensitivity analysis. Gravity-removed acceleration is given by

graphic file with name d33e494.gif 8

Data processing

Orientation estimation started at 200 ms, after simulation initialization transients. Analysis used simulation times from 3 s onward to exclude filter convergence artifacts [14], leaving 27 s of data.

Validation

Agreement was assessed per axis using Python 3.14 with NumPy, Pandas, SciPy, and the AHRS library.

Error characterization

Mean difference, Standard Deviation (SD), median, and Interquartile Range (IQR) were evaluated. The Signal-to-Noise Ratio (SNR) is

graphic file with name d33e513.gif 9

where Psignal is the mean squared gravity-free acceleration and Perror is the mean squared difference between gravity-removed and gravity-free signals.

Agreement analysis

Pearson correlation coefficients quantify the linear relationship between gravity-free and gravity-removed signals as

graphic file with name d33e552.gif 10

where xi and yi are the gravity-free and gravity-removed samples with means Inline graphic and Inline graphic. The 95% Confidence Interval (CI) was computed using Fisher’s z-transformation as

graphic file with name d33e581.gif 11

where n is the number of samples. Cross-correlation and the corresponding lag were computed as

graphic file with name d33e589.gif 12

where Inline graphic is the lag at which the maximum cross-correlation occurs.

Bland-Altman analysis

The difference di = xi − yi (gravity-free minus gravity-removed) was computed per sample. Bias and SD of differences were calculated as

graphic file with name d33e620.gif 13

and the Limits of Agreement (LoA) were calculated as bias  ± 1.96 ⋅ SD. The percentage of points outside the LoA and Bland-Altman [15] plots assessed outliers and systematic bias.

Distribution analysis

Residual error histograms were used to assess distributional assumptions for the LoA.

Results

Signal visualization

Visual comparison (Fig. 2) showed that gravity removal eliminated the approximately 9.81 m/s2z-axis offset, and the gravity-removed signals closely followed the reference. Gyroscope signals were identical between datasets.

Fig. 2.

Fig. 2

Comparison of acceleration signals along the x-, y-, and z-axes during the analysis window. Each panel shows the gravity-free translational acceleration, the raw IMU signal (with gravitational artifacts), and the gravity-removed estimate

Residual errors (Fig. 3) were centered around zero with no systematic drift. Maximum absolute errors were approximately 0.064 m/s2 (x-axis), 0.095 m/s2 (y-axis), and 0.065 m/s2 (z-axis).

Fig. 3.

Fig. 3

Residual error (gravity-free minus gravity-removed acceleration) for each axis (x, y, z) over the analysis window

Error characterization

Mean differences ranged from 0.0025 to 0.0055 m/s2 (Table 1). The SD and IQR were smallest on the z-axis and largest on the y-axis. Medians were close to the means.

Table 1.

Accuracy metrics of the gravity removal algorithm for each body axis, including mean difference, SD, median, IQR, Pearson correlation with 95% CI, SNR, LoA, percentage of points outside the LoA, and cross-correlation lag between gravity-removed and gravity-free acceleration

Axis/Metric x y z
Mean Difference (m/s2) 0.0055 0.0030 0.0025
SD (m/s2) 0.0194 0.0266 0.0088
Median (m/s2) 0.0044 0.0039 0.0012
IQR (m/s2) 0.0274 0.0366 0.0060
Pearson Correlation (95% CI) 0.9809 [0.9804, 0.9813] 0.9876 [0.9873, 0.9879] 0.9979 [0.9979, 0.9980]
SNR (dB) 13.8570 16.0367 23.3816
LoA (m/s2) [ − 0.0325, 0.0436] [ − 0.0492, 0.0552] [ − 0.0148, 0.0197]
Outside LoA (%) 5.3815 4.9296 3.3037
Cross-Correlation Lag (ms) 0.0000 0.0000 0.0000

Agreement analysis

Pearson correlation coefficients ranged from 0.9809 (x-axis) to 0.9979 (z-axis), and SNR ranged from 13.86 to 23.38 dB (Table 1). Cross-correlation revealed zero lag for all axes.

Bland-Altman analysis

Bland-Altman [15] plots (Fig. 4) showed small biases and no evident proportional bias. Points outside the LoA comprised 5.38% (x), 4.93% (y), and 3.30% (z). A cluster of z-axis outliers occurred near zero mean acceleration.

Fig. 4.

Fig. 4

Bland-Altman plots comparing gravity-removed and gravity-free acceleration for each axis (x, y, z). The horizontal axis shows the mean of the two measurements. The vertical axis shows gravity-free minus gravity-removed acceleration. The dashed line indicates the mean difference (bias), and the dotted green lines indicate the upper and lower LoA

Distribution analysis

Residual error histograms (Fig. 5) were centered near zero, with wider distributions for the x- and y-axes and a narrower, more peaked distribution for the z-axis.

Fig. 5.

Fig. 5

Histogram of the residual errors (gravity-free minus gravity-removed acceleration) for each axis (x, y, z). The red dashed line indicates the mean difference. The green dotted lines indicate the upper and lower LoA

Sensitivity analysis

Butterworth cutoff sensitivity was evaluated at 0.1, 0.2, 0.5, 1.0, 2.0, 5.0 Hz with other parameters fixed (Table 2). The 0.5 Hz cutoff yielded a z-axis SNR of 23.38 dB, compared with 25.40 dB at 1.0 Hz and 4.35 dB at 0.2 Hz. Thus, 0.5 Hz performed well but was not optimal on every axis. At 2.0 Hz and 5.0 Hz, z-axis SNR decreased to 8.49 dB and 2.27 dB, respectively.

Table 2.

Gravity removal performance for six Butterworth cutoff frequencies, reported per body axis

Cutoff (Hz) Axis Mean Difference (m/s2) SD (m/s2) Pearson r SNR (dB)
0.10 x − 0.0050 0.0449 0.9046 6.86
0.10 y 0.0002 0.0269 0.9874 16.00
0.10 z 0.0549 0.1878 0.5849 − 3.24
0.20 x 0.0050 0.0248 0.9685 11.89
0.20 y 0.0026 0.0270 0.9873 15.93
0.20 z 0.0060 0.0815 0.8564 4.35
0.50 x 0.0055 0.0194 0.9809 13.86
0.50 y 0.0030 0.0266 0.9876 16.04
0.50 z 0.0025 0.0088 0.9979 23.38
1.00 x 0.0057 0.0193 0.9812 13.89
1.00 y 0.0031 0.0267 0.9876 16.02
1.00 z 0.0014 0.0071 0.9986 25.40
2.00 x 0.0055 0.0247 0.9688 11.88
2.00 y 0.0030 0.0266 0.9876 16.04
2.00 z 0.0023 0.0507 0.9289 8.49
5.00 x 0.0053 0.0356 0.9350 8.83
5.00 y 0.0030 0.0265 0.9878 16.08
5.00 z 0.0024 0.1038 0.6489 2.27

Discussion

The proposed approach, combining Madgwick orientation estimation with low-pass-filtered gravity projection, closely matched the gravity-free reference in this simulation. Residual SD was smallest on the z-axis, while cross-correlation showed zero lag across all axes. This temporal alignment is consistent with zero-phase forward-backward filtering (sosfiltfilt) and is relevant to SCG analysis [16].

The low-pass filter complements orientation estimation, as filtering alone cannot distinguish low-frequency translation from changing gravitational projections [7]. The Madgwick filter determines the projection, while the low-pass filter estimates gravity magnitude from the world-frame vertical component before projection into the body frame.

Since validation was performed entirely on simulated data, the reported performance represents an upper bound under idealized conditions. Potential applications in SCG, BCG, wearable monitoring, and robotics require experimental IMU validation before deployment. Complementary work in the ARTIFACTS study compares physical BCG measurements under normal gravity and weightlessness [1], providing a potential route to assess transferability. Future work could use alternative simulation frameworks to explore additional motion scenarios and incorporate realistic sensor error models.

Limitations

While quantization and clipping were modeled, stochastic noise, bias instability, temperature effects, and long-term drift were omitted. Gyroscope noise and bias would perturb quaternion propagation, whereas accelerometer noise and bias would corrupt the gravity-direction reference for orientation correction. The resulting orientation errors would distort the gravity projection, while vertical accelerometer bias would also shift the filtered gravity estimate, leaving residual artifacts. Temperature effects and long-term drift could introduce time-varying bias, further limiting transferability to physical measurements.

Only one motion scenario and the TDK InvenSense ICM-42688-P sensor model were evaluated, so generalizability to other motions or sensors was not assessed. Neither filter parameter was established as universally optimal: β was not varied, and cutoff sensitivity was evaluated only for this scenario. Sustained translation can affect orientation correction, while low-frequency vertical motion can contaminate the gravity estimate. Different motion conditions may therefore require retuning both parameters.

Filter convergence may limit short recordings, while performance during extended recordings remains untested. The non-causal, zero-phase filtering restricts this implementation to offline processing, as real-time use would require causal filtering and separate phase-delay evaluation.

Acknowledgements

The authors also wish to thank Ruben Kuhlmann for his constructive criticism andvaluable feedback, which helped improve this work.

Abbreviations

IMU

Inertial measurement unit

GUI

Graphical user interface

AHRS

Attitude and heading reference system

EKF

Extended kalman filter

SNR

Signal-to-noise ratio

IQR

Interquartile range

CI

Confidence interval

LoA

Limits of agreement

SD

Standard deviation

BCG

Ballistocardiography

SCG

Seismocardiography

Author contributions

Conceptualisation: M.T, U.-V.A; Data curation: M.T; Formal analysis: M.T.; Funding acquisition: U.-V.A.; Investigation: M.T.; Methodology: M.T.; Project administration: U.-V.A.; Resources: U.-V.A.; Software: M.T.; Supervision: U.-V.A.; Visualisation: M.T.; Writing - original draft: M.T.; Writing - review & editing: M.T., U.-V.A. All authors approved the final version of the manuscript for publication.

Funding

Institutional resources are used. The authors additionally acknowledge financial support for the publication costs by the Open Access Publication Fund of Bielefeld University and the German Research Foundation (DFG).

Data availability

The datasets generated and analyzed during the current study are available on Zenodounder the following https://doi.org/10.5281/zenodo.21189793 [12]. Additionally, the code is hosted in the following GitLab repository: https://gitlab.ub.unibielefeld.de/ag4-digitale-medizin/papers/2026 bmc-simulation.

Declarations

Ethics approval and consent to participate

Not applicable.

Consent for publication

Not applicable.

Competing interests

The authors declare no competing interests.

Footnotes

Publisher’s note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

References

  • 1.Albrecht UV, Mielitz A, Rahman KMA, Kulau U. Identifying gravity-related artifacts on ballistocardiography signals by comparing weightlessness and normal gravity recordings (ARTIFACTS): protocol for an observational study. JMIR Res Protoc. 2024;13(1):e63306 10.2196/63306 [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 2.Sabatini AM. Quaternion-based extended Kalman filter for determining orientation by inertial and magnetic sensing. IEEE Trans Biomed Eng. 2006;53(7):1346–56. 10.1109/TBME.2006.875664 [DOI] [PubMed] [Google Scholar]
  • 3.Valenti R, Dryanovski I, Xiao J. Keeping a good attitude: a quaternion-based orientation filter for IMUs and MARGs. Sensors. 2015;15(8):19302–30. 10.3390/s150819302 [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 4.Kok M, Hol JD, Schön TB. Using inertial sensors for position and orientation estimation. Found Trends Signal Process. 2017;11(1-2):1–153. 10.1561/2000000094 [DOI] [Google Scholar]
  • 5.Madgwick SOH, Harrison AJL, Vaidyanathan R. Estimation of IMU and MARG orientation using a gradient descent algorithm. In: 2011 IEEE International Conference on Rehabilitation Robotics. Zurich: IEEE; 2011. p. 1–7. Available from: http://ieeexplore.ieee.org/document/5975346/. [DOI] [PubMed]
  • 6.Toppmöller M, Albrecht UV. Robotic-Arm-Based Validation of Orientation Estimation Filters for Gravity Artifact Removal in 6DoF Sensors. In: Mantas J, Hasman A, Gallos P, Haux R, Karitis K, editors. Studies in Health Technology and Informatics. IOS Press; 2026. Available from: https://ebooks.iospress.nl/doi/10.3233/SHTI260827. [DOI] [PubMed]
  • 7.van Hees VT, Gorzelniak L, Dean León EC, Eder M, Pias M, Taherian S, et al. Separating movement and gravity components in an acceleration signal and implications for the assessment of human daily physical activity. PloS One. 2013;8(4):e61691 10.1371/journal.pone.0061691 [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 8.Krogh MR, Nghiem GM, Halvorsen PS, Elle OJ, Grymyr OJ, Hoff L, et al. Gravity compensation method for combined accelerometer and Gyro sensors used in cardiac motion measurements. Ann Biomed Eng. 2017;45(5):1292–304. 10.1007/s10439-017-1798-4 [DOI] [PubMed] [Google Scholar]
  • 9.Sieciński S, Kostka P. Heart beat detection from smartphone SCG signals: comparison with previous study on HR estimation. In: Tkacz E, Gzik M, Paszenda Z, Pietka E, editors. Innovations in Biomedical Engineering. vol. 925. Cham: Springer International Publishing; 2019. p. 123–130. Series Title: Advances in Intelligent Systems and Computing. Available from: http://link.springer.com/10.1007/978-3-030-15472-1_14.
  • 10.Coumans E, Bai Y. PyBullet, a Python module for physics simulation for games, robotics and machine learning. Available from: http://pybullet.org.
  • 11.Panerati J, Zheng H, Zhou S, Xu J, Prorok A, Schoellig AP. Learning to Fly—a Gym environment with PyBullet physics for reinforcement learning of multi-agent quadcopter control. In: 2021 IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS); 2021. p. 7512–7519. ISSN: 2153-0866. Available from: https://ieeexplore.ieee.org/document/9635857.
  • 12.Kulau U, Rust J, Szafranski D, Drobczyk M, Albrecht UV. A differential BCG sensor system for long term health monitoring experiment on the ISS. In: 2022 18th International Conference on Distributed Computing in Sensor Systems (DCOSS). Marina del Rey, Los Angeles, CA, USA: IEEE; 2022. p. 85–92.
  • 13.TDK. ICM-42688-P: Detailed Information ∣ Sensors and Sensor Systems - Motion / Inertial Sensors - IMU (Inertial Measurement Unit). Available from: https://product.tdk.com/en/search/sensor/mortion-inertial/imu/info?part_no=ICM-42688-P.
  • 14.Madgwick SOH.: AHRS algorithms and calibration solutions to facilitate new applications using low-cost MEMS. Available from: https://x-io.co.uk/downloads/madgwick-phd-thesis.pdf.
  • 15.Martin Bland J, Altman D. Statistical methods for assessing agreement between two methods of clinical measurement. Lancet. 1986;327(8476):307–10. 10.1016/S0140-6736(86)90837-8 [DOI] [PubMed] [Google Scholar]
  • 16.Kulau U, Rust J, Albrecht UV. Demo: BCG Measurement by differential Sensing in Real-Time. In: 2022 18th International Conference on Distributed Computing in Sensor Systems (DCOSS); 2022. p. 75–78. ISSN: 2325-2944. Available from: https://ieeexplore.ieee.org/document/9881775.
  • 17.Toppmöller M, Albrecht UV.: Research note on gravity artifact reduction in IMU signals using Madgwick orientation estimation. Department of Digital Medicine, Bielefeld University. ISSN: 1756-0500. Available from: https://zenodo.org/doi/10.5281/zenodo.21189792. [DOI] [PMC free article] [PubMed]

Associated Data

This section collects any data citations, data availability statements, or supplementary materials included in this article.

Data Availability Statement

The datasets generated and analyzed during the current study are available on Zenodounder the following https://doi.org/10.5281/zenodo.21189793 [12]. Additionally, the code is hosted in the following GitLab repository: https://gitlab.ub.unibielefeld.de/ag4-digitale-medizin/papers/2026 bmc-simulation.


Articles from BMC Research Notes are provided here courtesy of BMC

RESOURCES