# Capture legitimate huge increase/drop in fuel level from noisy measurements

I have a fuel sensor installed in a lorry fuel tank. The sensor measures the current fuel level (in percentage) of the tank. However, due to the fact that the fuel is sloshing in the tank, the fuel level fluctuates wildly — sometimes more than 10%.

I decided to use Kalman filter to predict the actual fuel level, using the following model:

F(k+1) = F(k) - C
C = fuel consumed between k and k+1, which is estimated using
the distance travelled between k and k+1 (measured using GPS),
and the average fuel efficiency (fixed) of the lorry (e.g. 35 L/100km).


So far, Kalman filter works perfectly when the lorry is moving and consuming its fuel. However, it fails when 2 events happened that are not captured by the model:

• refuel (large increase in fuel level in a short span of time)
• fuel theft (large decrease in fuel level in a short span of time)

You can see an example below, on the left side of the graph, where a huge drop in fuel level (most probably due to fuel theft) and a huge increase in fuel level (due to refuel) are smoothed out by Kalman filter, thus the information are lost. On the right side of the graph, where the lorry is moving and consuming fuel, the prediction works well.

So my question is, how do I smooth the fluctuations of the fuel level, and at the same time, capture refuel and fuel theft events? Any ideas? Maybe use something else other than Kalman filter?

• Nice thought to use a Kalman. I was impressed by how fuel-theft was accepted as an eventuality. – A_A Sep 3 '17 at 20:58
• I too. Nice motivation to go beyond or remodel Kalman filter for your application! – Neeks Sep 3 '17 at 21:40
• Hasyimi Bahrudin, I have the same business problem. Can you explain your solution or show the implementation of the algorithm? How did you calculate F(X)? – Whoiam Jan 31 at 21:40
• maybe look into median filtering. – robert bristow-johnson Feb 1 at 3:18