LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Conditionally capturing certain data while continuously acquiring data

In case my question has totally confused you, let me describe the situation, a general one which I'm sure some of you have already tackled.

Suppose you're acquiring data from several channels (let's say two waveforms). And you only want to capture their amplitudes (Y1, Y2,etc.) when either a button is pushed (i.e., things are steady state, now grab that data) or when something else has changed a certain amount (say their frequency has changed 2 Hz).

When I say "capture", I simply mean grabbing the data into a separate array of X,Y values for later processing or on-line plotting while still acquiring data.

Hopefully, this makes sense. Would greatly appreciate any thoughts on this, as it's a
situation that I seem to run into often.
All the best, Hunter
0 Kudos
Message 1 of 5
(3,111 Views)
Your use of the terms "Waveforms" and "amplitude" implies a measurement of many samples into one number (for each channel).
For example, if your signal was pure 100 Hz, 1.000 Volts peak, and you captured a 0.1 second block of that signal, then you would have 10 cycles in the capture buffer, varying from +1V to -1V. You can use the RMS function to turn that block of samples into a number of 0.707, meaning the RMS value is 0.707V (= 1.0 V peak).

The basic philosophy would be:
1... Start a continuous acquisition. By specifying NUMBER oF SAMPLES = 0 in the AI-START vi, you will acquire data forever (until the buffer overflows, or until stopped).
2... Periodically (based on a timer), you ask the AI READ function to read zero samples. This does not remove data, but it does tell you how many samples are in the buffer.
3... You immediately read that many samples out of the buffer, and convert from volts to engineering units (if appropriate).
4... If you are measuring their frequency, you need to perform an FFT now. The highest peak in the magnitude of the FFT output is the dominant frequency in the signal. (Freq. of peak = Index of peak * Sample Rate / NPoints in block.
5... If you are doing FFTs, you get a big speed advantage if your block size is a power of two (128, 256, 512, 1024, etc.). If so, then replace step 3 with *-IF-* backlog >= N (power of 2) then read N points from buffer.
6... Apply your criteria - *-IF-* the button has been pressed, *-OR-* if the frequency of channel 2 is different, then compute the RMS or peak values and append to your final results array. Otherwise do nothing.

If you want to detect 2-Hz changes, you need to know the rules of how FFTs work - the frequency resolution is the BIN WIDTH, which equals the sample rate divided by the number of points in the block. If you have a 1000 Hz sample rate and a 1024 point block, your resolution is 1000 / 1024 or just less than 1 Hz. But if you have a 1000 Hz sample rate and a 32 point block, your resolution is 1000 / 32 or about 30 Hz.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 2 of 5
(3,111 Views)
Hello, CoastalMaineBird
Thanks for stepping up to help me figure this out. I'm in pretty good shape on sampling, etc., so the biggest question is using the condition.
Let's try a simple example. See attached VI. Here I'm generating a sine wave where I can control it's amplitude and offset. What I'd like to do is grab the current RMS and offset parameters when I press the "Capture" and create an array of captured X,Y values which is saved once the VI is stopped. While the VI is running, the XY plot is updated showing all previous captures along with the newest one. Obviously, the current version only puts the last captured Offset & RMS on the plot.
Get the drift?
Thanks for your help,
Hunter
0 Kudos
Message 3 of 5
(3,111 Views)
Your XY Chart only shows the most recent capture.

If you want to have an array of them, you have to build an array.

Put a shift register on the WHILE loop.
Initialize it with an EMPTY array of X-Y pairs.
Inside the CASE TRUE, append the new X-Y pair (you just captured) to the shift register left side and put the new array out to the right side
Inside the CASE FALSE, pass the shift reg thru unchanged.

You can plot the new array inside the TRUE case, if you're not concerned about speed (it will plot every time you click the button), or outside the while loop (it will plot only after you stop).

Outside the while loop, save your data to a file.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 4 of 5
(3,111 Views)
Ah, ha!!
I knew it must be pretty simple.
Thanks so much for the help. See the revised version attached.
0 Kudos
Message 5 of 5
(3,111 Views)