LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Average per minute and reset counter

Solved!
Go to solution

Hi,

 

First of all this is the first time i program in labview. I have a device that can measure radioactivity ( in disintegrations per minute ) and that device makes a sound everytime it gets a radioactivity signal, in labview i made an app that uses my laptop`s microphone to detect that sound ( high volume sounds ), and count the sounds, but my problem is that i need the counter to save values after every minute and than to give me a average of those values (for example first minute 5 signals so in the average box to be number 5, next minute i get 7 signals so the average box will show me 6 ). Can anyone please help me? 

0 Kudos
Message 1 of 7
(3,763 Views)
Solution
Accepted by topic author LaurRO

Hi Laurro,

 

- use ElapsedTime to determine your minute intervals.

- average := (average_previous + new_value)/(i+1) with "i" being the loop iterator. You need a shift register to hold the average_previous value

 

Both are basic LabVIEW concepts and you can learn them with all those free beginner resources offered by NI on their website (start here)!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 7
(3,751 Views)

thank you

0 Kudos
Message 3 of 7
(3,730 Views)
Solution
Accepted by topic author LaurRO

@GerdW wrote:

 

 

- average := (average_previous + new_value)/(i+1) with "i" being the loop iterator. You need a shift register to hold the average_previous value

 


I don't believe this will give you the average of all values. For instance, when you get your 3rd value you want the average to be (A+B+C)/3. With your method, it will be 

((A+B)/2+C)/3 = A/6+B/6+C/3 which is not equal. I think you want ( i * average_previous + new_value ) / ( i + 1 )

0 Kudos
Message 4 of 7
(3,694 Views)

Hi gregoryj,

 

yes, you're right. I forgot that factor when writing up the post.

 

The VI in my user.lib surely uses this factor… 😄

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 7
(3,688 Views)

In a nutshell, you store all values into an array, add all those up, then divide by the array's size, so you get an average of all those. The array will determine how many times the for loop iterates, and by how much the result is divided, so you don't have to calculate that; if there was no data it will not iterate and just deliver a zero. Just remember to empty the array after each use.

Adder.png

0 Kudos
Message 6 of 7
(3,685 Views)

Hi Daikataro,

 

did you notice the SumArray function in the numerics palette before?

😄

 

(Some might say there already is a Mean function in the math palette, but I also stay away from it as it enforces an additional DLL bundled with an executable…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 7
(3,675 Views)