# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution
Highlighted

## Average Filter by using mean ptBypt function

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.

Message 1 of 5
(191 Views)
Highlighted

## Rif.: Average Filter by using mean ptBypt function

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
Message 2 of 5
(181 Views)
Highlighted

## Rif.: Average Filter by using mean ptBypt function

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?

Message 3 of 5
(168 Views)
Highlighted
Solution
Accepted by topic author Amr95

## Re: Average Filter by using mean ptBypt function

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 LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
Message 4 of 5
(150 Views)
Highlighted

## Rif.: Average Filter by using mean ptBypt function

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
Message 5 of 5
(148 Views)