03-15-2011 09:45 AM
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
03-15-2011 09:51 AM
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.
03-15-2011 10:09 AM
Sorry, I don't think my earlier description was entirely accurate. I've pasted something that should get you moving in the right direction:
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.
03-15-2011 10:32 AM
03-15-2011 10:34 AM
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.
03-15-2011 10:36 AM
Use my example code above and update the main data array only if the remainder is zero using a case structure.
03-15-2011 10:46 AM - edited 03-15-2011 10:47 AM
@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 altenbach posted as well. Either of these should help get your thinking in the right place in order to tweek out your own solution. Altenbach's solution might be the more efficient of the two, since it only involves 1 loop.
03-15-2011 12:12 PM
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!