Skip to content

Filter design

This report details how the filter design of the level sensor was designed.

Executive Summary

A 10 Hz sampling frequency combined with a SMA filter (N=20) will significantly improve the relability of the measured values, with an acceptable trade-off in increased current consumtion and slower step response.

1. Introduction

1.1 Purpose and Scope

The purpose of this report is to determine how to best filter the depth sensor in order to achieve best accuracy with reasonable response time.

It does not do a full characterization of the sensor or aims to find the best solution. It only looks to find a working solution.

1.2 Background

The initial approach to filtering was to use a sigma clipping filter. It works by taking a series of measurements and, for outlier robustness, computes the standard deviation ("sigma") and rejects values outside a limit. It then computes the mean of the remaining values.

This was found to be unsatisfactory. (Issue #10)

1.3 Objectives

The report aims to identify why the initial approach was not effective enough, and how it can be improved.

1.4 References

2. Methodology

A static signal was captured from the probe (after the current-to-voltage converter). A step response was faked by artifically adding a constant value to the latter half of the measurement.

Various sampling and filtering designs were then evaluted:

  • 2 MHz sample rate (default from oscilloscope)
  • 1 kHz sample rate
  • 1 kHz sample rate w/ averaging filter (N=20)
  • 1 kHz sample rate w/ FIR filter
  • 10 Hz sample rate
  • 10 Hz sample rate w/ averaging filter (N=20)

The FIR filter coefficients were chosen as a low-pass filter with a gain of 1 for <100Hz and a gain of 0 for >200Hz. The coefficients are available in the processing code.

For each design the min, mean, max and standard deviation was computed.

For some promising designs, they were plotted against the original signal. (2Mhz)

3. Results

The statistics for the designs are presented in the table below. (Sorted by standard deviation)

Signal min mean max stddev
10Hz SMA (N=20) 103.125 298.78 495.833 158.84
10Hz 0 298.264 545.833 196.024
1kHz FIR 9.43545 289.745 559.916 196.133
1kHz SMA (N=20) 33.3333 299.916 564.583 202.026
1kHz -62.5 299.965 650 204.481
2MHz -375 302.404 941.667 204.511

The frequency plot and simulated step response is presented in the figure below.

Simulated step response for three different filter/sampling designs

4. Discussion

There is a lot of low-frequncy noise (<100 Hz) that affects the stability of readings. This prompts a slower sampling frequency to suppress the noise.

A sampling frequency of 10 Hz with an SMA filter with N=20 drastically improves the signal quality with much reduced noise.

It has two drawbacks:

  • The current consumption will increase as sampling takes longer
  • The step response is longer (2 s, compared to <300 ms)

The step response is still sufficient for the given environment, where much slower changes are expected and sampling interval is much slower.1

The sensor draws a maximum of 20 mA @ 5000 mm.2 Assuming a 1 hour sampling interval, then reducing the sampling frequency from 1kHz to 10 kHz with an SMA filter, will result in <0.3 mAh more current consumption, per day. It is very likely that the design will handle this.


Author: Oscar Aurin | Date: 2025-08-09 | Revision: A


  1. The sensor level will be reported every hour or so, so when sampling at 10 Hz, it is only for the needed samples for averaging. 

  2. In practice the maximum drawn current will be much less, as it is proportional to depth and its only expected to measure <2 m.