LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I want to plot the average of the last 10 points

My program is running at 10 Hz (I have 100ms wait in my main FOR loop), but I want to plot and save data at 1Hz. But since I'm already running 10x faster than my desired plot rate I'd like to average the 10 points which are collected between plots. I'm sure there is a simple straight forward way to do this but I haven't figured it out yet.

Any help would be appreciated.

Ron

0 Kudos
Message 1 of 8
(5,207 Views)

Make the 10Hz for loop nested inside a for loop set to run 10 times which contains the plot and the 100 ms wait. Use the mean VI inside the inner loop and set the sample width to '10'. Set the output of this mean to an indexing tunnel feeding the plot inside the outter loop. Use shift registers to save the array between loops.

0 Kudos
Message 2 of 8
(5,201 Views)

Sorry, I don't think my earlier description was entirely accurate. I've pasted something that should get you moving in the right direction:

 

AVGed Array.png

 

So, you don't really need indexing tunnels, you just take the avg after running that inner loop 10 times and add that to the plot which is perpetuated via the shift registers of the outer while loop.

0 Kudos
Message 3 of 8
(5,188 Views)

You can use "Mean pt-by-pt" or make your own.

 

Here are more details and an example.

 

Message 4 of 8
(5,175 Views)

OK, that looks helpful, but I have one other requirement: I want the program to be able to respond to my input (number source) at the higher frequency. As I understand your diagram my number source would be stuck in the loop and the numbers would only be available to the whole program at the slower rate--am I understanding this correctly? So I want to loop through my program 10 times and respond to those 10 numbers, but then take the average of those last ten numbers and plot/write them to chart/file.

Thanks.

0 Kudos
Message 5 of 8
(5,173 Views)

Use my example code above and update the main data array only if the remainder is zero using a case structure.

0 Kudos
Message 6 of 8
(5,171 Views)

 


@rsi77 wrote:

OK, that looks helpful, but I have one other requirement: I want the program to be able to respond to my input (number source) at the higher frequency. As I understand your diagram my number source would be stuck in the loop and the numbers would only be available to the whole program at the slower rate--am I understanding this correctly? So I want to loop through my program 10 times and respond to those 10 numbers, but then take the average of those last ten numbers and plot/write them to chart/file.

Thanks.


You would put the logic to handle the numbers sample by sample inside the inner loop if that were the case. If they need to save data between iterations, use shift registers or feedback nodes. Look at the example

 

 

0 Kudos
Message 7 of 8
(5,160 Views)

The case structure coupled with "quotient and remainder" does exactly what I want. I hadn't thought of using it that way before. Here's a simplified version of what seems to be working for me. Thanks for the help!

Plot average every 10th cycle.png

0 Kudos
Message 8 of 8
(5,142 Views)