grabbing a sample of streamed data

Recommended Posts

I am currently streaming 60Hz AC voltage from a current transformer into a labjack U3 and would love some tips on how to grab a portion of the streamed data, say a couple of cycles, possibly over 0.1seconds and find the max value (rms conversion). Then repeat this say every minute and graph this max or rms(conversion), with respect to time.

Link to comment
Share on other sites

Well, you could do this a number of ways, but I'd probably let the stream run continuously and then use DAQFactory's ability to subset by time to pull out a chunk of the channel history. First, make sure your history is long enough to hold a large chunk of data. The default of 3600 will go real quick even at 1khz. Something like 100,000 might be good. If you go bigger, you might think about using the Persist instead. Now, lets say your input channel is called Volts. Here's some approximate script for grabbing 0.1 seconds of data at random every minute and calcing the max and stuffing it in a channel called VoltMax (which would have a timing of 0, but then so would Volts). I'll assume you are starting the stream from elsewhere, so this sequence would run concurrently:

private chunk
private themax
while(1) // loop forever
   // grab a chunk of data, the last 0.1 seconds worth
   chunk = Volts[systime(),systime()-0.1]
   // calc the max
   themax = max(chunk)
   // assign a time
   themax.time = systime()  
   // stick it into the other channel
   // wait a minute
   // and repeat

You can add more calcs on chunk too to determine your rms and stick it in another channel. You'll notice that I explicitly assign a time to themax. When you do max(chunk), not only will it return the max, but it will assign the time of that max point to themax. I don't know if you want this, but it will result in your VoltMax data stream having rather jumpy times (but within 0.1 seconds) depending on when the max occurred. Its really up to you and you might try eliminating the themax.time line and see if you like the result better.

Finally, just graph VoltMax vs time to get your graph.

Link to comment
Share on other sites

  • 3 months later...

Thanks for the help and I am getting rms values. For some reason however the voltmax channel ( which was converted to power) starts reading a constant value after a couple of hours. The streamed channels seem OK and the max values of the incoming ac voltage appear to change over time as they should.

Link to comment
Share on other sites


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