iTranslated by AI
Using a Median Filter to Handle Outliers in Load Cell Readings
Overview
This is a story about how I struggled with an unusually large value appearing for just a single frame while trying to capture the peak pressure using a load cell and HX711 with Arduino.
Original Implementation (Moving Average Filter)
I was processing the values from the load cell using a low-pass filter with a simple moving average without thinking much about it.
Revised Implementation (Median Filter)
I referred to the following site:
Moving averages seem good for removing fine fluctuations (high frequency), but they don't seem suitable for rejecting outliers.
Based on the following description, I decided to try using a median filter:
The Hampel filter does not smooth the data much.
It feels like it only removes spikes.
There is a similar filter called the median filter, but this one smooths the data slightly more.
I found a library, so I used it:
It is written in French, but
you can load the library with #include "MedianFilterLib.h",
set the number of samples with MedianFilter<int> medianFilter(5);,
and the result is returned by calling int median = medianFilter.AddValue(rawMeasure);.
It seems to work the same way for decimal values as well.
When I actually used it, even when an outlier occurred in the Raw data, it didn't seem to affect the Med value.


Discussion