Looking at the data, you do not want any peeks that change the value by a certain amount (around 200, let us call this max_y_delta
) in a certain time (5-15 perhaps, max_x_delta
).
So as I'm not sure which structure your data has, I'll just assume it's 3 arrays data_array
of floating point values that have a data point at every integer position. The solution I present is meant to be as simple as possible and you should try different values of max_x/y_delta
to get good results. Even with the right values I'm sure there are much better solutions, but perhaps this one is good enough for you as a start.
max_x_delta = 10
max_y_delta = 200
for each of the 3 arrays
for x = -1000...1000
points_above_delta = 0
average_value = 0
for deltax = -max_x_delta/2...max_x_delta/2
average_value += data_array[deltax]
if abs(data_array[deltax] - data_array[x]) > max_y_delta
points_above_delta++
endif
end for deltax
average_value = average_value / max_x_delta
if points_above_delta > max_x_delta/4
for deltax = -max_x_delta/2...max_x_delta/2
data_array[deltax] = average_value
end for deltax
end if
end for x
Note that this code has two downsides you might not want:
- The detection is very simple, there
are also some peeks in your data that
are meant to be there, so you might
lose some of those.
- After detecting a peak, every value in the
max_x_delta
region around the peak is set to the average value in that region which will give you a straight line.