Skip to content Skip to navigation

Connexions

You are here: Home » Content » Essential Programming Structures in LabVIEW

Navigation

Lenses

What is a lens?

Definition of a lens

Lenses

A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual Connexions member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

This content is ...

Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
  • Featured Content display tagshide tags

    This module is included inLens: Connexions Featured Content
    By: ConnexionsAs a part of collection:"Musical Signal Processing with LabVIEW -- Programming Techniques for Audio Signal Processing"

    Click the "Featured Content" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

  • National Instruments display tagshide tags

    This module is included in aLens by: National InstrumentsAs a part of collections:"Musical Signal Processing with LabVIEW -- Programming Techniques for Audio Signal Processing", "Musical Signal Processing with LabVIEW (All Modules)"

    Comments:

    "After completing this multi-media course you will be well-equipped to start creating your own audio and signal processing applications within the LabVIEW development environment. The modules in […]"

    "Developed by Rose Hulman Prof Ed Doering, this collection is a multimedia educational resource for students and faculty that augments traditional DSP courses and courses that cover music […]"

    Click the "National Instruments" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

Also in these lenses

  • richb's DSP display tagshide tags

    This module is included inLens: richb's DSP resources
    By: Richard BaraniukAs a part of collection:"Musical Signal Processing with LabVIEW -- Programming Techniques for Audio Signal Processing"

    Comments:

    "A great course on LabVIEW based signal processing using music and audio as motivation."

    Click the "richb's DSP" link to see all content selected in this lens.

    Click the tag icon tag icon to display tags associated with this content.

  • NI Signal Processing display tagshide tags

    This module is included inLens: Digital Signal Processing with NI LabVIEW and the National Instruments Platform
    By: Sam ShearmanAs a part of collections:"Musical Signal Processing with LabVIEW -- Programming Techniques for Audio Signal Processing", "Musical Signal Processing with LabVIEW (All Modules)"

    Comments:

    "This online course covers signal processing concepts using music and audio to keep the subject relevant and interesting. Written by Prof. Ed Doering from the Rose-Hulman Institute of Technology, […]"

    Click the "NI Signal Processing" link to see all content selected in this lens.

    Click the tag icon tag icon to display tags associated with this content.

Recently Viewed

This feature requires Javascript to be enabled.

Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.

Essential Programming Structures in LabVIEW

Module by: Ed Doering. E-mail the author

User rating (How does the rating system work?)
Ratings

Ratings allow you to judge the quality of modules. If other users have ranked the module then its average rating is displayed below. Ratings are calculated on a scale from one star (Poor) to five stars (Excellent).

How to rate a module

Hover over the star that corresponds to the rating you wish to assign. Click on the star to add your rating. Your rating should be based on the quality of the content. You must have an account and be logged in to rate content.

:
(1 ratings)

Summary: Learn how to work with LabVIEW's essential programming structures such as for-loops, while-loops, case structure, MathScript node, and diagram disable.

Overview

Signal processing applications developed in LabVIEW make frequent use of basic constructs that are common to all high-level programming languages: for-loops, while-loops, and case structures. A For Loop repeats a block of code a fixed number of times, a While Loop repeats a block of code as long as a particular condition is true, and a Case Structure executes one of several blocks of code depending on some selection criterion. After completing this module you will be able to use these three essential structures in your own LabVIEW VIs.

You will also learn about two additional structures. The MathScript Node provides a way for you to develop a customized node whose behavior is defined using the MathScript text-based programming language. MathScript syntax and functions are quite similar to MATLAB, so the MathScript node can help you to leverage any MATLAB programming experience you may have. Lastly, the Diagram Disable structure is useful when you need to temporarily “comment out” a portion of your LabVIEW code.

The following diagram highlights the structures on the “Programming | Structures” palette about which you will learn in this module:

Figure 1: Structures on the "Programming | Structures" palette described in this module
Figure 1 (graphics1.png)

For-Loop Structure

Basic concepts

The For Loop structure provides a means to repeatedly run a block of code (or subdiagram) for a fixed number of times. The following screencast video introduces the For Loop structure, including concepts such as loop count terminal, iterator, loop tunnel, indexing, shift register, and the feedback node.

Figure 2: [video] LabVIEW Techniques: For-Loop structure
Figure 2 (lvt_for-loop-basic.html)

Working with arrays as inputs

The For Loop structure works efficiently with arrays. The next screencast video describes how to work with arrays that serve as inputs to the for-loop structure. Array elements can be used individually or collectively within the for-loop, depending on whether you have enabled indexing on the loop tunnel. Indexing on the output side of the for-loop can also be used to store a value (either a scalar or an array) on each iteration of the for-loop, thereby producing an array as output. Arrays can also be concatenated, a standard technique for constructing an audio signal from individual segments.

Figure 3: [video] LabVIEW Techniques: For-Loop structure with arrays as input
Figure 3 (lvt_for-loop-arrays.html)

While-Loop Structure

The While Loop structure is similar to the For Loop structure with its ability to repeatedly run a subdiagram, but the number of times is not fixed in advance. Instead, the while-loop structure will execute its subdiagram as long as a particular condition is true. The following screencast will show you how to use the While Loop structure.

Figure 4: [video] LabVIEW Techniques: While-Loop structure
Figure 4 (lvt_while-loop.html)

Case Structure

The Case Structure provides a mechanism by which exactly one of several possible subdiagrams will be executed, depending on the value connected to the selector terminal. When the selector terminal is a Boolean type (either True or False), the case structure implements the “if-else” construct of text-based languages. When the selector terminal is an integer type, the case structure implements the “case” or “switch” construct of text-based languages.

The following screencast introduces you to the Case Structure. You will learn how to add and delete subdiagrams, how to choose the default subdiagram, and how to ensure that valid outputs are generated for all possible cases. The Boolean and integer data types are covered in this screencast; the next screencast describes how to work with the string and enumerated data types, which provide a user-friendly way to select cases from the front panel.

Figure 5: [video] LabVIEW Techniques: Case Structure with "Boolean" and "integer" data types at the selector terminal
Figure 5 (lvt_case-boolean-int.html)
Figure 6: [video] LabVIEW Techniques: Case Structure with "string" and "enumerated" data types at the selector terminal
Figure 6 (lvt_case-string-enum.html)

MathScript Node

The MathScript Node offers a convenient way to implement a programming concept that may be otherwise difficult to implement using standard G code (i.e., creating LabVIEW block diagrams by wiring available structures and nodes). MathScript is a text-based programming language that uses syntax very similar to MATLAB. If you have prior experience with MATLAB, you can easily develop and debug a MathScript-based script in the MathScript interactive window, then copy the text into a MathScript node on your block diagram. After you create input and output terminals on the MathScript node, it can be connected to the rest of the block diagram as you would any other structure.

The following screencast video introduces you to the MathScript Node. The example walks you through the process to create a specialized node that accepts a scalar N as input and produces a specialized array as output.

Figure 7: [video] LabVIEW Techniques: MathScript node and MathScript Interactive Window
Figure 7 (lvt_mathscript-node.html)

% Create a triangle array
x = [linspace(0,1,N/2) linspace(1,0,N/2)]

The screencast in this section (just above) walks through creation of a LabVIEW VI that includes a MathScript node that will invoke this .m file script.

Figure 8: The screencast in this section (just above) describes how to build a VI that includes a MathScript node.
Figure 8 (MathScriptNodeExercise.png)

Diagram-Disable Structure

You probably have used the software debugging technique known as “commenting out” a block of code; you do this so that you can effectively remove a portion of code without actually deleting it from the file. Watch the next screencast video to learn how to use the Diagram Disable structure to “comment out” a portion of your LabVIEW block diagram.

Figure 9: [video] LabVIEW Techniques: Use Diagram-Disable structure to "comment out" a section of code
Figure 9 (lvt_diagram-disable.html)

Content actions

Give Feedback:

E-mail the module author | Rate module ( How does the rating system work?)

Rating system

Ratings

Ratings allow you to judge the quality of modules. If other users have ranked the module then its average rating is displayed below. Ratings are calculated on a scale from one star (Poor) to five stars (Excellent).

How to rate a module

Hover over the star that corresponds to the rating you wish to assign. Click on the star to add your rating. Your rating should be based on the quality of the content. You must have an account and be logged in to rate content.

(1 ratings)

Download:

Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections directly in Connexions. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need a Connexions account to use 'My Favorites'.

| A lens (?)

Definition of a lens

Lenses

A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual Connexions member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks