John_R Posted March 28, 2019 Report Share Posted March 28, 2019 Hey All, Anyone have an elegant way to do an average on floating (MF) numbers? I am reading a float value from a device every 10 seconds, but saving that value once a minute to a Data Table, I would like to keep a running average of the 6 reads per minute and store that instead of whatever the value is at that instant. Some sort of FIFO arrangement where the newest value comes in and the oldest value drops off with an output value of the running average. I've used the Filter FB before with integers, but that doesn't work with floats (unless I'm missing something). Any Ideas? Regards, JohnR Quote Link to comment Share on other sites More sharing options...
MVP 2021 Flex727 Posted March 28, 2019 MVP 2021 Report Share Posted March 28, 2019 Can't you just use a vector of the 6 MFs? Store the new value using an indirect address for the MF, increment that indirect value, then sum and divide for your moving average. This should work fine if you only have 6. If you have a hundred or a thousand values to average, I have developed an elegant solution for that, but it's only an approximate calculation. Quote Link to comment Share on other sites More sharing options...
MVP 2021 Ausman Posted March 28, 2019 MVP 2021 Report Share Posted March 28, 2019 Flex's answer is correct, but there is also the question that needs to be answered that affects the way you do the maths. Do you want to average only the last 6 readings, or do you want to leverage in the rolling average? Both ways are just different maths, therefore you need to know which one you want to use. cheers, Aus Quote Link to comment Share on other sites More sharing options...
MVP 2021 Flex727 Posted March 28, 2019 MVP 2021 Report Share Posted March 28, 2019 12 minutes ago, Ausman said: Flex's answer is correct Yay! I'm 1 for 1 today! Quote Link to comment Share on other sites More sharing options...
MVP 2021 Ausman Posted March 28, 2019 MVP 2021 Report Share Posted March 28, 2019 Flex.....😀 I should add that if you need to do the leveraged average, depending on how you do this it can take ages to get it up to your ideal reading amount. This can be a problem on a full init and reset, or power cycle of sensors that need time to stabilise properly. You either need to add in a suitable delay on any actions associated with the average, or have the average over-ridden for a set time with an amount close to the normal running situation. cheers, Aus Quote Link to comment Share on other sites More sharing options...
John_R Posted March 29, 2019 Author Report Share Posted March 29, 2019 16 hours ago, Flex727 said: Can't you just use a vector of the 6 MFs? Store the new value using an indirect address for the MF, increment that indirect value, then sum and divide for your moving average. Flex, this is the direction I was leaning, something like a Vector-Shift-Left, plug a value into the starting address, which then bumps the rest of the values down, then do the math. I see the Store Direct under Math/Float/Basic functions, but (unless I'm missing the obvious), you can't do vector functions with MF's. So, are you thinking that I should have a net with 6 of these Float Store Directs in series, each moving the previous value to the next, then doing the math? 14 hours ago, Ausman said: Do you want to average only the last 6 readings, or do you want to leverage in the rolling average? Aus, I was thinking that if I plugged one value in and dropped one off, then did a sum & divide, that would be a rolling average.... JohnR Quote Link to comment Share on other sites More sharing options...
MVP 2021 Ausman Posted March 29, 2019 MVP 2021 Report Share Posted March 29, 2019 JohnR, I think that you could look at using a Formula to do the maths. I haven't physically tried your need and it's time for zzzzzzz, but Formulas work with MFs and it should be much easier. Along the lines of (A+B+C+D+E+F)/6. Have a go and I think you'll find it ok. Re my average comments, brain too tired to explain tonight. I'll try and do it in the morning. cheers, Aus Quote Link to comment Share on other sites More sharing options...
MVP 2021 Flex727 Posted March 29, 2019 MVP 2021 Report Share Posted March 29, 2019 1 hour ago, JohnR said: I see the Store Direct under Math/Float/Basic functions, but (unless I'm missing the obvious), you can't do vector functions with MF's. I was talking about Store Indirect, but you are correct that you can't do that with MFs. Not sure why. It looks like your solution may be the most straightforward way. Quote Link to comment Share on other sites More sharing options...
John_R Posted March 29, 2019 Author Report Share Posted March 29, 2019 1 hour ago, Ausman said: but Formulas work with MFs and it should be much easier. Aus, you are correct, that is much simpler then my net full of math...... 1 hour ago, Flex727 said: I was talking about Store Indirect, but you are correct that you can't do that with MFs. Not sure why. Flex, I'm not sure why MF's are excluded from a lot of stuff either, but at least you bumped my mind into looking at the Float functions available.... We are a little closer to an Elegant solution JohnR Quote Link to comment Share on other sites More sharing options...
MVP 2021 Ausman Posted March 29, 2019 MVP 2021 Report Share Posted March 29, 2019 I'm working on my "methods" pros and cons essay. Might take a bit longer. 🐢 Almost done but I'll revisit it a few times before posting. Stay tuned! cheers, Aus Quote Link to comment Share on other sites More sharing options...
MVP 2021 Ausman Posted March 31, 2019 MVP 2021 Report Share Posted March 31, 2019 I know, I know, taking longer than I wanted. Other things cropping up. I am doing a subroutine (export/import) to show examples. Hopefully able to do this homework tonight. cheers, Aus Quote Link to comment Share on other sites More sharing options...
MVP 2021 Ausman Posted April 2, 2019 MVP 2021 Report Share Posted April 2, 2019 Sorry...other things on the go. Almost there...will be worth the wait. "Elegance Extraordinaire Monsewer" Well...maybe. Certainly will get your brain cells firing. Cheers, Aus Quote Link to comment Share on other sites More sharing options...
MVP 2021 Ausman Posted April 8, 2019 MVP 2021 Report Share Posted April 8, 2019 Sorry All....Real work has prevailed over volunteer stuff. It is coming and you'll like it. cheers, Aus Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.