LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Average Filter by using mean ptBypt function

Solved!
Go to solution

I need to get the mean value of of some data that I acquire using the producer/consumer structure. I need to get the average of each 5 samples (That could be changed later) and calculate the mean value of the next 5 samples and so on. I checked some old discussion and the mean ptBypt has been recommended multiple times and I have a question regarding it. It needs to set the sample length beforehand (which is the number of samples my signal has as far as I understood, correct me if I'm wrong), the problem is I don't know how many samples my signal has beforehand, the mean value should be calculated simultaneously as the data is being acquired not after I collect a set of data. So I would like to know if I could use this function for this purpose or do I need to figure out some other algorithm for achieving that.

0 Kudos
Message 1 of 5
(1,360 Views)

Sample length is the size of the averaging buffer. In your case, it's 5.

The average will be recalculated for every new sample.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 5
(1,350 Views)

So for instance if I get those values for the first 10 samples: 1,2,3,4,5,6,7,8,9,10
It will calculate an array of the following samples: sample 1=1 , sample 2= 1+2, .... , sample 5: 1+2+3+4+5
and then the buffer gets emptied and it starts with sample 6= 6, sample 7: 6+7 and so on.

Do I understand the working principle of it right?

0 Kudos
Message 3 of 5
(1,337 Views)
Solution
Accepted by topic author Amr95

HI amr,

 


@Amr95 wrote:

I checked some old discussion and the mean ptBypt has been recommended multiple times and I have a question regarding it. It needs to set the sample length beforehand (which is the number of samples my signal has as far as I understood, correct me if I'm wrong), the problem is I don't know how many samples my signal has beforehand, the mean value should be calculated simultaneously as the data is being acquired not after I collect a set of data.


You can use PtByPt-Mean as it takes the last sample as input and uses an internal buffer to hold previous samples…

 


@Amr95 wrote:

So for instance if I get those values for the first 10 samples: 1,2,3,4,5,6,7,8,9,10
It will calculate an array of the following samples: sample 1=1 , sample 2= 1+2, .... , sample 5: 1+2+3+4+5
and then the buffer gets emptied and it starts with sample 6= 6, sample 7: 6+7 and so on.


No.

After the 5th iteration it will have "1,2,3,4,5" in its internal buffer and output "3" as mean.

In the 6th iteration it gets "6" as new samples, the internal buffer holds "2,3,4,5,6" and output will be "4"…

 

The buffer will not be emptied, but works as a sliding window.

 

To get to your requirements (one mean value for each block of 5 input samples) you just need a shift register to hold the sum of previous samples. For iteration 1-4 you just add the new sample to shift register value. At 5th iteration you get the sum of 5 samples, calc the mean and write a zero into the shift register…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 5
(1,319 Views)

No, actually it's a moving average. Mean is calculated over the last N samples. The function help is a little ambiguous about this input.

I suggest you to write a small test vi with varying data sets and see what happens. It's a 5 min exercise but very helpful in such cases.

You may also open the vi and watch its code, although you cannot debug it.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 5 of 5
(1,317 Views)