Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Tutorial
NI Supported: Yes
Publish Date: Sep 26, 2007

Inside LabVIEW MathScript

17 ratings | 4.53 out of 5
Read in | Print

Overview

In National Instruments LabVIEW, you have freedom to choose the syntax you use for technical computing, whether you are developing algorithms, analyzing results, processing signals, or exploring DSP concepts. You can combine intuitive LabVIEW graphical programming with MathScript, a math-oriented text-based programming language that utilizes .m file script syntax and includes more than 700 commonly used functions for math, signal processing and analysis.

What Is NI LabVIEW MathScript?

LabVIEW MathScript adds math-oriented, textual programming to LabVIEW. MathScript joins graphical 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. As we will explore in this paper, the significance of LabVIEW and MathScript lies in this “best of both worlds” approach that it facilitates.

At the heart of 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 more than 700 built-in functions for such work you can also create your own new user-defined functions.

MathScript Language Feature Description
Powerful Textual Math MathScript includes more than 700 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 data types MathScript uses matrices and arrays as fundamental data types, 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. 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 third-party software to compile and execute
Table 1: Features of MathScript make it useful as a textual language for signal processing, analysis and math.

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 web sites that distribute open-source .m file scripts.

See Also

MathScript

Working with MathScript

You can work with LabVIEW MathScript through both interactive and programmatic interfaces. For an interactive interface in which you can load, save, design, and execute .m file scripts, you can work with the MathScript Interactive Window. To deploy your .m file scripts as part of a LabVIEW application and combine graphical and textual programming, you can work with the MathScript Node.

Using the MathScript Interactive Window

The LabVIEW MathScript Window (shown in Figure 1) offers an interactive interface in which you can enter .m file script commands and see immediate results, variables and commands history. The window includes a command-line interface where you can enter commands one-by-one for quick calculations, script debugging or learning. Alternatively, you can enter and execute groups of commands through a script editor window.

As you work, a variable display updates to show the graphical / textual results and a history window tracks your commands. The history view facilitates algorithm development by allowing you to use the clipboard to reuse your previously executed commands.


[+] Enlarge Image
Figure 1. The MathScript Window provides an interactive interface in which you can enter / execute commands and immediately see results.

Using the MathScript Node

The MathScript Node offers an intuitive means of combining graphical and textual code within LabVIEW. Figure 2 shows the MathScript Node on the block diagram, represented by the blue rectangle. Using MathScript Nodes, you can enter .m file script text directly or import it from a text file.

Figure 2
Figure 2. With the MathScript node, you can easily integrate textual math commands with graphical programming.

You can define named inputs and outputs on the MathScript Node border to specify the data to transfer between the graphical LabVIEW programming and the textual MathScript code. Figure 2 shows variable inputs on the left side of the MathScript Node named fstoplow, fpasslow, and taps that input these parameters to the .m file script. The MathScript Node contains output variables, F and sH, to transfer the array-based result to the LabVIEW graphical code.

You can associate .m file script variables with LabVIEW graphical programming, by wiring Node inputs and outputs. Then you can transfer data between mfile scripts with your graphical LabVIEW programming. The textual .m file scripts can now access features from traditional LabVIEW graphical programming.

See Also

LabVIEW: Intuitive Graphical Programming Language for Scientists and Engineers

Instrument Your Algorithms

One benefit of working with the MathScript Node is the ability to easily “instrument your algorithms” by using powerful, built-in LabVIEW tools for defining custom interactive user interfaces. You can create custom, interactive user interfaces for .m file script algorithms by associating the variables of your textual .m file script code with LabVIEW controls and indicators such as knobs, sliders, buttons, and 2D/3D plots, shown in Figure 3.

You can wire MathScript Nodes to any of hundreds of ready-to-use user interface elements that are shipped with LabVIEW, including graphs, charts, knobs, dials, and thermometers, to implement custom user interfaces for your .m file scripts.

 Figure 3
Figure 3. You can instrument your .m file scripts by using built-in user-interface elements available within LabVIEW.

Graphical Signal Processing, Analysis, and Math

Plugging textual .m file scripts into LabVIEW graphical code with the MathScript Node also provides access to an extensive library of graphical tools for signal processing, analysis, and math. LabVIEW has more than 700 graphical Virtual Instruments with functionality covering such areas as:

  • Signal Processing: Signal Generation, Signal Conditioning, Monitoring, Digital Filtering, Windowing, and Spectral Analysis
  • Mathematics: Transforms, Curve Fitting, Interpolation/Extrapolation, Probability/Statistics, Optimization, Ordinary Differential Equations, Geometry, Polynomial Functions, 1D/2D Evaluation, and Calculus

Employing Measurement Hardware

Another benefit of merging textual with graphical programming using the MathScript Node is simplified data acquisition, signal generation and instrument control. .m file scripts that execute from within MathScript Nodes can use hardware control capabilities that are a pervasive part of the LabVIEW development environment. The graphical environment naturally manages continuous data acquisition operations and saves significant time for developers. LabVIEW sets the standard for integration with measurement hardware by providing support for:

  • More than 100 plug-in data acquisition devices
  • More than 5,000 stand-alone instruments from more than 200 vendors
  • More than 1,200 PXI-based modular devices from more than 70 vendors
  • More than 10,000 supported sensors from more than fifteen 3rd party plug&play sensor vendors
  • More than 1,000 motion stages and drives
  • More than 400 industrial and scientific cameras

Integrating Software Components

You can take advantage of the MathScript Node to bridge the gap between .m file scripts and external software or data. As a widely used development platform for a variety of applications and disciplines, LabVIEW offers a broad collection of software integration tools, libraries, and file formats to link it with many different design and simulation tools. LabVIEW also offers connectivity to a variety of software standards for integration with other software tools and packages, or with such measurement resources as:

  • DLLs, shared libraries
  • ActiveX, COM and .NET (Microsoft)
  • DDE, TCP/IP, UDP, Ethernet, Bluetooth
  • CAN, DeviceNet, ModBus, OPC
  • USB, IEEE 1394 (FireWire), RS232/485, GPIB
  • Databases (ADO, SQL, etc.)

Exploring Internet-Based Remote Panels and Distance-Learning Tools

Other connectivity options enabled by the MathScript Node go beyond local software or hardware. .M file scripts can employ LabVIEW features such as the remote panel to allow remote web-based control—with no additional programming. You can embed your custom LabVIEW user interfaces in a standard Web browser, with only two mouse clicks. Users then can control your applications remotely from a standard Web browser without installing LabVIEW. This feature is especially important for distance learning remote experiments, where professors can enhance lectures with live demonstrations, students can access laboratories after hours, and researchers can share costly equipment and collaborate on research.

Conclusion

LabVIEW MathScript complements traditional LabVIEW graphical programming for such tasks as algorithm development, signal processing, and analysis. LabVIEW MathScript speeds up these and other tasks by giving users a single environment in which they can choose the most effective syntax, whether textual, graphical, or a combination of the two. In addition, because MathScript is generally compatible with the .m file script syntax, you can exploit the best of LabVIEW and thousands of publicly available .m file scripts from the web, textbooks, or your own existing m-script applications.

See Also

LabVIEW MathScript

Note

MATLAB® is a registered trademark of The MathWorks, Inc. All other trademarks are the property of their respective owners.

17 ratings | 4.53 out of 5
Read in | Print

Reader Comments | Submit a comment »

 

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/).