Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Highlighted

10-29-2020 06:32 AM

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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.

Solved! Go to Solution.

Highlighted
Options

10-29-2020 06:46 AM - edited 10-29-2020 06:47 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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

-------------------

LV 7.1, 2011, 2017, 2019

Highlighted
Options

10-29-2020 06:56 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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?

Highlighted
Options

Solution

Accepted by topic author Amr95

10-29-2020 08:15 AM - edited 10-29-2020 08:18 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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

GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO

Highlighted
Options

10-29-2020 08:16 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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

-------------------

LV 7.1, 2011, 2017, 2019