Musical Signal Processing With LabVIEW
Musical Signal Processing With LabVIEW
By:
Ed Doering
By:
Ed Doering
Online:
< http://cnx.org/content/col10440/1.1/ >
CONNEXIONS
Rice University, Houston, Texas
This selection and arrangement of content as a collection is copyrighted by Ed Doering. It is licensed under the
Creative Commons Attribution 2.0 license (http://creativecommons.org/licenses/by/2.0/).
Collection structure revised: July 18, 2007
PDF generated: February 3, 2011
For copyright and attribution information for the modules contained in this collection, see p. 32.
Table of Contents
1 Programming Tutorials
2 Getting Started with LabVIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3 Editing Tips for LabVIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4 Essential Programming Structures in LabVIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
5 Create a SubVI in LabVIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
6 Arrays in LabVIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
7 Audio Input and Output
8 Audio Output Using LabVIEW's "Play Waveform" Express VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
9 Audio Sources in LabVIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
10 Reading and Writing Audio Files in LabVIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
11 Real-Time Audio Output in LabVIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Attributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
iv
Chapter 1
Programming Tutorials
Chapter 2
2.1 Overview
LabVIEW for audio and signal processing applications! This module
screencast videos, meaning that the videos were captured directly from my computer screen.
As I operate the LabVIEW software, I explain each step and discuss what is going on. After you watch each
of the videos, you will possess a good idea of some fundamental LabVIEW concepts, including:
Laboratory Virtual
Macintosh) to control and gather data from electronic instrumentation (voltmeters, oscilloscopes, and the
like) all interconnected by the standard General Purpose Instrumentation Bus, or GP-IB. From its incep-
wires,
which looks just a traditional electronic instrument, i.e., it can have knobs, sliders, buttons, and display
panels. The complete application is called a
LabVIEW has since evolved into a complete programming environment; anything that you can imagine
can probably be implemented in LabVIEW. Recent versions of LabVIEW have added a full suite of tools for
doing signal processing, and since soundcard operations are provided, it becomes natural to develop audio
signal processing applications in LabVIEW.
LabVIEW's interactive front panel oers a unique opportunity to explore signal processing concepts in
real time.
As you work your way through other modules in this series, you will learn how to implement
your own applications whose user interface consists of knobs, sliders and switches that can adjust processing
parameters
1 This
While Loop
Figure 2.1:
to make forward progress learning about LabVIEW to create your own applications. Dataow programming
means that valid data must be present at
all
of the input
terminals
node (or subVI) will produce valid data on its output terminals. Moreover, the node (or subVI) does
not
continually process its inputs data unless it is embedded in some sort of looping structure.
Click on the following animation of the dataow concept to watch a screencast video that explains and
further explores the dataow programming concept.
Figure 2.2:
The following
screencast video will acquaint you with the oating point and integer styles of numeric data type, as well
as the Boolean data type.
dot that ags a mismatch on data types applied to the input of a node or subVI as well as
conversion nodes that you can use to intentionally convert a value from one data type to another.
Figure 2.3:
number of causes, and it is important to understand why the wire is broken and how to correct the situation.
The following screencast describes broken wires in detail.
Figure 2.4:
Highlight Execution feature, using the Retain Wire Values feature, single-stepping, viewing wire
values using probes, and creating breakpoints to pause execution when new data is available on a wire.
the
Figure 2.5:
programming techniques and get a better idea of everything that LabVIEW has to oer.
Once you have developed some skill with LabVIEW, consider Peter A. Blume's text,
The LabVIEW
2 http://www.ni.com/
3 http://www.ni.com/academic/
4 http://zone.ni.com/devzone/cda/main
Chapter 3
3.1 Overview
LabVIEW oers an extensive range of techniques to create and edit block diagrams and front panels. This
screencast video reviews some of the commonly-used editing techniques, including:
icons
text labels
Figure 3.1:
1 This
Chapter 4
4.1 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
a block of code a xed number of times, a
condition is true, and a
While Loop
For Loop
repeats
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
to develop a customized node whose behavior is dened 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:
1 This
10
Figure 4.1:
11
For Loop
Figure 4.2:
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
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
Figure 4.3:
its subdiagram as long as a particular condition is true. The following screencast will show you how to use
the
Figure 4.4:
12
Case Structure
selector terminal.
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.
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
string and enumerated data types, which provide a user-friendly way to
[video] LabVIEW Techniques: Case Structure with "Boolean" and "integer" data types
at the selector terminal
Figure 4.5:
[video] LabVIEW Techniques: Case Structure with "string" and "enumerated" data types
at the selector terminal
Figure 4.6:
MathScript Node oers a convenient way to implement a programming concept that may be otherwise
dicult to implement using standard G code (i.e., creating LabVIEW block diagrams by wiring available
structures and nodes).
MATLAB.
If you have prior experience with MATLAB, you can easily develop and debug a MathScript-
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.
through the process to create a specialized node that accepts a scalar N as input and produces a specialized
array as output.
13
Figure 4.7:
The screencast in this section (just above) describes how to build a VI that includes a
MathScript node.
Figure 4.8:
Diagram Disable
Figure 4.9:
of code
14
Chapter 5
subVI
languages.
subVI one time updates its behavior for all VIs that use the subVI, which simplies program design and
maintenance. Moreover, the subVI forms the basic method by which you can create a hierarchical program.
The screencast video below details the necessary steps to convert a conventional block diagram into a
subVI by adding a
as an element on another block diagram with a connection pattern specic to the requirements of the task
performed by the subVI. In addition, you can set the
subVI so that hovering your cursor over your subVI reveals a helpful description of its behavior.
Figure 5.1:
1 This
16
Chapter 6
Arrays in LabVIEW
6.1 Overview
Arrays are a fundamental data type for signal processing.
to create and manipulate arrays, and to perform mathematical and signal processing operations on arrays.
This module will acquaint you with the basic techniques for working with arrays.
Figure 6.1:
dimensions
1 This
reshaping
arrays.
17
subarrays,
18
Figure 6.2:
Important side eects (such as what happens when two arrays of dierent lengths are added to-
Figure 6.3:
Figure 6.4:
Chapter 7
19
20
Chapter 8
8.1 Overview
Play
Waveform Express VI. The screencast video shows how to listen to an audio signal source (a sinusoid in this
example). The 1-D array must rst be converted to the waveform data type using the Build Waveform
A 1-D array representing an audio signal can be played directly by the computer's soundcard using the
node.
Figure 8.1:
1 This
22
Chapter 9
9.1 Overview
Sine Wave subVI in the Signal Processing palette is a useful way to produce a sinusoidal audio signal.
normalized
frequency. This subVI is one of several re-entrant signal generators, meaning that they have the ability
The
The screenscast video will acquaint you with the Sine Wave subVI, especially its requirement for
to pick up where they left o; that is, they can maintain continuity in their output across execution runs
and loop iterations.
Figure 9.1:
1 This
24
Chapter 10
10.1 Overview
LabVIEW oers a variety of ways to read and write audio les in WAV format.
module you will be able to use the
| Graphics & Sound | Sound | Files palette to retrieve an audio signal as a 1-D array from a .wav le, and
also to save a 1-D array that represents an audio signal to a .wav le. Additional points covered include
scaling your audio signal to have a maximum absolute value of one before saving as an audio le, and how
to create a two-channel (stereo) audio le.
subVI accepts a lename for an audio le in .wav format and returns a
waveform data type. You can read mono or stereo les, and also determine information such as the audio
signal's sampling frequency and its total number of samples.
The following video screencast shows how to use
Simple Read
data type that can be used as a signal input for your own VIs. You may want to start LabVIEW now, then
follow along to create your own version of the VI pictured below. If so, you will need the two audio les
referenced in the screencast: tone-noise.wav
Figure 10.1:
2 and left-right.wav3 .
25
26
subVI accepts a signal in waveform data type and a lename and stores
the signal as a .wav le. You can set the number of bits per sample (16 is recommended for best delity).
You must ensure that your signal values lie in the range -1 to +1, otherwise other applications may not be
able to read your .wav le properly.
The next video screencast shows how to use
an audio signal to a .wav le.
to create your own version of the VI pictured below. If so, you will need the audio le referenced in the
screencast: tone-noise.wav .
Figure 10.2:
Quick Scale is an easy way to scale your 1-D array such that the
Quick Scale is located in the Signal Processing | Sig Operation
palette, and should be used as the last step before converting to the waveform data type.
Figure 10.3:
le
[video] LabVIEW Techniques: Scale audio signal to +/- 1 range before saving to a .wav
4 See
27
Figure 10.4:
[video] LabVIEW Techniques: Save a stereo (two-channel) audio signal to a .wav le
28
Chapter 11
11.1 Overview
The interactive front panel is a hallmark of the LabVIEW programming paradigm. In this screencast video
you will learn how to use the low-level
Sound Output
subVIs called
Congure, Write,
and
Clear
to
build a general-purpose framework that can continually produce audio output, all the while responding to
parameter changes on the front panel in real time. The example uses a sinusoidal source, but you can easily
adapt the VI for your own signal sources; the nished VI from this example is available: lvt_audio_realtime-
out.vi
Figure 11.1:
INDEX
30
Keywords
do not necessarily appear in the text of the page. They are merely associated with that section.
apples, 1.1 (1)
A aligning, 3(7), 7
array, 6(17)
front panel, 3
function, 5(15)
G graphical, 3
H help page, 7
Highlight Execution, 5
B block, 3
icons, 3(7), 7
breakpoints, 5
index, 6(17)
indexing, 11
integer, 12
interactive, 11(29)
Clear, 29
iterator, 11
coercion indicator, 4
congure, 11(29), 29
constants, 3(7), 7, 7
icon, 15
icon editor, 5(15)
Boolean, 4, 12
concatenated, 11
M MathScript, 12
CSV, 6(17)
Ctrl+B, 7
moving, 3(7), 7
debugging, 2(3)
nodes, 3
decorations, 3(7), 7
diagram, 3
numeric, 4
Play Waveform, 21
Play Waveform Express VI, 8(21)
probes, 5
exponential, 18
distributing, 7
enumerated, 12
feedback node, 11
Ex.
apples, 1
INDEX
real-time audio, 11(29)
string, 4, 12
removing, 7
subarray, 6(17)
replace, 3(7)
subarrays, 17
replacing, 3(7), 7, 7
subdiagram, 11, 11
replicating, 3(7), 7
subroutine, 5(15)
reshape, 6(17)
subVI, 5(15), 15
reshaping, 17
subVIs, 3
31
terminal, 7
scaling, 10(25)
terminals, 4, 5(15)
screencast, 3
selector terminal, 12
Simple Read, 25, 25
Simple Write, 25, 26
sine wave, 9(23), 23
single-stepping, 5
sinusoid, 9(23)
Sinusoidal source, 8(21)
Sound File Simple Read, 25
Sound File Simple Write, 26
Sound Output, 11(29), 29
soundcard, 8(21)
spreadsheet, 6(17)
stereo, 10(25)
V VI, 3
VI Description, 15
VI Properties, 15
virtual instrument, 3
virtual instrument (VI), 2(3)
ATTRIBUTIONS
32
Attributions
Collection:
ing
Musical Signal Processing with LabVIEW Programming Techniques for Audio Signal Process-
ATTRIBUTIONS
Module: "Audio Sources in LabVIEW"
By: Ed Doering
URL: http://cnx.org/content/m14770/1.3/
Page: 23
Copyright: Ed Doering
License: http://creativecommons.org/licenses/by/2.0/
Module: "Reading and Writing Audio Files in LabVIEW"
By: Ed Doering
URL: http://cnx.org/content/m14771/1.6/
Pages: 25-27
Copyright: Ed Doering
License: http://creativecommons.org/licenses/by/2.0/
Module: "Real-Time Audio Output in LabVIEW"
By: Ed Doering
URL: http://cnx.org/content/m14772/1.5/
Page: 29
Copyright: Ed Doering
License: http://creativecommons.org/licenses/by/2.0/
33
Musical Signal Processing with LabVIEW Programming Techniques for Audio Signal Processing
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 this course
make extensive use of "screencasts" videos captured directly from the computer screen that show the LabVIEW tool in operation, with audio narration to explain each step. The course includes a "Getting Started"
tutorial, editing tips, essential programming structures, subVIs, arrays, audio sources, audio output to the
soundcard, reading and writing audio les, and real-time audio output with interactive parameter control.
This course is part of the series "Musical Signal Processing with LabVIEW".
About Connexions
Since 1999, Connexions has been pioneering a global system where anyone can create course materials and
make them fully accessible and easily reusable free of charge. We are a Web-based authoring, teaching and
learning environment open to anyone interested in education, including students, teachers, professors and
lifelong learners. We connect ideas and facilitate educational communities.
Connexions's modular, interactive courses are in use worldwide by universities, community colleges, K-12
schools, distance learners, and lifelong learners.
English, Spanish, Chinese, Japanese, Italian, Vietnamese, French, Portuguese, and Thai. Connexions is part
of an exciting new information distribution system that allows for
Connexions
has partnered with innovative on-demand publisher QOOP to accelerate the delivery of printed course
materials and textbooks into classrooms worldwide at lower prices than traditional academic publishers.