LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sample Delay VI

Had some spare time so I whipped up a VI to (hopefully) address your need. This is how it works:

Because the purpose of the code is to buffer data, it is built inside a WHILE loop that always executes just one time. This loop has on its perimeter three uninitialized shift registers (or USRs). The top-most USR holds the buffered data. The middle USR holds the index for the next value to be inserted into the buffer (or the buffer position pointer). Finally, the bottom USR stores the buffer's depth in number of samples.

When the VI is run with the function input in the Initialize position, the code allocates the FIFO buffer, including in it any data present at the Data In input. To do this it measures the size of the data array and subtracts that count from the number of samples to delay. The result of this subtraction drives an Initialize Array function to create an array of the floating point value NaN. This array is appended to the data array and the result initializes the buffer shift register. In addition, the size of the data array initializes the buffer position pointer; and the Samples to Delay value is written to the buffer depth USR.

When the VI is run with the function input in the Update position, the data array and the buffer data feed a FOR loop that updates the buffer while extracting data that is getting overwritten. The code in the loop starts by using the buffer position pointer and loop counter to index from the two input arrays the buffer value currently at the buffer position pointer location and the new data value that will be going into that position, respectively. It then inserts the old buffer value into the data array and the new data value into the buffer array. When this inner loop finishes, the data array will hold all the replaced data values and the buffer array will hold all the new data. To implement a circular buffer, the buffer position pointer is incremented and the result is divided by the buffer depth. The integer remainder from the operation is the new buffer position pointer value.

Once the WHILE loop finishes, the array containing the replaced data values is tested to see if it contains any NaN values. If it does not, it is passed to the output without modification. If it does contain a NaN, the code search to find the first index where the array value is not NaN. If the result of this search is -1 (no non-NaN values found) the output array is set to a null array; otherwise the result of the search is used to split the output array and only the portion of the array containing non-NaN values is output.

Hope this helps.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 21 of 21
(444 Views)