I have found a lot of resources describing the theory and general alorithm for an (extended) Kalman filter but I find it hard to translate to the use case of GPS smoothing in a mobile app, which is what I want to do. I even found this library which seems promising but I am not sure how to insert my variables into that.
I have longitude, latitude, altitude (not sure that I need that) and speed from the gps. And also the INS input (accelerometer, gyroscope, magnetometer) to work with.
How do I use all there inputs with the library?
I have these inputs available in Expo:
import {
Accelerometer,
Gyroscope,
Magnetometer,
} from 'expo-sensors';
From these I can get x,y,z-values every 200ms for instance. I also have expo-location which gives me latitude, longitude, speed and timestamp every 1 second.
So I have all these variables and I want to use all of them to improve the performance of the gps when recording the path of a pedestrian who is out walking. The purpose is to paint the path onto a map as accurate as possible.
The result from the extended kalman filter should be improved gps latitude and longitude.
I understand that I can initiate a kalman filter using the library like this to make it behave as an extended kalman filter:
const kFilter = new KalmanFilter({
observation: {
dimension: x,
stateProjection: (opts) => {
return [];
},
covariance: (opts) => {
return [];
},
},
dynamic: {
dimension: y,
transition: (opts) => {
return [];
},
covariance: (opts) => {
return [];
},
},
});
Each return should return a matrix. I think that I should use all my given variables in a matrix which should be something like
[ accelerometer x, accelerometer y, accelerometer z, gyro x, gyro y, gyro z, magnetometer x, magnetometer y, magnetometer z, latitude, longitude, speed ]
Something like this is my stateProjection right? Not sure about the others. What am I missing to connect my inputs with the properties of this library?
(This wouldn't fit as a comment, so posting as an answer)
Just for some context: what you are trying to do is really hard. I regularly see research papers about it, and big companies pay their engineers a lot of money to get systems like this working. INS inputs are challenging because of the biases inherent in those types of sensors. In addition to having states in your Kalman Filter for corrected GPS position, you will also need states for accelerometer bias, gyroscope bias, and magnetometer bias (often 3+ states for each, if the sensors measure along multiple axes). Often when an INS is available, the typical dynamics update step of the Kalman Filter is replaced by the output of the INS, and the position states of the kalman filter are the errors in the INS estimate. You may be able to get that working with the library you referenced, but it will be challenging.
If you do want to use the library, it looks like much of your customization will be in kf-options.js
. If you do model-replacement as I discussed in the previous paragraph, your measurements would just be the GPS measurement. You will have to think about which coordinate system you are using. It sounds like you are wanting to use a local cartesian coordinate system; you will need the origin of that coordinate system in latitude/longitude/altitude in order to translate the GPS measurements into that frame.
I could keep going, but my point is that this is a challenging problem. I don't think that anyone will be able to give you an answer in this format, because the answer would probably be hundreds of lines of code with many inputs from you about how exactly you want to do things.