Example Code

Convert Waveform to 2D Array in LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

The Waveform to 2D Array polymorphic VI will convert any single waveform or 1D array of waveforms to a 2D array of doubles.  The resulting array will have time information in the first column, indexed according to the timing of the first waveform. This instance could easily be modified to provide a different method for this conversion, such as having individual time columns for each waveform/channel. 

 

Description

This function works by stepping through the array of waveform data, getting the waveform components dt (time difference between samples) and Y (amplitude of sample), then auto-indexing through the array using a for loop.  Inside this loop, a 2-D array is built, again using auto-indexing.  This new array contains time data in the first column, calculated by multiplying the dt of the waveform with the iteration of the for loop.  Subsequent columns contain waveform amplitude data; there will be one additional column for each waveform in the initial array of waveforms.

 

Requirements

LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

1.  Download and unzip the Waveform to 2D Array LV 2012 NI Verified ZIP folder.

2.  Place the unzipped files into the directory for your project.

3.  Add the files into your project (In Project Explorer window, right-click on My Computer, select Add»File...).

4.  Add the Convert Waveform to 2D Array LV 2012 NI Verified.vi sub-VI into the VI where you plan to use the function.

5.  Wire either a single waveform or an array of waveforms into the VI.  Because the function is polymorphic, it will automatically select the Single or Multiple Waveforms instance based on the data you wire in.

 

Additional Information or References

Single Waveform Instance Block Diagram:Single Waveform LV 2012 NI Verified.png

 

Multiple Waveform Instance Block Diagram:

Multiple Waveforms LV 2012 NI Verified.png

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

Regards,
Dan King

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Opperman
Member
Member
on

This vi is a good idea, but do you think you can post some previous versions on here (v8.5, 8.2 etc)?

Dan_K
Active Participant
Active Participant
on

Done, I converted it down to 8.2 and posted it.

Regards,
Dan King

Todd S.
NI Employee (retired)
on

As usual, awesome code!

Todd S.
LabVIEW Community Manager
National Instruments
KrisnaWisnu
Member
Member
on

thx man, just what i need

Certified LabVIEW Developer (CLD)
Certified TestStand Developer (CTD)
Using LabVIEW 8.5.1 (2008) to LabVIEW 2021