<< Chapter < Page Chapter >> Page >
Learn how to work with LabVIEW's essential programming structures such as for-loops, while-loops, case structure, MathScript node, anddiagram 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:

Structures on the "Programming | Structures" palette described in this module

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 .

[video] LabVIEW Techniques: For-Loop structure

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.

[video] LabVIEW Techniques: For-Loop structure with arrays as input

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.

[video] LabVIEW Techniques: While-Loop structure

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.

[video] LabVIEW Techniques: Case Structure with "Boolean" and "integer"data types at the selector terminal
[video] LabVIEW Techniques: Case Structure with "string" and "enumerated"data types at the selector terminal

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.

[video] LabVIEW Techniques: MathScript node and MathScript Interactive Window
% 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.
The screencast in this section (just above) describes how to build a VI that includes a MathScript node.

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.

[video] LabVIEW Techniques: Use Diagram-Disable structure to "comment out" a section of code

Questions & Answers

what is mutation
Janga Reply
what is a cell
Sifune Reply
how is urine form
Sifune
what is antagonism?
mahase Reply
classification of plants, gymnosperm features.
Linsy Reply
what is the features of gymnosperm
Linsy
how many types of solid did we have
Samuel Reply
what is an ionic bond
Samuel
What is Atoms
Daprince Reply
what is fallopian tube
Merolyn
what is bladder
Merolyn
what's bulbourethral gland
Eduek Reply
urine is formed in the nephron of the renal medulla in the kidney. It starts from filtration, then selective reabsorption and finally secretion
onuoha Reply
State the evolution relation and relevance between endoplasmic reticulum and cytoskeleton as it relates to cell.
Jeremiah
what is heart
Konadu Reply
how is urine formed in human
Konadu
how is urine formed in human
Rahma
what is the diference between a cavity and a canal
Pelagie Reply
what is the causative agent of malaria
Diamond
malaria is caused by an insect called mosquito.
Naomi
Malaria is cause by female anopheles mosquito
Isaac
Malaria is caused by plasmodium Female anopheles mosquitoe is d carrier
Olalekan
a canal is more needed in a root but a cavity is a bad effect
Commander
what are pathogens
Don Reply
In biology, a pathogen (Greek: πάθος pathos "suffering", "passion" and -γενής -genēs "producer of") in the oldest and broadest sense, is anything that can produce disease. A pathogen may also be referred to as an infectious agent, or simply a germ. The term pathogen came into use in the 1880s.[1][2
Zainab
A virus
Commander
Definition of respiration
Muhsin Reply
respiration is the process in which we breath in oxygen and breath out carbon dioxide
Achor
how are lungs work
Commander
where does digestion begins
Achiri Reply
in the mouth
EZEKIEL
what are the functions of follicle stimulating harmones?
Rashima Reply
stimulates the follicle to release the mature ovum into the oviduct
Davonte
what are the functions of Endocrine and pituitary gland
Chinaza
endocrine secrete hormone and regulate body process
Achor
while pituitary gland is an example of endocrine system and it's found in the Brain
Achor
what's biology?
Egbodo Reply
Biology is the study of living organisms, divided into many specialized field that cover their morphology, physiology,anatomy, behaviour,origin and distribution.
Lisah
biology is the study of life.
Alfreda
Biology is the study of how living organisms live and survive in a specific environment
Sifune
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Musical signal processing with labview -- programming techniques for audio signal processing. OpenStax CNX. Jul 18, 2007 Download for free at http://cnx.org/content/col10440/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Musical signal processing with labview -- programming techniques for audio signal processing' conversation and receive update notifications?

Ask