1

I have a sonar sensor reading water level by measuring distance to the water's surface and sending back as a floating point number.

It takes single measurement at fixed intervals and sends them right after.

but every once in a while , due to environmental factors, there is a spike in the reading which does not match the physical quantity its measuring.

expected: 100 105 95 97 103 101 100 98 99 103 ... n (values hovering around 100)

received: 100 105 250 95 97 102 101 20 105 98 ... n (250 and 20 are spikes)

the value 205 and 20 is false because by design it is not possible for the water level to change that fast.

What method should I use to ignore these large changes ? I can decrease the sampling interval to get more samples to compare against and correct before reporting, but how do I do it mathematically?

Averaging doesn't work because the spike will drag the value towards it.

Allahjane
  • 127

1 Answers1

1

Hint:

Your sequence of ${y_k}$ values is a discrete time signal.
The removal of spikes, i.e. of high frequency noise component, is the purpose of filters.

The choice of a suitable filter is an engineering task: a compromise between removing noise while keeping the information of interest.
As such, it much depends on knowing the stochastic characteristics of noise and of the signal of interest.

In the problem you posed, you do not say much about this.
It seems to understand that spikes occur quite "isolately" and have amplitude much higher than the base signal "fluctuations".
In this situation, a simple low-pass filter shall do: it is up to you to choose type and parameters.

G Cab
  • 35,272