# Thread: Calculating variable flow rate when the scale is subject to random movement

1. ## Calculating variable flow rate when the scale is subject to random movement

I have an ingredient feeder resting on electronic scale that is transmitting one reading per second to a computer. I would like to calculate the current flow rate of the product as it is being dispensed from the feeder. It is possible for the flow rate to change over time so I would like to recalculate the flow rate on an ongoing basis as best as possible using a moving window. I know there will be a lag in the correct flow rate calculation.
Now here is the real problem… The system is subject to random movement and bumps (which cannot be eliminated) creating random 'noise' in the data so a graph of the readings is not smooth. I need to be able to smooth out the rough spots in the data and calculate the current flow rate as best as possible without too much undue error and a minimum of lag time. Thanks.

2. Assuming you're interested in a mass flow rate computed as the time derivative of the $m(t)$ signal you're getting from the scale, might I recommend fitting a line to the last $n$ points, and reading the slope off of that line? Fitting a line to data is robust with respect to noise, unlike taking a derivative (which is highly susceptible to noise). In fact, you wouldn't even need to compute the $b$ of the $m(t)=(m')t+b$. You could just go with the computation of the $m'$ as follows. Given the latest time series data $(t_{i},m_{i}),$ the slope of the line fitted through the last $n$ data points is given by

$\displaystyle m'=\dfrac{\left(\sum_{i=1}^{n}t_{i}m_{i}\right)-n\bar{t}\,\bar{m}}{\sum_{i=1}^{n}t_{i}^{2}-n\bar{t}^{2}},$

where

$\displaystyle\bar{t}=\dfrac{1}{n}\sum_{i=1}^{n}t_{ i},$ and

$\displaystyle\bar{m}=\dfrac{1}{n}\sum_{i=1}^{n}m_{ i}$

are the averages.

Since everything in sight is a sum, you have a procedure that's robust with respect to noise. In addition, you can re-compute the slope each time you get a new data point in, so you'll have up-to-the-second information.

A word of caution, however: the more data points you include in these computations, the less susceptible to noise your numbers will be. However, it is also true that the more data points you include in these computations, the slower your computed slope will respond to real changes in the slope. So you'll need to play around with $n$ to see what works the best in your case. I would recommend that you sample at 10 times the frequency of any expected frequencies showing up in your data, otherwise you won't be able to tell noise from real signal so well. One sample per second might be perfectly adequate if you don't expect things to change except on a scale of every ten seconds, for example.

Hope this helps.

[EDIT] There are even some fancy ways of reducing the computations required by keeping running buffers of data, and doing the sums by only adding one point and subtracting the last point, that sort of thing. But that may be much fancier than you need.

3. Ackbeet,
Thanks for the help. I just need to make sure I understand the terms used. I asssume that m would be the measured weight, in grams. Is t the time, in seconds, from the start of the observations? I presume that m' would be the flow rate in grams per second. I understand the rest completely. I can easily maintain the partial solution in software, which is what I do best but it's been about 25 years since I have had a math course. Thanks again for the help.

4. Yes to all, and you're welcome.