LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Running average after each iteration

Hello,

 

Attached is an example of my vi file where I capture data for n iterations and then get a final average of the iterations for only the y-data values.

0 Kudos
Message 1 of 9
(5,750 Views)

Attached is an example of my vi file where I capture data for n iterations and then get a final average of the iterations for only the y-data values.  I then plot the final x- vs average y-data.  Is there a way to plot a graph of the average y-data after each iteration instead of just at the end?

 

Thanks,

hiNi.

0 Kudos
Message 2 of 9
(5,749 Views)

Just place a graph in the "For Loop".

You should really connect wires from left to right.

Message 3 of 9
(5,729 Views)

Hello,

 

Firstly, is there a way to get the average of the y-data after each iteration?  The way of how I have it set up, the average of the y-data only comes out at the end of the iterations?  Can you assist me in getting the average of the y-data after each iteration?

 

Thanks,

hiNi

0 Kudos
Message 4 of 9
(5,707 Views)

This is another very basic LabVIEW task. You have the orange wire going to your Y data indicator. Browse to the Mathematics>Probability and Statistics palette and select Mean. Wire it up. You could also simply drag a copy of your existing average calculation to inside the loop.

 

Please see the free LabVIEW training.

Message 5 of 9
(5,695 Views)

Hello,

 

OK, I selected the mean function as you recommended, however, I'm having a problem with the task that I originally asked help for.  I was unclear.  I apologize.  However, this is what I would like to get some help to accomplish:

 

After the first iteration, the data might be:

 

x-data y-data (iteration #1)

1           .10

2           .30

3           .50...

 

The graph of the average response after the 1st iteration will have data points:

 

x-data y-data (Average)

1           .10

2           .30

3           .50...

 

For the second iteration, the raw data might be:

 

x-data y-data (iteration #2)

1           .30

2           .10

3           .30...

 

The graph of the average response after the 2nd iteration will have data points:

 

x-data y-data (average of iteration #1 and # 2)

1           .20  ((0.1+0.3)/2)

2           .20  ((0.3+0.1)/2)

3           .40  ((0.5+0.3)/2)...

 

For the third iteration, the raw data might be:

 

x-data y-data (iteration #3)

1           .40

2           .80

3           .10...

 

The graph of the average response after the 3rd iteration will have data points:

 

x-data y-data (average of iteration #1 and # 2 #3)

1           .30  ((0.4+0.2)/2)

2           .50  ((0.8+0.2)/2)

3           .25  ((0.4+0.1)/2)...

 

Thanks,

hiNi

0 Kudos
Message 6 of 9
(5,685 Views)

Hi hiNI,

 

well, what you describe isn't exactly something called a running average usually...

 

To get your desired result simply add the new data to theold ones and divide by 2 - it's as simple as described as LabView processes arrays the same way as scalars.

 

To have a "real" running average simply search this forum, you will find more than one example!

Message Edited by GerdW on 09-13-2008 05:45 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 9
(5,658 Views)

hiNI wrote:

 

After the first iteration, the data might be:

The graph of the average response after the 1st iteration will have data points:

 

The graph of the average response after the 2nd iteration will have data points:

x-data y-data (average of iteration #1 and # 2)

 

The graph of the average response after the 3rd iteration will have data points:

x-data y-data (average of iteration #1 and # 2 #3)


All you need to do is sum the Y data array in a shift register and divide by the number of iteration (i+1) for display and further processing.

 

 

You code makes no sense, because you generate random x values and also average those. I assume x= constant and just the array index, else nothing would make sense. I also don't know why you generate 2D arrays with stacked FOR loops and then slice out the only data row. Way too much code!

 

Since X is constant and equally spaced, you can use a waveform graph. Here's a simple example, see if it makes sense. 🙂

 

 

It is not a "running average" of e.g. the last x traces, but an average of all N acquisitions as you specified

 

Message Edited by altenbach on 09-13-2008 10:04 AM
Download All
Message 8 of 9
(5,645 Views)

THANK YOU!

 

That was exactly what I needed!!!

 

hiNi

0 Kudos
Message 9 of 9
(5,596 Views)