01-13-2022 02:52 PM
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?
01-13-2022 03:11 PM
01-13-2022 05:00 PM
@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.
01-17-2022 11:35 AM
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:
I'm pretty sure a Web Search for Producer/Consumer and LabVIEW will turn up other examples.
Bob Schor