https://github.com/michal34512/magnetometer-calibration
magnetometer calibration algorithm with light weight linear algebra library
https://github.com/michal34512/magnetometer-calibration
accelerometer calibraition eigen ellipsoid-fit imu least-squares light linear-algebra magnetometer
Last synced: about 1 year ago
JSON representation
magnetometer calibration algorithm with light weight linear algebra library
- Host: GitHub
- URL: https://github.com/michal34512/magnetometer-calibration
- Owner: michal34512
- License: mit
- Created: 2024-06-28T21:48:02.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-20T15:21:42.000Z (almost 2 years ago)
- Last Synced: 2025-03-24T23:41:27.605Z (about 1 year ago)
- Topics: accelerometer, calibraition, eigen, ellipsoid-fit, imu, least-squares, light, linear-algebra, magnetometer
- Language: C
- Homepage:
- Size: 43.9 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Magnetometer calibration
Magnetometer calibration algorithm using ellipsoid fit and least squares method with light weight linear algebra library. Unlike similar algorithms, it does not require external linear-algebra library thus it's perfect for:
- ESP32
- Arduino
- Lightweight applications
Visualization (graphs not included in the code)
# How to use
```c
// data arrays
double x[231] = {18.923634, 20.785405, 23.265396, ...};
double y[231] = {94.943907, 103.939205, 113.472091, ...};
double z[231] = {27.951207, 32.958822, 31.772349, ...};
// Create vector based on data arrays
Vector vx = vec_from_array(x, 231);
Vector vy = vec_from_array(y, 231);
Vector vz = vec_from_array(z, 231);
// Fit best ellipsoid to the data and save offest vector, translation matrix
Callibration_t calib = calib_calibrate_sensor(vx, vy, vz);
// Print the result
vec_print(calib.offset);
mat_print(calib.transform);
// Compensate new data point based on calib
// new data = calib.transform*(old data - calib.offset)
Vector new_data_vector = vec_new(3);
VEC_X(new_data_vector) = 18.923634;
VEC_Y(new_data_vector) = 94.943907;
VEC_Z(new_data_vector) = 27.951207;
calib_calibrate_point(calib, new_data_vector);
// Print calibrated vector
vec_print(new_data_vector);
```
# Algorithm perfomance
Average variance of points length in relation to calibration data noise (random mag. 100 data points):

Average chance of algorithm failure in relation to data point count (random mag. data with 10% noise):

Example of data calibration with 50% noise:
