LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to have labview calculate on streaming data?

I want to create a vi that will allow for calculations on the data stream as it is incoming. Every VI I've created in the past would be collect all the data and then do all the calculations with it. I'm trying to figure out the best way to implement it in real time. The best example I can think of would be measuring frequency and duty of a square wave. If hook a function generator up to the daq and change either of those values while the program is running I'd want the program to display those changes as I change them, of if I turn off the function generator everything will be zero until I turn it back on and it goes back to showing the data correctly.

 

Is the best way to implement something like this is have the daq take x number of samples, and measure that set, and then go take another x number of samples and just keep doing that loop until the program is stopped?

0 Kudos
Message 1 of 4
(1,210 Views)
Sure, there is no problem with continuously collecting data and calculating the frequency of it.
0 Kudos
Message 2 of 4
(1,203 Views)

@ABZ741 wrote:

Is the best way to implement something like this is have the daq take x number of samples, and measure that set, and then go take another x number of samples and just keep doing that loop until the program is stopped?


Yes, that can work. It's basically the same as what you know (collect all the data, then do all the calculations), but you're doing it in many small chunks.

 

You might need/want to keep a buffer of the data to do your analysis. For example, on each iteration of the loop maybe you read 100 points from the instrument, rotate it into an array, only keeping the 1000 most recent points, then do your calculation on the 1000 points. This can help if you're measuring signals that are slower than your data loop rate.

0 Kudos
Message 3 of 4
(1,182 Views)

You are describing something called the Producer/Consumer Design Pattern.  The notion is you have a "continuous data gathering" routine, the "Producer", that, as soon as an aliquot of data have been acquired, immediately "ships it off" (meaning out of the "Acquisition Loop") to a parallel process, the "Consumer", that "does something useful with it".  This can involve plotting it, doing an FFT on it and plotting the spectrum, saving it to disk, etc.

 

Try this:

  • Start LabVIEW.
  • Click "File" on the Menu bar.  Select "New ..." (be use you choose the second entry, with the three dots).
  • Choose "Producer/Consumer Design Pattern (Data).
  • Examine the VI that LabVIEW "produces" (bad pun!) for you.

I'm pretty sure a Web Search for Producer/Consumer and LabVIEW will turn up other examples.  

 

Bob Schor

 

 

0 Kudos
Message 4 of 4
(1,129 Views)