Converting a Waveform to a 2D Array

Updated Nov 19, 2018

Reported In

Software

  • LabVIEW Full
  • LabVIEW Base

Issue Details

  • My data is in a waveform and I would like to convert it to a two-dimensional (2D) array of doubles
  • I need to write waveform data to a text file
  • I would like to use array functions on my waveform data

Solution

  • In order to convert this data to a 2D array, you will need to extract the existing Y data from the waveform and assign a time to each value
  • Below is an example of how to convert the data into a 2D array of doubles
    1. Use the Get Waveform Components function to extract the and dt data from the waveform
    2. Auto-index via a For Loop to get the array of Y values
    3. Within the loop multiply dt by the iteration count. This will give the time associated with each data point
    4. Combine the array and the output of the multiplication by using the Build Array function
    5. The indexed output from the Build Array function will give you a 2D array of the waveform data relative to time

Additional Information

  • The waveform data type is a special type of cluster made up of 4 elements
    • Y - This is a 1D Array of the amplitude measurements of your data
    • t0 - This is a time stamp signifying the start time of your measurement
    • dt - This is a scalar that describes the uniform time division of the signal in seconds
    • Attributes - This is a variant data type containing all of the waveform metadata, such as the hardware device number or the channel names
  • The snippet above and this community example show an implementation of the desired program
  • The method above is completely ignoring the attributes and t0 data elements from the waveform and only focusing on the time division (dt) and amplitude data (Y).
    • This simplifies the code and focuses on the most important elements of the incoming data.
  • The code in the snippet above does the following
    • Takes the amplitude array and iterates through the array, assigning a time value of the time division multiplied by the current iteration of the loop
    • By first combining these two values into a two element 1D array and then indexing it with a for loop, the result is a 2D array of two columns
    • The first column contains time information, starting at 0, increasing by dt every row
    • The second column contains all of the amplitude data.
    • Note that additional waveform functions can be found in the functions palette under Programming » Waveform.

WAS THIS ARTICLE HELPFUL?

Not Helpful