Scientific Computing with NI LabVIEW

Publish Date: Sep 22, 2011 | 3 Ratings | 5.00 out of 5 |  PDF

Scientific Computing with LabVIEW


NI LabVIEW, a development environment based on the G programming language, is ideal for creating flexible and scalable design, measurement, control, and test applications rapidly and at minimal cost. Because of this, scientists can use it to interface with real-world signals, analyze and visualize data, and develop and prototype new algorithms; interface with external scientific computing libraries and text-based programming languages and scripts; and directly deploy the final application using commercial off-the-shelf (COTS) technology. Regardless of programming experience, LabVIEW makes development fast and easy for all users in the scientific community. But G is not the typical text-based programming language when combined with LabVIEW. LabVIEW G is a graphical programming language based on the dataflow model of execution.


Figure 1. G Graphical Programming and Data Flow

The basic concept of dataflow programming is that each node is enabled (executes) as soon as data is available at all of the node's inputs. This intrinsic architecture of LabVIEW and its G programming language is important for scientific computing applications because it allows nonprogrammers and domain experts to develop sophisticated, math-intensive applications that take advantage of parallel programming and parallel hardware.

Dataflow and Parallel Programming

You can easily map LabVIEW parallel code to parallel hardware with no knowledge of the low-level specifics of parallel programming. Therefore, LabVIEW G is an ideal development language for targeting multiprocessor, hyperthreaded, and multicore systems, all of which are common in the scientific computing environment. 

Figure 2. Scientific Computing with Multithreading, Multicore Systems

Multicore processors provide a faster platform for scientific computing − even faster than multiprocessor systems that use slower external communications. However, parallel programming with traditional text-based languages is not an easy task.

Figure 3. Dual Processors versus Dual-Core Processor

Because LabVIEW is a graphical programming language, domain experts can use it to easily develop and visualize parallel applications. In addition, LabVIEW automatically generates threads for parallel sections of code, so engineers and scientists with little or no programming background can spend more time problem solving and less time worrying about low-level implementation of their applications. To make a LabVIEW application “parallel,” programmers need to use some simple programming techniques, such as pipelining and multithreading programming, which requires little effort and no specialized knowledge from the programmer.

For example, an application to identify prime numbers greater than two is shown in Figure 4. The block diagram evaluates all the odd numbers between three and Num Terms, and determines if they are prime. The inner for loop returns TRUE if any number divides the term with a zero remainder. The inner for loop is computationally intensive because it does not include any I/O or wait functions. It executes fast, but the architecture of this VI prevents LabVIEW from taking advantage of any parallelism. There is a mandatory order for every operation in the loop. This order is enforced by data flow, and there is no other execution order possible because every operation must wait for its inputs.


Figure 4. This VI calculates prime numbers greater than two.

To introduce parallelism into this VI, you must make sure that no single loop iteration depends on any other loop iteration. If you meet that condition, you can distribute loop iterations between two loops. However, one LabVIEW constraint is that no iteration of a loop can begin before the previous iteration finishes. By splitting the process into two loops after, you achieve parallelism. One way to do this is by having one loop (top loop) evaluate half of the odd numbers and another loop (bottom loop) evaluate the other half.

Figure 5. This parallel VI calculates prime numbers greater than two in separate loops.

On a multicore computer, this two-loop version is more efficient because LabVIEW can simultaneously execute code from both loops. Notice that the output of this version of the VI has two arrays instead of one as in the previous example. You can write a subVI to combine these arrays and, because the calculations consume most of the execution time, the additional VI at the end of the process becomes negligible.

Data Acquisition

National Instruments offers the most complete family of data acquisition devices for desktop, portable, industrial, and embedded applications on several buses, including PCI, PCI Express, PXI, PCMCIA, USB, CompactFlash, Ethernet, and IEEE 1394, and many operating systems, including Windows, Linux®, Mac OS X, Pocket PC/Windows CE, and real-time OSs.

Data acquisition is the process of gathering or generating information in an automated fashion from analog and digital measurement sources such as sensors and devices under test. It uses a combination of PC-based measurement hardware and software to provide a flexible, user-defined measurement system. Oftentimes, you must condition sensors and signals before a data acquisition device acquires them. You can analyze and visualize the data in real time (online) while you are acquiring it. In the context of scientific computing, this concept is expanded to include previously acquired data, available in files, databases, and other forms of storage, from which data can be accessed for offline analysis and visualization.

Figure 6. Data Acquisition Model

You can choose from multiple data acquisition options featuring different form factors, characteristics, and specifications. Some data acquisition devices are intended to be plugged into a PCI, PCI Express, or PCMCIA slot of a PC, while others are external devices that you can connect to a PC via a USB, serial, or Ethernet port. Some of the external options are stand-alone-capable because they have their own CPU/memory and can execute code (EXEs) in real time (NI CompactRIO, PXI, Compact FieldPoint modules).


Figure 7. Data Acquisition Devices for USB, Ethernet, PCI, PCI Express, and PXI/CompactPCI

Another element to consider in the model shown in Figure 7 is signal conditioning, or SC. Signal conditioning is used for preconditioning the signal before it is processed by the data acquisition device (or after if it is an output signal). Among the signal conditioning functions are the following:

  • Amplification
  • Linearization
  • Simultaneous sampling
  • Isolation
  • Extended voltage
  • Attenuation
  • Filtering
  • Power supply for specialized circuits (strain gages, accelerometers, and so on)
  • Relay actuation

In most cases, some form of signal conditioning is required between the data acquisition hardware and the sensors/actuators. Some data acquisition devices already include built-in signal conditioning. However, in those cases where the signal conditioning functionality already included in the data acquisition device may not be sufficient or when it is simply absent, some type of external signal conditioning is required and recommended. For this purpose, several choices are available, including external options that are added to the data acquisition device (NI SCC, SCXI) and built-in options where the data acquisition device and the signal conditioning circuitry are integrated in the same device (NI C Series modules, SC Series boards, Compact FieldPoint modules).


Figure 8. External and Built-In Signal Conditioning Options

Some specialized devices, for applications such as dynamic signal acquisition or DSA (sound and vibration measurements), also include some built-in signal conditioning capabilities such as simultaneous sampling, precision current supply for sensors, antialiasing filters, and so on.


LabVIEW features an extensive analysis library (also known as the Advanced Analysis Library) and a wide variety of visualization tools that scientists and engineers can use to develop scientific computing-type applications in less time and with less effort through one common set of software tools that supports a wide variety of COTS-based hardware. The LabVIEW Advanced Analysis Library, which is incorporated in the standard LabVIEW Full and Professional development systems, includes the following functionality:

  • Curve fitting
  • Interpolation and extrapolation
  • Optimization
  • Linear algebra
  • Probability and statistics
  • Differential equation solvers
  • Signal processing
  • Integration and differentiation

Figure 9. Some of the Mathematical Functions Available in LabVIEW

As an example, you can easily solve a system of ordinary differential equations (ODEs) using one of the VIs or functions available in the Mathematics library included in LabVIEW Full and Professional development systems. Given the following system of ODEs ...

.... you can use the following “right sides” of the differential equations and initial conditions ...

  • Time start: 0.00
  • Time end: 50.00
  • X: [x, y, z]
  • X0: [1, 1, 1]
  • F(X,t):  [10*(y - x), x*(28 - z) - y, x*y - (8/3)*z]

... to find the solutions for x using the Runge-Kutta fourth-order method with a step size h = .1.

LabVIEW includes the following VI in the Mathematics library:


Figure 10. ODE Runge-Kutta 4th Order VI Available in the LabVIEW Advanced Analysis Library

With the following code, a solution is found:

Figure 11. G Program for Solving the Equation System Using the Runge-Kutta Fourth-Order Method


The solution for x is shown in the following graph:

Figure 12. Solution for x Using the Runge-Kutta Fourth-Order Method

One interesting feature is that the values of x, y and z in the code above can come directly from measurements captured online through the use of a data acquisition device, bringing live, real-world signals to mathematics.


Figure 13. Bringing “Live” Data to Mathematics

You can use a similar approach with partial differential equations (PDEs). For example, you can implement numerical solutions to the heat, wave, or Poisson equations, among others, using real-time data for controlling complex, multiphysics systems such as fusion nuclear reactors (tokamaks). Figure 14 shows a 3D surface plot of the solution for a 128-by-128 Poisson equation.

Figure 14. Online Solution (and Visualization) to the Poisson Equation


For visualization, LabVIEW also offers a wide variety of options, including the following:

  • 3D indicators/controls for numbers, text, and Booleans
  • 3D surface graphs
  • Charts, graphs, XY graphs, and intensity graphs
  • Bode, Nichols, Nyquist, Smith, radar, and polar plots
  • Image, video, and picture controls/indicators
  • Tables and matrix indicators/controls
  • Digital waveform and mixed-signal indicators
  • Line, column, and bar graphs
  • Time-frequency (spectrograms) and waterfall graphs

Figure 15. Some of the Visualization Tools Available in LabVIEW

LabVIEW provides  a wide selection of options to present your data. Another example of the visualization capabilities of LabVIEW is shown in Figure 16. This example shows how you can use the 3D Picture Toolkit and other features to create, import, and control 3D graphics for the realistic presentation of real-world objects.

Figure 16. 3D Image Rendering with LabVIEW and the 3D Picture Toolkit

One interesting feature in the above example (available at NI Labs at is the capability to connect real-world signals to the image via a data acquisition device. The color gradients in the image change with the sensor readings.

Connecting External Tools to LabVIEW

You can easily expand both this analysis and visualization functionality by either creating your own functions in G language, adding new toolkits to LabVIEW, using LabVIEW MathScript commands, or interfacing with third-party tools such as Maple, Mathcad, Mathematica, Scilab, GNU Octave, Microsoft Excel, and others.

You can achieve connectivity with these third-party tools through a Script Node, a special API, or standard interface mechanisms such as ActiveX, .NET, OPC, TCP/IP, or specific VIs created for this purpose. There are links and interfaces for dynamically exchanging data between LabVIEW and these or other commercial packages, tools, and scientific computing libraries.

More experienced programmers can call external scientific libraries from LabVIEW in the form of C code (*.h, *.c), DLLs, and CINs (C code compiled into CIN nodes). You can access popular scientific libraries such as LAPACK, FFTW, NAG, and others via external links or function library calls from/to LabVIEW.


By using an integrated development environment and programming language such as LabVIEW in scientific computing applications, you can take advantage of benefits including the following:

  • Compiled code speed through integrated development environment (LabVIEW) and graphical programming language (G)
  • Powerful, flexible, and scalable environment (open, connects to external libraries and third-party tools)
  • Easy to learn, use, maintain, and upgrade (intuitive graphical programming)
  • One tool for all needs (design, prototyping, and deployment)
  • Tight software-hardware integration (supports wide variety of data acquisition and control devices)
  • Multicore, symmetric multiprocessing-ready (intrinsic parallelism and real-time support, use of digital signal processors (DSPs), field-programmable gate arrays (FPGAs), and GPUs as coprocessors)
  • Multiplatform (Microsoft Windows, Apple Mac OS, Linux, RTOSs)
  • Longevity (COTS-based, more than 20 years of evolution)
  • Capable of executing complex algorithms in real time (ODEs, PDEs, linear algebra, optimization, and so on) using real-world signals (A/D)
  • Multidisciplinary use (same easy graphical programming language for different applications and domain experts in different disciplines)
  • Same language used in industry (academic-to-industry transition more transparent)

Related Links

Scientific Computing with Graphical System Design

Multicore Programming

Visualization and Imaging

Introduction to G Programming

Introduction to Curve Fitting

Statistical Analysis

Scripting Languages and NI LabVIEW


Linux® is the registered trademark of Linus Torvalds in the U.S. and other countries.


Back to Top

Bookmark & Share


Rate this document

Answered Your Question?
Yes No