Fuel Chart Smoothing Algorithm

I am developing a fleet management system, and one of the tasks is to show a graph reflecting the fuel consumption on the vehicle (based on data from CANBUS).

If the data value is between 0 and 100, this means a percentage. So, if I get an integer equal to 45, this means that the fuel in the tank is 45%.

However, if the car is moving, conflicting data may arise due to the physics of the ship. For example, a series of data might be:

76,76,75,74,73,73,71,70 <- this is a good model, because it shows how the fuel is reduced.

76,70,75,76,77,76,74,74,73,72,69,72,73,73,72,71 - this is not a good model due to fuel surges in the tank is not consistent, and the data which I receive are not suitable for display to the user.

I want to smooth out the values, but depending on how many values ​​I select on average at a time, the result is different.

The key problem is that sometimes there are drainage and refueling points that I MUST show on the graph and should not be smoothed out.

What algorithm can I use to analyze and present my chart in a convincing way for the user?

+6
source share
2 answers

Are there ways to determine when refueling / drainage occurs? If so, then you can change your algorithm dynamically at this time.

Otherwise, I would recommend using exponential smoothing.

Let d (0 <= d <1) be the weight coefficient for the previous number. So display_number = prev_data * d + new_data * (1-d)

With the correct weight, it would seem that the "bumpy" will be removed, but at the same time, the result will reflect fuel events.

This is not the only option, a more approximate algorithm, but I hope you find it useful.

A little editing: I did not understand that exponential smoothing has its own name. I just used the technique when displaying the frame rate in the games that I create. So thanks Camper.

+2
source

As I understand it, you want the small variations to disappear, but keep the big jumps without smoothing. Probably the driving median is what you are looking for, it saves big jumps without smoothing ( edge preservation .

I'm not sure if this is the best method for you, I will need to see your data.

+1
source

Source: https://habr.com/ru/post/947870/


All Articles