An Introduction to NI-DAQmx Tools for Data Acquisition with The Mathworks, Inc. MATLAB® Software
Overview
This document introduces NI-DAQmx Tools for data acquisition with The Mathworks, Inc. MATLAB®1 evaluation software that allows you to work with National Instruments data acquisition hardware fromMATLAB software. As we’ll see, this evaluation software offers major advantages over The MathWorks, Inc.’s Data Acquisition Toolbox for MATLAB® software.
NI-DAQmx Tools is a great introduction to the National Instruments hardware platform. The second section of this document introduces you to some of the relevant software of this platform.
Download NI-DAQmx Tools
Table of Contents
What is NI-DAQmx Tools for Data Acquisition
NI-DAQmx Tools adds a library of commands that you can invoke from the m-file scripts that you work with from the MATLAB software environment. In addition to the new library, it also includes many practical examples that show you how to acquire and generate signals, configure your National Instruments hardware, and other useful tasks. NI-DAQmx Tools supports a broad range of National Instruments multifunction data acquisition devices, from the established E-series line to latest M- and S-series lines. The device options allow you to choose a hardware platform that best suits your requirements, whether you need a portable USB-connected device, low cost device, or high-accuracy device. NI-DAQmx Tools includes support for all devices supported by the NI-DAQmx driver. Visit ni.com/daq for more information about the multifunction data acquisition hardware options.
Working with NI-DAQmx Tools for Data Acquisition
To work with NI-DAQmx Tools, you invoke function calls from the MATLAB command line or as part of a batch m-file script. When you do so, an appropriate call is made to the NI-DAQmx driver to interface with the hardware. The fundamental advantage of this software is the user interface that will be discussed in the following demo.
Let’s walk through acquiring data using the “AcqNUpdates_UI.m” example as though we had just installed and opened up NI-DAQmx Tools from within the MATLAB® environment.
There are a few methods that can be used to access the library calls that are needed. The most efficient method is to use the built-in demo browsers that are installed with NI-DAQmx Tools. These two browsers display two different classes of demos. The first, DAQ_Demo_Browser.m, displays the function calls that require direct inputs in the Command Window. Figure 1 below displays this interface.

[+] Enlarge Image
By browsing through this interface, you can see the help files for all of the library files contained in the browser to determine which call will best suit your needs. Figure 1 displays the help file for AcqNUpdates.m, which we will discuss in detail.
The other demo browser, DAQ_UI_Demo_Browser.m, displays a different set of library calls. As you can see in Figure 2; these files all contain a “_UI” at the end of the name. This means that you don’t have to pass any input parameters into the program because they display an interactive LabVIEW interface window in which these parameters are entered. This interactive window will also be discussed in detail. The help files for each of these user-interface programs can be accessed using this browser, such as the AcqNUpdates_UI displayed in Figure 2.

[+] Enlarge Image
Another way to access this example is to browse to the folder where the functions are contained. The default installation directory is C:/Matlab/Toolbox/NatInst/DAQ/. By selecting “Open” from the File menu and browsing to this directory, you see all of the scripts included in NI-DAQmx Tools, as displayed in Figure 3.
You will also see a few other functionalities that cannot be accessed through the demo browser. A few of these include the NIPlot.m, Launch_Examples_Help.m, DisplayAcqFile.m, and OpenLVProductPage.m. The NIPLOT function, in contrast to the plot function included with the MATLAB software, will plot values on the National Instruments graph interface that is seen in many of the data acquisition functions. The DisplayAcqFile.m will acquire waveform data from a binary file and plot it on a LabVIEW interface window.

[+] Enlarge Image
The red arrow (Figure 3) indicates the particular file that we will be working with. There are two further methods to understanding how a particular script works. The first is to open up the actual function call and see how the function is working.

[+] Enlarge Image
By observing the file itself in Figure 4, we see that there is no need to pass any input parameters to this function. This is because this particular function opens up a user-interface to perform the data acquisition. This will be discussed further. There are descriptions within the .m script that describe each return type and input type.
Another way to identify what types of parameters are needed is to use the help command in the MATLAB software environment.
By observing the returned help from the MATLAB software, we would deduce the same results. We see that this function will return a total of three variables: the recorded data, the time matrix, and the initial time. Now, let’s run this command with only the data as a return.

Figure 6 – Calling AcqNUpdates_UI
After calling the function, an interactive window will pop up. This window is the user interface that was used to design the example in LV. All of the examples which include the “_UI” suffix, contain these interfaces. This interactive window can be viewed in Figure 7.

[+] Enlarge Image
The red arrow (Figure 7) indicates that the device and channel need to be specified. This box is auto-populated by the NI-DAQmx driver. It contains all of the available channels on all available devices that correspond to the functionality being used. For example, this example is an analog input task. Therefore, the analog output channels would not show up while all of the analog input channels will be auto-populated.

[+] Enlarge Image
For this example, Device 2 is a USB-6009 device. We used the analog input channel 0 to acquire the data. The other options are populated with the default values. They can be changed for each acquisition. The number of samples is determined by the Samples Per Channel control. The combination of Sample Rate and Samples Per Channel must adhere to the Nyquist Theorem in that the Sample Rate needs to be at least 10 times larger than the Samples Per Channel. The blue arrow (Figure 8) indicates the Start button used to start the acquisition. After the specified number of samples is acquired, the plot is populated with the data, indicated by the yellow arrow (Figure 8). The red arrow (Figure 8) indicates some zoom and handle options available for the graph itself. The data is then returned to the MATLAB software environment when the Quit button is selected. At this point, the window will disappear.
As seen in Figure 9, the data is returned to the MATLAB Command Window and stored in the variable specified, “data” in this case. Also, the length, max, and min of the data array are displayed. Once this data has been imported by the MATLAB software environment, normal data processing and analysis can begin.

Figure 9 – Data When Returned To MATLAB®
There is also a corresponding function associated with this interactive window that does not use the interactive window. It is named AcqNUpdates.m. The help file can again be used to determine the required input and output parameters. The command in Figure 10 was used to perform the same collection of data as in the previous example. The six input parameters are the same parameters that were labeled on the interactive window in the previous example.

[+] Enlarge Image

Figure 11 – Returned Data Using Command without Interactive Window
Download NI-DAQmx Tools
Transitioning to use of NI-DAQmx Tools for Data Acquisition
If you are currently working with The MathWorks, Inc. Data Acquisition Toolbox for MATLAB, transitioning to use of NI-DAQmx Tools is simplified by the fact that NI E Series and NI M Series devices supported by the Data Acquisition Toolbox are also supported by NI-DAQmx Tools; therefore, no hardware changes are required for those that are already using Data Acquisition Toolbox. Additionally, NI-DAQmx Tools software is available as a free download on ni.com.
Download NI-DAQmx Tools
Related Software: LabVIEW and the Math Interface Toolkit
NI-DAQmx Tools was created using National Instruments LabVIEW and an add-on for LabVIEW called the Math Interface Toolkit. LabVIEW is a graphical development environment for creating flexible and scalable test, measurement, and control applications rapidly and at minimal cost. With LabVIEW, engineers and scientists interface with real-world signals, analyze data for meaningful information, and share results and applications. Regardless of experience, LabVIEW makes development fast and easy for all users.
The National Instruments Math Interface Toolkit for LabVIEW provides LabVIEW developers tools for distributing their LabVIEW applications for use in the MATLAB analysis environment. Through an intuitive wizard, you can quickly create the function name, organize the parameters in the function prototype, and customize automatically generated help for the function. The final MEX file can then be distributed for native use in the MATLAB environment. By using LabVIEW to add functionality to MATLAB software, MATLAB users can easily take advantage of unique features of LabVIEW such as: the wide-ranging I/O capabilities for plug-in data acquisition, instrument control, motion, vision, intuitive user interfaces, communication protocols such as TCP/IP and CAN, and over 500 functions for signal processing, analysis and math.
Related Software: Combine Graphical and Textual Programming with LabVIEW
LabVIEW MathScript is an important new feature added to LabVIEW 8 that adds math-oriented, textual programming to LabVIEW. LabVIEW MathScript joins graphical dataflow programming as another means to define the custom software you develop using LabVIEW. Working with LabVIEW, you can choose a textual approach, a graphical approach, or a combination of the two. You can choose the most effective syntax for technical computing, whether you are developing algorithms, exploring signal processing concepts or analyzing results. Please visit ni.com/mathscript for more information.
At the heart of LabVIEW MathScript is a high-level text-based programming language with syntax and functionality (Table 1) that abstracts the complexity of tasks related to signal processing, analysis and math. MathScript includes over 500 built-in functions for such work and allows you to define your own new user-defined functions. MathScript is generally compatible with m-file script syntax, which is the syntax widely used by alternative technical computing software such as The MathWorks, Inc. MATLAB® software, and others.
Such compatibility means that you can work with many previously developed m-file scripts such as those available in engineering textbooks or on the Internet. This means you can leverage web sites that distribute open-source m-file scripts, such as SourceForge.net, which has one of the largest repositories of open source code.
| LabVIEW MathScript Language Feature | Description |
| Powerful Textual Math | MathScript includes over 500 built-in functions for math, signal processing and analysis; functions cover areas such as linear algebra, curve fitting, digital filters, differential equations, probability / statistics and much more |
| Math-oriented datatypes | MathScript utilizes matrices and arrays as fundamental datatypes, with built-in operators for generating data, accessing elements and other operations |
| Compatible | MathScript is generally compatible with the m-file script syntax used by The MathWorks, Inc.’s MATLAB® software, and others. Such compatibility means that you can use MathScript to leverage thousands of algorithms available on the web and textbooks |
| Extendible | You can extend MathScript by defining your own custom functions |
| Part of LabVIEW | MathScript does not require additional 3rd-party software to compile and execute |
| Performance | Like LabVIEW itself, MathScript is compiled for efficient execution |
Summary
NI-DAQmx Tools for data acquisition software allows you to work with National Instruments data acquisition hardware from within the MATLAB software environment. NI-DAQmx Tools was built using LabVIEW, works with all devices supported by the NI-DAQmx hardware driver and is available as a free download from ni.com.
By using LabVIEW to add functionality to MATLAB software, MATLAB users can easily take advantage of unique features of LabVIEW such as: the wide-ranging I/O capabilities for plug-in data acquisition, instrument control, motion, vision, intuitive user interfaces, communication protocols such as TCP/IP and CAN, and over 500 functions for signal processing, analysis and math.
Download NI-DAQmx Tools
______________
1MATLAB® is a registered trademark of The MathWorks, Inc. All other trademarks are the property of their respective owners. Neither NI-DAQmx tools nor any other NI-DAQ software is in any way sponsored by, approved by, or connected with The MathWorks. Rather, NI-DAQmx tools has been designed by NI to be compatible with the MATLAB software.
Reader Comments | Submit a comment »
which version of Matlab?
Can you include a note on which version
of Matlab you have developed this tool
on ? I am getting errors when I run this
tool set on R2007b version. Thanks.
- Jan 25, 2008
How to decide input mode, DI or SE?
- Nov 13, 2007
very helpful, would like to see more on
this topic.
- Aug 16, 2007
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).

