# Determine automatically when measurement has reached a stable point

I am working on a scale project where the aim is to weight babys. The goal is that the scale will recognise when baby is on the scale and when the measurement has reached a stable value. So simplified the software works like this:

1. Device in stanby: scale reading is updated constantly. When an increase in slope is recognised, we jump to 2.

2. Measurement mode: scale reading is updated constantly. When the measurement settles, we want the scale to automatically tell that the measurement is over and to save the babys weight. Then we jump back to 1.

The problem is with the automatic recognition in step 2. A baby is never still so it will move on the scale and make the reading fluctuate all the time. How would you determine the correct weight? In comparison, a kitchen scale would be super easy compared to a baby. One liter of water will weight steady 1 kg so the recognition would be much easier.

I am now deciding the start and finish of the weight by storing the weight at time 0 ms and at time 0 + 100 ms. Then we can calculate the slope(for example reading is 4700g at time 0 and 5000g at time 100 ms -> slope is (5000 - 4700)/(100 - 0) = 3 g/ms. Then we say that a slope under 2 g/ms is considered stable)

Yeah, trick is indeed to define what you find stable. A limit on the slope would be one thing. But do you continuously do that? Or every 100ms? And what value do you take as valid? 4700g? 5000g? 4850g?

Other way is to use a low pass filter. You can combine that with a hysteresis. I think that will give you a better (more stable / repeatable) outcome.

septillion:
Yeah, trick is indeed to define what you find stable. A limit on the slope would be one thing. But do you continuously do that? Or every 100ms? And what value do you take as valid? 4700g? 5000g? 4850g?

The weight is updated at max speed to a moving average with about 5 values. Then at some point we take "time 0 ms" weight and after 100 ms we take "time 100 ms" and do the slope calulation. Then we wait 100 ms and take again time 0 and wait 100ms to take time 100... The scale reading is updating all the time in the background.

Every time slope is smaller than the predefined value, we add to a counter which is updated every second. If the slope has been small enough for 3 seconds, we say that the measurement is stable.

There is no specific valid weight. The scale range is from 0 - 20 kg and the detection should work through the whole range. A newborn weighs maybe 3000g and a bigger baby 10 kg.

septillion:
Other way is to use a low pass filter. You can combine that with a hysteresis. I think that will give you a better (more stable / repeatable) outcome.

Would you have some example of this?

What I meant by valid weight is the actual weight of the (non-moving) baby.

The running average is a crude kind of low pass filter. (My biggest argument for the term crude is the free running of the measurements aka not a fixed timing) But making more exact discrete low pass filters is a semester filling course on it's own.

But what exactly isn't working if you all have it thought out?

I tested the scale today for the first time with a real baby. The scale went crazy! It is showing correct weight but the stable value is jumping +-1 kg because of baby moving.

I need to do some changes to the code. A lot longer averaging time and a moving average with many values.

I will inform how it went.

A median filter works much better than moving averages or low pass filters, if there are large fluctuations.

Any vertical acceleration (such as starting to raise an arm) will result in a change in the apparent weight. However, the opposite acceleration must eventually occur as the movement stops, giving the opposite effect on apparent weight. The speeds may vary but when integrating over time, the weight shift will be zero.
The conclusion is; sample the scale often (in range 10-100 times/sec) and do a simple average over long time (= several seconds). Sliding window isn't necessary.

To determine when to accept the measurement, compare two such periods of averages to see when the readings are stable.