Stream chunk averaging

Recommended Posts

A user asked us this question direct:

When streaming with a LabJack UE9, we want to be able to stream at say 500Hz for 0.2s every second (so 100samples every second) and average those 100samples each second. I can stream no problems, but was wondering what would be the best way to set the time period for each streaming 'burst' (ie to stream for 0.2s each second). I was just going to use 'delay(0.2)' in a loop but was thinking there must be a better way (ie a specific function or something to define stream time or number of samples??). How would you suggest I go about this??

And the answer:

I actually wouldn't do it that way. I'd just let the stream run continuously, and then use DAQFactory to pull out the desired chunks of data. DAQFactory can subset both by point index and by time. So, lets say you wanted to average the first 0.2 seconds of each second. I'll assume you have a channel called StreamChannel that is getting 500hz stream data, and another channel called AvgChannel that will get the average:

StartStream() // some function to start the streaming

// wait for next xxx.5 second point:
// We add 1.5 to ensure the stream has generated a full 0.2 seconds of data
private nexttime = floor(systime()) + 1.5 

while (1)
   nexttime += 1  // wait for next second

The key to this is the [] using time instead of index. Floor(nexttime) is simply the beginning of the current second, and the [] gets all the data points between xxxx.0 and xxxx.2. This will work no matter what the stream rate is, as long as your history is long enough.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.