Posted Saturday at 7:59 AM Hello! Is there any FB for average value calculation? I did add Value to int every secend and devide it value by passed secends. Only problem is that by the time goes on int will be full? Share this post Link to post Share on other sites

Posted Saturday at 3:42 PM maybe... did you check the instruction list? and you should always post your code and expectations. (resolution, time span, accuracy...) if i read this right you have a problem due summation since average is computed by: AVG(n) = (X_{1}+X_{2}+...X_{n})/n it appears that you are attempting to store top side of the fraction into one variable and of course this will overflow pretty soon. solution to not do that... note that the very next average will be AVG(n+1) = (X_{1}+X_{2}+...X_{n+1})/(n+1) but this can also be written as this (isolate last term) AVG(n+1) = (X_{1}+X_{2}+...X_{n})/(n+1) + X_{n+1}/(n+1) or AVG(n+1) = (AVG(n)*n + X_{n+1})/(n+1) but that will overflow the same way as before due multiplication AVG(n)*n. however this can be rewritten as AVG(n+1) = AVG(n)*n/(n+1) + X_{n+1}/(n+1) where AVG(n) is previous average, X_{n+1} is the latest sample, and "n+1" is the latest sample count. as long as you compute n/(n+1) before multiplying AVG(n), there should be no problem since n/(n+1) will grow but never exceed 1. ultimately this will settle at some average value since limit of X_{n}/n goes to zero as n goes to infinity so adding more samples will just add zeroes and average will stop changing. this begs question... are you really really sure you need total average over indeterminate and always increasing time interval and not average of several most recent samples? one would normally look at average only over fixed number of samples. that number can be small or large but it should be fixed. if you really want to cover "endless" interval, you need to define what is "endless". 1 person likes this Share this post Link to post Share on other sites

Posted Saturday at 7:36 PM I think you are looking for the function MovingAverage. Often called a floating average. Essentially a FIFO of values that is divide by the number of values. Share this post Link to post Share on other sites