I am trying to use a multilayer perceptron to make a flight controller for a ROV. I have a MPU-9250 IMU and I need to remove the noise from the sensor before I can train my MLP. The IMU has a accelerometer, gyro and a magnetometer. I know my state vector is supposed to be

[acc_x, Acc_y, Acc_z, gyro_x, gyro_y, gyro_z, mag_x, magy, mag_z]

I am not sure about the rest. Since I want the clean Acc, gyro and mag's x, y and z values can I just use an identity matrix for everything in EKF?

I want to pass the IMU data to the MLP after cleaning it and try to predict the control signal for all my thrusters. For my dataset I recoded the IMU information from a ROV2 and I also recorded the pwm signals for each thruster. If it does work I won't be able to control things like PID values of the thrusters but for now I don't really care about it.

  • $\begingroup$ Could you please be more specific with what you're trying to do? You want to use a neural network to do what, exactly? What would the inputs and outputs be? The problem with IMU data generally isn't noise but sensor bias and especially bias drift. You could of course record data and then filter it to remove noise (like the Matlab function filtfilt), but then you're left training a neural network with unrealistic (unobtainable) data. Did you want to use the NN to get from raw IMU output to a pose estimate or are you trying to use the NN to get from a reference error to a control signal? $\endgroup$
    – Chuck
    Jun 16, 2017 at 19:46
  • $\begingroup$ Why do you decide to use EKF? UKF is looks like easy to implement and it's performance usually is better than EKF. $\endgroup$
    – Gluttton
    Jun 17, 2017 at 20:04
  • $\begingroup$ From what I understand about Kalman Filters EKF is better over KF cause it can handle non gaussian distributions and UKF is better when the data is very non linear.So, I thought about using a UKF but then I say that Ardupilot is using a EKF and I figured an EKF is better suited for the problem. $\endgroup$
    – ItsKalvik
    Jun 17, 2017 at 20:09
  • $\begingroup$ @Chuck About the drift I read that by using sensor fusion with a 9dof IMU we can get stable values from an IMU for long periods. So I figured the bias wouldn't be a big issue. $\endgroup$
    – ItsKalvik
    Jun 18, 2017 at 2:26

2 Answers 2


There are a couple of potential traps with the scenario you seem to be outlining. Many of them have already been addressed in literature on inertial navigation. You can find many good references on inertial navigation and dead reckoning using IMUs, and you may want to look into that, depending on your goals.

What you are asking for is a method to clean up your raw IMU data using an EKF. This is a bit of a strange request, because the EKF is generally designed for dynamic systems. In our context, it's sufficient to say that dynamic systems are driven by some known process in between measurements; for instance, if you were estimating position and velocity, there is a known relationship (derivative) that describes how the velocity affects position in between measurements from, e.g., a GPS receiver. You have not mentioned any other measurements, like GPS, that you want to use in the filter. If you don't have any other measurements available, then an EKF is not going to buy you anything in practice, and is probably much more challenging to set up.

If all you want is filtered accelerometer, gyroscope, and magnetometer data, then I would suggest designing a low-pass filter to smooth those data instead. You would also want to make sure to calibrate the bias of the accelerometer and gyros by reading the first N measurements, and then subtracting the average of those values from all subsequent measurements. Depending on your application and the motion of your vehicle, you might have usable data for as many as several minutes. I'm making some fairly wild guesses about your IMU bias drift rates, since I'm not familiar with the MPU-9250. In general, I would not trust a MEMS IMU output for too long, since there will always be bias drift. There are ways to address this limitation: you could augment the IMU with additional sensors, or you could re-calibrate periodically by stopping the vehicle and taking measurements. Unfortunately, the latter approach is only really very realistic if you have a ground vehicle moving over fairly level terrain.

It's not clear if your application is for a flying vehicle or for an underwater one, nor is it clear what your desired inputs and outputs for an ANN-based controller are. For instance, if all you are giving the controller is IMU data, what will be its objectives? It sounds like what you may want to do is perform inertial navigation. Assuming you have an underwater vehicle, you will mostly likely want to perform dead reckoning. Essentially, dead reckoning integrates the accelerometer histories twice to estimate the position of the vehicle, and the gyro histories once to estimate its orientation. If you have estimates of the position, then you could give your controller simple commands, such as "go to position X = 5 m" and then have the controller try to do that. (You can do the same thing with accelerations, of course, but I'm not sure what the point would be, since the vehicle won't be capable of even basic autonomy.)


When I was writing my own flight for quad-copter, this article helped me a lot and I think it could help: Arduino code for IMU Guide algorithm. Using a 5DOF IMU (accelerometer and gyroscope combo):

This article introduces an implementation of a simplified filtering algorithm that was inspired by Kalman filter. The Arduino code is tested using a 5DOF IMU unit from GadgetGangster – Acc_Gyro. The theory behind this algorithm was first introduced in my Imu Guide article.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.