LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

moving total of "x" numbers

Solved!
Go to solution

Hi, 

I have a (probably) simple question. One of the timed loops in my program iterates every second. Inside is a value based off several temperature and pressure sensors--it changes every second. I know how to add this number to itself to keep a total, but I need to add, say, 60 of the numbers together.

In other words, for the first 60 seconds, every sensor reading is added to the last and this running total is displayed on the screen, but then, the 61st value would add in and the 1st value would be dropped.  Do I need to put together some sort of array with 60 places? 

 

Thanks for your help!

0 Kudos
Message 1 of 9
(2,951 Views)

Yes, an array & shift register would work.

 

If you want this sum of 60 readings to use to calculate an averaged reading you may wish to look at the signal processing palette. The Point By Point VIs are very easy to implement and may fit easily with what you are doing.

 

b

 

 

0 Kudos
Message 2 of 9
(2,942 Views)
Solution
Accepted by NXTenergy

Try something like this:

SumMaximumNumSamples.PNG

 

hope this helps,

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 3 of 9
(2,935 Views)

thanks for the reply. 

actually, I really don't want an average, I've used the point by point vis to do such things in the past. What I am having trouble with is the logic behind:

1) take each incremental value and add it to the running total.

2) at the 61st (or whatever I specify) value, drop the first and use the 61st.

3) repeat this indefinitely so that there is always a sum of 60 values displayed (except when 60 values haven't been gathered, in which case it's just the total of those that have).

0 Kudos
Message 4 of 9
(2,928 Views)

Very clever Norbert! That is a smart way to avoid making copies of the array using some array subset shenanigans.

Cory K
0 Kudos
Message 5 of 9
(2,923 Views)

THat is what he did. The vi that you see is sum aaray. It give the running total of the array values.

Tim
GHSP
0 Kudos
Message 6 of 9
(2,922 Views)

If you use what Norbert gave you it will do exactly what you asked for. Mine looked the exact same but Norbert beat me to it.

Tim
GHSP
0 Kudos
Message 7 of 9
(2,917 Views)

@NXTenergy wrote:

thanks for the reply. 

actually, I really don't want an average, I've used the point by point vis to do such things in the past. What I am having trouble with is the logic behind:

1) take each incremental value and add it to the running total.

2) at the 61st (or whatever I specify) value, drop the first and use the 61st.

3) repeat this indefinitely so that there is always a sum of 60 values displayed (except when 60 values haven't been gathered, in which case it's just the total of those that have).



An (arithmetic) average would devide the sum by the number of elements which i don't do in the code. If you code it, you will see a sum of about 0.5*NumElements which shows that the random number function indeed is expected to return a value of about 0.5.*

 

So setting NumElements to 20 will result in a sum jittering around 10.

 

hope this helps,

Norbert

 

* [EDIT]: This is like tossing a coin. Heads would be 0 and tail be 1. If you toss the coin several times, the "average" of each toss would be 0.5 if the coin is statistically OK. If the average is not 0.5 for a certain coin, the coin could be understood as "marked" (like a marked die rolling certain eyes more often than other eyes)

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 8 of 9
(2,913 Views)

Thanks Norbert! (and the rest). 

I didn't see your post before I wrote my reply. 

I've duplicated what you have there and it seems to be doing just what I want so I'll just modify to fit my code. 

0 Kudos
Message 9 of 9
(2,900 Views)