LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Downsampling and averaging data.

Hello,

A quick question, which probably has a very simple answer but I can't see it!

I have a vi that samples data at a rate of x (in this case 1 Hz). This data is collected in an event structure so every second an event is fired that polls the device for data, and that data is displayed. The data is also logged to file, however what I really want is log the average of 5 samples every 5 seconds (i.e. down-sample to 0.2Hz and average out).

I tried creating an array in a for loop that replaces a different index each iteration, and then averaging every 5 iterations, but that dint work. I also tried the decimate sub vi, but couldn't make that work either. When I searched, everything that came up related to a running average at the same frequency, but that isn't quite what i want. Any suggestions appreciated...

Cheers,
EDF.
0 Kudos
Message 1 of 5
(3,067 Views)

What you'll need to do is set up a shift register to store data between loop iterations, and then clear the register every fifth iteration.

 

edit - Oops, in avg.PNG, instead of dividing by Data IN, you should be dividing by 5.  Sorry.



Message Edited by JeffOverton on 02-20-2008 12:49 PM
Download All
0 Kudos
Message 2 of 5
(3,062 Views)
Thanks for that, looks like a good solution!

Cheers,
EDF
0 Kudos
Message 3 of 5
(3,013 Views)
Ok, I've implemented this code in my program, but I can't quite get it to work.

After putting probes everyhwere to see what was happening, I discovered that everythign goes fine untill the 5th itteration of the loop. The output of the shift register on the while loop works fine and outputs the sums nicley before resetting to zero. But on the 5th itteration, after going through the tunnel into the event structure, the array wipes out! It only does this on the 5th itteration when it's supposed to average. So you get the array adding up like it's supposed to, ie (for a hypothetical voltage measurment of ~25v) 25 on the first, 50 on the second, 75 on the 3rd, 100 on the 4th, but then on the 5th outside the tunnel to the even structure, it records 125, but inside it has a blank array, which then obviolusly averages to nothing! I'm a little stumped to be honest... Any suggestions appreciated...

EDF.
0 Kudos
Message 4 of 5
(2,978 Views)
I whipped up a quick test of that structure, and I'm not seeing anything.  Could you post that section of your code?  If not, are you using any local variables or other race-prone data structures?
0 Kudos
Message 5 of 5
(2,959 Views)