Sei sulla pagina 1di 47

Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 1



BASIC LABVIEW CONCEPTS
1.1 What is LabVIEW?
At the end of this lesson, the student shall be able to:
a. explain the concept of virtual instrumentation and raphical prorammin! and
b. understand the uses and capabilities of LabVIEW.
LabVIEW is the short name for Laboratory Virtual Instrument Engineering Workbench. It is a
prorammin environment in "hich #ou create prorams usin a raphical notation. $nli%e the traditional
text&based prorammin lanuaes, li%e ', '((, )ava, or *A+LA,, #ou proram in LabVIEW raphicall#,
that is functions are represented as nodes "ith inputs and outputs, and are "ired throuh "hich data flo"s.
,ein a prorammin lanuae, LabVIEW can be used to develop applications similar to "hat can be
developed usin text&based prorammin lanuae. -o"ever, more than bein a prorammin lanuae,
LabVIEW can be used to do the follo"in:
ac.uire data from instruments or enerate data usin sinal eneration functions!
anal#/e data!
process data 0e.. filterin, transforms, etc.1! and
control instruments and e.uipment.
Enineers and scientists use LabVIEW to brin information from the outside "orld into a computer usin
data ac.uisition 02A31 devices, process these data, and present these data to the user. +hus, LabVIEW
can be used to create virtual instruments 0VI1.
A virtual instrument is a computer proram that imitates the functionalit# of the real&"orld ph#sical
instrument. +hese virtual instruments can also ta%e in external data and do somethin about these data,
4ust as ho" a standard instrument "ill "or%. +hese VIs ho"ever has the inherent advantae of bein
flexible in terms of its use. ,ein virtual, these instruments5 functionalities are bein prorammed, and
hence can be chaned "henever "anted and needed. In most cases, virtual instrumentation also results to
lo"er costs, as a sinle set of hard"are 0a 2A3 device, a computer, and a soft"are1 can be confiured to
perform man# instrumentation tas%s that re.uire multiple ph#sical instruments.
A LabVIEW proram is also called a virtual instrument or VI.
*oreover, LabVIEW can also be used to simulate processes and control external instruments and
e.uipment. +hus, LabVIEW is ver# useful in the field of instrumentation and control.
Eam!le "#"
1. 6pen LabVIEW 7817 0via the des%top shortcut or the 9tart menu1 and on the openin "indo", clic%
$el! and choose %in& Eam!les'.
7. 6n the NI Eam!le %in&er "indo", choose the Search tab, t#pe in Simulation ( Tank Le)el in the
Enter key*or&+s, field and clic% Search. +he Simulation ( Tank Le)el#)i must appear at the results
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 2

field. 2ouble clic% it to open the VI.
:. ;ress the "hite arro" icon 0the -un icon1 on the VI to run the VI.
<. 'lic% the $V"./ valve to ma%e it blac% and the LCV"." to ma%e it reen. +his step basicall# opens an
input valve to let fluid flo" into the tan% 0the reen valve1 and a drain valve 0the blac% valve1 to drain
fluid out of the tan%. +he tan% has an inherent slo" lea% drain.
=. +he ob4ective of the control of the s#stem is to %eep the level of the fluid inside the tan% 0the process
variable PV1 the same as the Set!oint 09;1. +he deree b# "hich the controller reacts is indicated b#
the value of the Out!ut 0the reater the difference bet"een the ;V and 9V, the reater the output of
the controller1. +hus, "hen #ou chane the value of the setpoint, the level of the tan% should follo"
throuh 0tr# chanin the setpoint from =8 to 18 and from 18 to >8! observe ho" the output of the
controller chanes "ith these1.
?. +urn off the $V"./ valve and chane the setpoint from >8 do"n to <8. 6bserve ho" the ;V value
chanes as compared ho" it chaned in the previous step.
>. ;la# around "ith the other parameters of the VI 0li%e the PI0 !arameters1 and observe ho" the ;V
chanes "ith the chanes in setpoint.

LabVIEW uses a ver# po"erful raphical prorammin lanuae "hich most LabVIEW users refer to as @
for raphical 0the term is in reference to the ' prorammin lanuae1. ;rorams are created in pictorial
form called a block &iagram. 6ne advantae it offers is that the developer does not need to %no"
s#ntactical details associated "ith text&based prorammin lanuaes. +he developer 4ust needs to
connect functional nodes and ho" data flo"s from one node to another. -o"ever, those that are used to
"or%in "ith text&based lanuaes ma# need time to ad4ust to LabVIEW5s st#le of prorammin 0a personal
experienceA1.
Eam!le "#/
When #ou opened the Simulation ( Tank Le)el#)i, the 1ront !anel 0or %P1 appeared. +o displa# the
source code or the block &iagram 0B01, press Ctrl2E. Bou need not %no" ho" does this ,2 "or%s at this
point, but #ou can examine the composition of this ,2 b# turnin on the 'ontext -elp 0via Ctrl2$1, and
then hoverin the mouse over the icons.
1. Cind out "hat functional nodes do this ,2 contain.
7. What does the ra# line that bounds the bloc%s represent?

9top the VI b# pressin the Abort eecution icon on either the C; or the ,2.

0rill Problems "#"
1. 2iscuss "hat is meant b# virtual instrumentation and ho" LabVIEW facilitates development of virtual
instruments. What are the advantaes and disadvantaes of usin virtual instruments?
7. Explain "hat raphical prorammin is and ho" it accelerates development of s#stems.
:. Enumerate the uses and capabilities of LabVIEW.

Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 3

Sel1 Assessment3 Date #our level of achievement for the follo"in outcomes:
Outcome
Can4t &o

+.,
5arginal
Per1ormance
+",
Acce!table
Per1ormance
+/,
Ece!tional
Per1ormance
+6,
Explain the concept of virtual
instrumentation and raphical prorammin

$nderstand the uses and capabilities of
LabVIEW.

Write #our o"n thouhts and reflections on this topic.

1.7 +he LabVIEW environment
At the end of this lesson, the student shall be able to identif# parts of and naviate throuh the LabVIEW
environment.
When the LabVIEW is opened, a Welcome screen 0or the @ettin 9tarted "indo" in older versions1
appears, as sho"n belo"

Figure 1. 1 The LabVIEW 2012 welcome screen.
+o start usin LabVIEW, one can either choose to clic% the Blank VI, clic% on the %ile 77 Ne* VI menu or
press Ctrl2N to open a ne", blan% VI. +his opens up t"o "indo"s: the 1ront !anel 0%P1 and the block
&iagram 0B01, as sho"n in the fiures belo":
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 4


Figure 1. 2. The front panel.

Figure 1. 3. The bloc !iagram.
Each "indo" contains different set of menus. +he menus pop out "hen #ou riht&clic% on an empt# field in
a "indo". We first discuss the front panel and its menus.
+he front panel is the "indo" throuh "hich the user interacts "ith the proram. +his is the "indo" "here
the user "ould input into the VI and also "here the output is displa#ed. When #ou riht&clic% on an empt#
field in the front panel, the Controls palette appears as sho"n in the fiure belo".
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 5


Figure 1. ". The controls palette with the #o!ern controls palette selecte!.
+his set of menus contains the controls and indicators for the front panel. In LabVIEW, controls are used
as inputs into the VI, "hile in&icators are used as outputs of the VI. Bou can pin this menu to the front
panel b# clic%in the pin icon on the top left corner of the menu. Bou can unpin it b# clic%in the close
button at the top riht corner of the menu "hen it is pinned. Bou can also clic% Vie* 77 Controls Palette
on the menu bar of the front panel so that the controls palette "ill appear. Bou can use the Search button
"hen findin for a front panel ob4ect. +o et information about a certain ob4ect, press Ctrl2$ and hover the
mouse over the ob4ect #ou "ish to have more information about.
'ontrols are t#picall# %nobs, push buttons, dials, sliders, and strins. 'ontrols simulate instrument input
devices and suppl# data to the bloc% diaram of the VI. Indicators are t#picall# raphs, charts, LE2s, and
status strins. Indicators simulate instrument output devices and displa# data the bloc% diaram ac.uires or
enerates.
Eam!le "#6
Cind and place the follo"in ob4ects into the front panel, and find out some information about each.
1. Eumerical control and numerical indicator.
7. -ori/ontal and vertical slide s"itches.
:. A s.uare LE2 and round LE2.
<. A %nob and a dial.
=. A strin and a rin control.
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 6

?. A strin and a file path indicator.
>. A chart and a raph.

'lose the VI "ithout savin #our "or%. +hen open a ne" blan% VI aain.

+he fiure belo" sho"s the menu icons for runnin and arranin the ob4ects in the front panel.

Figure 1. $. #enu icons in the front panel.
+he fiure are labeled as follo"s:
1. -un button F this button causes the VI to run once.
7. -un Continuously button F this button causes the VI to run continuousl# until the Sto! or Pause
button is pressed.
:. Abort Eecution button F this button stops the runnin of the VI.
<. Pause button F this button pauses the runnin of the VI.
=. A!!lication %ont button F this pull&do"n menu displa#s the options for chanin the si/e, st#le,
alinment, color and t#pe of font for different fonts used in the VI. +he first option causes the %ont
0ialog Bo to appear.
?. Align Ob8ects button F this pull&do"n menu displa#s the options for alinin ob4ects in the front
panel "ith respect to different axes.
>. 0istribute Ob8ects button F this pull&do"n menu displa#s the options for distributin ob4ects, or
settin the spacin in bet"een ob4ects "ith respect to different axes.
G. -esi9e Ob8ects button F this pull&do"n menu displa#s the options for resi/in ob4ects.
H. -eor&er button F this pull&do"n menu displa#s the roupin, loc%in and orderin options for the
ob4ects in the front panel.
18. Search text field and Contet $el! tole button F #ou can t#pe in %e#"ords here to search them
in LabVIEW. Bou can also use this to find ob4ects in the Controls palette and if the# exist, #ou can
directl# dra and drop them in the front panel. +he Contet $el! button is a tole button that
opens and closes the Contet $el! "indo".
Eam!le "#:
;lace the follo"in ob4ects in the current front panel: a "aveform chart, a dial and a real matrix indicator.
+hen tr# out the different alinment, distribution, resi/in and reorder buttons to demonstrate the use of
each. 'lose the front panel but do not save the VI. 6pen a ne" VI.

After #ou create the front panel "indo", #ou add code usin raphical representations of functions to
control the front panel ob4ects. +he bloc% diaram "indo" contains this raphical source code.
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 7

;ressin the Ctrl2E "hile the front panel is active brins out the block &iagram 0B01. +he bloc% diaram is
"here the functionalit# of the VI is defined thru function nodes and "ires connectin these nodes. ,loc%
diaram ob4ects include terminals, subVIs, functions, constants, structures, and "ires, "hich transfer data
amon other bloc% diaram ob4ects. Diht&clic%in on an empt# field inside the bloc% diaram causes the
%unctions palette to appear, as sho"n in the fiure belo".

Figure 1. %. The Functions palette.
+his set of menu contains the functions, VIs and Express VIs. Bou then connect these nodes "ith "ires so
that data ma# flo" in and out of these nodes.
6b4ects on the front panel "indo" appear as terminals on the bloc% diaram. +erminals are entr# and exit
ports that exchane information bet"een the front panel and bloc% diaram. +erminals are analoous to
parameters and constants in text&based prorammin lanuaes. +#pes of terminals include control or
indicator terminals and node terminals.
Eam!le "#;
1. ;lace a numeric control and a %nob in the front panel. +hen observe the correspondin nodes that
have been placed in the bloc% diaram.
7. ;lace a tan% and a "aveform chart in the front panel. 6bserve the difference bet"een the
correspondin nodes of the controls and the indicators in the bloc% diaram.
:. ;lace a color box control and a round LE2 indicator on the front panel. What can be said about the
correspondin nodes of the control and the indicator in the bloc% diaram as compared to the first
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 8

nodes placed?
<. 'onnect the %nob control node "ith the tan% indicator node and the color box control node "ith the
"aveform chart node in the bloc% diaram. 6bserve "hat happens.
=. 'onnect the numeric control node "ith the ,oolean indicator node. What happens?
?. In the front panel, replace the numeric control "ith a push button. 6bserve "hat happens in the bloc%
diaram.
>. In the front panel, replace the "aveform chart "ith a numeric indicator. What is the difference 0in
ph#sical aspect1 bet"een the numeric control and the numeric indicator? 6bserve "hat also happens
in the bloc% diaram.
Bou can run the VI continuousl# and experiment on ad4ustin the values. +hen close the VI "ithout savin
it.

+here are t"o distinuishin characteristics bet"een a control and an indicator terminal on the bloc%
diaram. +he first is an arro" on the terminal that indicates the direction of data flo". +he controls have
arro"s sho"in the data leavin the terminal, "hereas the indicator has an arro" sho"in the data
enterin the terminal. +he second distinuishin characteristic is the border around the terminal. 'ontrols
have a thic% border and indicators have a thin border.

Figure 1. &. 'ontrol an! in!icator terminals.
Ciure 1.> sho"s terminals in icon vie". Bou can vie" these terminals "ithout an icon b# riht&clic%in on
the terminal icon at the bloc% diaram and unchec%in the Vie* As Icon option. Bou can also automaticall#
place terminals on the bloc% diaram "ithout an icon b# unchec%in the Place 1ront !anel terminals as
icon option under the <eneral options for the bloc% diaram, "hich can be accessed via the Tools 77
O!tions menu and selectin Block 0iagram under Category pane of the O!tions "indo" that pops out.
Eode terminals are terminal that do not appear as ob4ects in the front panel, such as a constant.
'olors are used to represent "hat data t#pes b# default the nodes and the "ires are carr#in. +able 1.1
sho"s the common data t#pes used in LabVIEW.
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 9

Table 1. 1 'ommon LabVIEW !ata t(pes. From Larsen) 2012

+he common rule of the thumb is that #ou can onl# connect nodes of the same color, other"ise, it ma#
result to a bro%en "ire and a proram error. ,ut not all lead to errors. In some cases LabVIEW does some
conversions. +his is the case "hen #ou have for example, a control node carr#in an inteer data is
connected to an indicator node carr#in a double&precision floatin&point number. In such case, the
conversion is indicated b# a small red dot at the node, as sho"n in the fiure belo"

Figure 1. *. +ata t(pe con,ersion.
Bou transfer data amon bloc% diaram ob4ects throuh "ires. Each "ire has a sinle data source, but #ou
can "ire it to man# VIs and functions that read the data. Wires are different colors, st#les, and thic%nesses,
dependin on their data t#pes. +able 1.7 sho"s different "ires and ho" are the# identified dependin on
their data t#pe.
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 10

Table 1. 2. Wires in LabVIEW. From http-..www.ni.com.gettingstarte!.lab,iewbasics.!ataflow.htm) retrie,e! 0/01an0201".

Eodes are ob4ects on the bloc% diaram that have inputs andIor outputs and perform operations "hen a VI
runs. +he# are analoous to statements, operators, functions, and subroutines in text&based prorammin
lanuaes. Eodes can be functions, subVIs, Express VIs, or structures. 9tructures are process control
elements, such as 'ase structures, Cor Loops, or While Loops.
Cunctions are the fundamental operatin elements of LabVIEW. +he Add and 9ubtract functions are
examples of function nodes. Cunctions do not have front panel "indo"s or bloc% diaram "indo"s but do
have connector panes. 2ouble&clic%in a function onl# selects the function. A function has a pale #ello"
bac%round on its icon.
After #ou build a VI, #ou can use it in another VI. A VI called from the bloc% diaram of another VI is called
a sub&VI. Bou can reuse a sub&VI in other VIs. +o create a sub&VI, #ou need to build a connector pane and
create an icon. 9ub&VIs are to be discussed in the next topic.
Express VIs are nodes that re.uire minimal "irin because #ou confiure them "ith dialo boxes. $se
Express VIs for common measurement tas%s. Express VIs appear on the bloc% diaram as expandable
nodes "ith icons surrounded b# a blue field. Express VIs are to be discussed in a future topic.
+he fiure belo" sho"s the menu icons available for the bloc% diaram.

Figure 1. /. #enu icons for the bloc !iagram.
+he fiure is labeled as follo"s:
1. Dun options "hich are the same as that in the front panel.
7. 2ebuin tools F tools "hich can be used for debuin the VI.
$ighlight eecution F displa#s an animation of the bloc% diaram execution "hen the VI
is run.
-etain *ire )alues F saves the "ire values at each point in the flo" of execution so that
"hen probes are placed #ou can immediatel# retain the most recent value of data that
passed the "ire.
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 11

Ste! into F causes the execution of a node and then pause after execution.
Ste! o)er F causes the execution of a node and then pause after the execution of the next
node.
Ste! out F finishes the execution of the entire VI.
:. Application font button "hich is the same as in the front panel.
<. 6ptions for alinin, distributin, orderin and cleanin the ob4ects in the bloc% diaram.
=. +he 9earch field and the 'ontext -elp tole button "hich are the same as that in the front panel.
+he Tools palette, "hich is common to both the front panel and bloc% diaram, is sho"n in the fiure
belo". +he +ools palette contains options for the cursor and is accessible thru the Vie* 77 Tools Palette.
Bou can also press Shi1t 2 Le1t click on an empt# C; or ,2 to displa# the +ools palette temporaril#.

Figure 1. 10. The Tools palette.
+he icons in the +ools palette menu are as follo"s:
Automatic Tool Selection Button F this enables the cursor to chane automaticall# as needed in
the bloc% diaram. A reen LE2 lit on indicates that this tool is enabled.
O!erate Value Tool 0finer1 F used to push buttons 0to tole a ,oolean value, to select a menu
item, etc.
Position = Si9e = Select Tool 0arro"1 F used to relocate and resi/e controls.
E&it Tet Tool 0A "ith cursor1 F used to enter text 0on labels and strin constants1.
Connect Wire Tool 0spool1 F used to connect "ires bet"een bloc% outputs and inputs.
Ob8ect Shortcut 5enu Tool 0menu icon1 F opens a pop&up menu of options for controls and
prorammin bloc%s, the same as "hen an ob4ect or node is riht&clic%ed.
Scroll Win&o* Tool 0cupped hand1 F used to dra a "indo" 0e. to scroll to a hidden portion of a
lare bloc% diaram1.
Set = Clear Break!oint Tool 0stop sin1 F used to set and clear brea%points in the bloc% diaram
"hich free/es the execution of the proram to enable the prorammer to see "hat is happenin
"ithin the proram.
Probe 0ata Tool 0probe s#mbol: #ello" circle, arro", ; character1 F used to place probes in the
bloc% diaram "hich sho"s the value in a "ire as the proram is executed.
<et Color Tool 0dropper1 F used to set the current foreround and bac%round colors
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 12

0rill Problems "#/
1. What are the main "indo"s that pop out "hen a blan% VI is opened? What tas%s can #ou do "ith each
one?
7. -o" can ob4ects be found and placed in the front panel and bloc% diaram? 2iscuss the use of the
follo"in menus: controls palette, functions palette and tools palette.
:. What is the difference bet"een controls and indicators? In the front panel, ho" can #ou identif#, 4ust b#
mere loo%in at them, if the ob4ect is a control or an indicator?
<. -o" are data t#pes differentiated in LabVIEW? @ive an example node that represents each data t#pe
used in LabVIEW.
Sel1 Assessment3 Date #our level of achievement for the follo"in outcomes:
Outcome
Can4t &o

+.,
5arginal
Per1ormance
+",
Acce!table
Per1ormance
+/,
Ece!tional
Per1ormance
+6,
Identif# parts of and naviate throuh the
LabVIEW environment.

Write #our o"n thouhts and reflections on this topic.

1.: ,uildin the virtual instrument 0VI1
At the end of this lesson, the student shall be able to:
a. build virtual instruments usin arithmetic and comparison functions in LabVIEW!
b. create a sub&VI out of a portion of, or all of, a VI alread# made! and
c. debu VIs usin different debuin tools.
As an example, "e build the follo"in virtual instrument 0VI1 "ith the follo"in front panel and bloc%
diaram
Sum>A)erage"#)i
Cront panel:


,loc% diaram:

Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 13

and save this as Sum>A)erage"#)i 0%ile 77 Sa)e or %ile 77 Sa)e As1. ;ut values in the Num " and Num
/ then clic% the -un button to test the functionalit# of the VI.
,# clic%in the -un button, the VI is run onl# once. Bou can use the -un continuously so that the VI
becomes interactive 0it updates the results "hen the inputs are chaned1. We can ma%e the front panel
displa# more attractive b# usin not 4ust numerical controls and indicators. Edit Sum>A)erage"#)i as
sho"n belo" and save this as Sum>A)erage/#)i
Sum>A)erage/#)i
Cront panel:


,loc% diaram:


+he front panel uses vertical pointer slider as controls and meters as indicators. +a%e note that the limit of
the Sum meter "as chaned to /. because the limits of both the inputs are 1u and therefore the maximum
sum "ill be 2u. In the bloc% diaram, the control and indicator nodes are vie"ed as simple nodes to
conserve space.
9ome instruments have "arnin indicators in their panels. We can add this up usin a round LE2 0liht
emittin diode1 that lihts up "henever the averae of the t"o numbers reach 9. Edit Sum>A)erage/#)i
as sho"n belo" and save this as Sum>A)erage6#)i.



Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 14

Sum>A)erage6#)i
Cront panel:


,loc% diaram:


In this VI, annotations are added into the bloc% diaram to provide information to the reader of the source
code. Labels are also displa#ed to the function nodes providin more readabilit# to the bloc% diaram.
Eam!le "#?
,uild the VI A)erage<ra&e#)i. +he VI "ill have a front panel similar to the one belo". +he VI lists the
mathematics courses that an enineerin student "ill ta%e. +he user is allo"ed to input numerical rades,
assumin that the input of the user "ill be 4ust bet"een Su and 1uu. +he VI averaes the inputs and
displa#s the averae rade rounded off to the nearest "hole number usin a aue. A round LE2 is lit red
"hen the averae is less than 7S, and reen "hen it is 7S or above.
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 15



As another example, let us ma%e a VI that "ould compute the mean, variance and standard deviation for a
set of five numbers. +he variance
2
for a population is computed as

2
=
1
N
(x
I
)
2
N
I=1

"hile the standard deviation for a population is
= _
1
N
(x
I
)
2
N
I=1

"here x
I
is the ith data, is the population mean, and N is the number of data 0population1. +o implement
this formula, "e do the follo"in steps:
1. 'ompute the population mean .
7. 9ubtract the population mean from the data and s.uare their difference. +his .uantit# is called the
s.uared error 0Eii
2
1. Cind the s.uared error for all the data.
:. Add all the error s.uared data. +he sum is called the sum of s.uared error 0SSE1.
<. 2ivide the sum of s.uared error "ith the number of data. +his .uantit#, "hich is a mean, is called
the mean s.uared error 0NSE1. +his is also the variance
2
of the data.
=. +a%e the s.uare root of the variance. +his .uantit# is no" the standard deviation .
+he St&0e)"#)i sho"s ho" the five steps "ere implemented in LabVIEW.


Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 16

St&0e)"#)i
Cront panel:


,loc% diaram:


+he VI is tested b# enterin test values as sho"n in fiure 1.11.

Figure 1. 11. 2t!+e,1.,i with sample inputs. The output is as e3pecte!.
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 17

Eotice that the averain part "as t"ice done: first to determine the population mean, and second to
averae the s.uared error terms. A more eleant bloc% diaram can be built if sub&VIs "ere used. A sub&VI
is a VI that is used as part of a larer VI. +"o thins are needed to be defined "hen ma%in sub&VIs:
1. the functionalit# of the sub&VI! and
7. the input and output ports of this sub&VI.
6ptionall#, an icon for the sub&VI can be customi/ed. +he St&0e)/#)i sho"s the use of such sub&VIs. A VI
named A)erage#)i "as created from the oriinal VI and "as t"ice used. Another VI called the
ErrS@uare&#)i "as also created from the oriinal VI.
St&0e)/#)i
Cront panel:

,loc% diaram:


)ust li%e an# other prorammin lanuaes, #ou ma# encounter t"o t#pes of errors or bus in LabVIEW:
1. those errors or bus that prevent the VI from runnin 0similar to s#ntactical errors in text&based
prorammin lanuaes1! and
7. those errors or bus that cause #our VI to enerate bad results or incorrect behavior.
In both cases, LabVIEW has tools to help #ou deal "ith these errors and bus.
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 18

VIs "hich does not run is bro%en or non&executable. +his ma# be caused b# an# of the follo"in:
+he bloc% diaram contains a bro%en "ire because of a mismatch of data t#pes or a loose,
unconnected end.
A re.uired bloc% diaram terminal is un"ired.
A subVI is bro%en or #ou edited its connector pane after #ou placed its icon on the bloc% diaram of
the VI.

A VI "hich cannot be run because of a prorammin error is indicated b# a bro%en arro" as sho"n in the
fiure 1.17.

Figure 1. 12. 4 VI with an error.
+o %no" "hat error has occurred, #ou can clic% the bro%en arro" "hich "ill displa# the error list.

Figure 1. 13. Error list.
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 19

+he list suests that the error occurred at the ErrS@uare&#)i because it is not executable. Bou can clic%
the error messae under the Block 0iagram Errors to hihliht the node "hich contains errorIs. 6penin
the subVI reveals the follo"in bloc% diaram

Figure 1. 1". The subVI with an error.
"hich sho"s that the error is caused b# unconnected "ires in the subVI. 'orrect it b# ma%in the proper
connections. With no" a correct subVI, the VI is no" executable. -o"ever, testin the VI "ith the same
sample values as before,

Figure 1. 1$. 2t!+e,2.,i with erroneous output.
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 20

We can use LabVIEW5s debuin tools to troubleshoot this apparentl# erroneous VI. +he follo"in can be
used:
1. 9inle steppin execution, "here the VI is run step b# step.
7. ,rea%points "hich pauses the VI "hen data passes throuh and allo"s the prorammer to inspect
the current state of the VI at this point.
6ne can animate the execution of the VI b# clic%in the $ighlight eecution button, and use Probes to
displa# and monitor the values passin thru a "ire "hile the VI executes.
Eam!le "#A
+he file St&0e)/Berr#)i contains errors. $se the debuin tools to correct the errors.

0rill Problems "#6
1. ,uild a VI that "ould solve a .uadratic e.uation of the form
ax
2
+ bx + c = u
b# usin onl# basic arithmetic operations and comparison operators. +a%e note that the s.uare root
operations return a NaN 0not a number1 value "hen it operates on neative numbers. +his should not
be the case "ith #our VI, ho"ever. It should be able to return complex numbers, but do not use
functions for complex numbers #etA 'all this VI as Cua&raticE@uationSol)er#)i
7. $se the Cua&raticE@uationSol)er#)i to build a VI that "ould solve a .uartic e.uation of the form
ax
4
+ bx
2
+c = u
callin this as CuarticE@uationSol)er#)i. )ust li%e in the previous item, the VI should be able to return
complex numbers as ans"ers "ithout usin functions for these.
:. ,uild a VI that "ould convert a decimal number into a 1?&bit binar# number, callin this as 0ecToBin#)i
and another VI that "ould convert a 1?&bit binar# number into its decimal form, callin this as
BinTo0ec#)i
<. $se the VIs built in number : to build 0ecToOct#)i 0decimal&to&octal1 and OctTo0ec#)i 0octal&to&
decimal1.
=. +he VI tscoreBerr#)i computes the 9tudent5s t&score for t"o sets of sampled data. +he t&score of t"o
sets of data indicates "hether there is sinificant difference bet"een the means of the t"o sets. +hese
t"o sets of data can be dependent or independent of each other. +he steps to compute the t&score are
the follo"in:
a. 'ompute the means of the t"o data sets, callin them x
a
and x
b
0"e have used the x s#mbol to
indicate that "e are ta%in the mean of a sample, "hich sa#s that the data at hand are part of a
larer data "hich is the most practical case1.
b. 'ompute the sum of the s.uares of the error for the t"o sets of data, callin them SSE
a
and SSE
b
.
c. 2etermine the sample variance usin the formula
s
2
=
SSE
a
+ SSE
b
(n
a
1) + (n
b
1)

"here n is the number of samples for each data set.
d. 2etermine the standard deviation of the samplin distribution of the sample&mean differences usin
the formula
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 21

= _
s
2
n
a
+
s
2
n
b

e. +he t&score is then computed as
t =
|x
a
x
b
|


$sin LabVIEW5s debuin tools, troubleshoot the VI "hich should ive the correct t&score for the
follo"in set of fifteen data:
Bata set A: 26, 26, 26, 21, 18, 21, 19, 2S, 2S, 29, 22, 22, 24, 2S, 22
Bata set B: 18, 2u, 2u, 26, 17, 2S, 2u, 16, 21, 18, 21, 29, 2u, 2S, 19
Sel1 Assessment3 Date #our level of achievement for the follo"in outcomes:
Outcome
Can4t &o

+.,
5arginal
Per1ormance
+",
Acce!table
Per1ormance
+/,
Ece!tional
Per1ormance
+6,
,uild virtual instruments usin arithmetic
and comparison functions in LabVIEW

'reate a sub&VI out of a portion of, or all of,
a VI alread# made

2ebu VIs usin different debuin tools
Write #our o"n thouhts and reflections on this topic.

1.< LabVIEW5s mathematical functions
At the end of this lesson, the student shall be able to:
a. use LabVIEW5s different elementar# math, statistical and complex number functions! and
b. use "hile loops "ith shift reister and tunnels "ith different modes.
LabVIEW offers different built&in elementar# mathematical, statistical and functions for complex numbers.
+he follo"in function roups are found in the %unctions 77 5athematics 77 Elementary an& S!ecial
%unctions
Trigonometric: functions such as sin, cos, tan, etc., are under this palette.
E!onential: functions such as e!, ln, log, etc., are under this palette.
$y!erbolic: functions such as sinh, cosh, tanh, etc., are under this palette.
Demember that trionometric functions accept radians as inputs and inverse trionometric functions return
anles in radians.
9tatistical functions such as measures of central tendencies 5ean, 5e&ian and 5o&e are found at the
%unctions 77 5athematics 77 Probrability an& Statistics.
'omplex number functions are found at %unctions 77 Numeric 77 Com!le. 9ome of these functions
include 'om!le Con8ugateD Polar to Com!leD Com!le to PolarD -e=Im to Com!leD and so on.
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 22

As an example, "e build a VI that accepts input of anle in derees and returns the sine, cosine, tanent,
cosecant, secant and cotanent values for such anle.
Trigo#)i
Cront panel:


,loc% diaram:


Eam!le "#E
,uild a VI that "ould allo" the input of a value from 1 to +1 and return the anle in derees
correspondin to the inverse sine and inverse cosine of the input value.

+he WhileFloo! is a structure in LabVIEW that depends on the mode it is run, "ill do the follo"in:
a. execute a code and stop "hen a certain condition is met! or
b. execute a code as lon as a certain condition is bein met.
Ciure 1.1? sho"s the WhileFloo! and the iteration and condition terminals. +he iteration terminal is an
output node that %eeps trac% of the number of times the WhileFloo! has executed. +he condition terminal is
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 23

an input node that re.uires the necessar# conditions to terminate the execution of the VI. It has t"o modes:
Sto! i1 True and Continue i1 True. +he node re.uires a ,oolean input, and dependin on the mode, does
one of the t"o thins as stated before.

Figure 1. 1%. The While0loop with the terminals shown.

Figure 1. 1&. The two mo!es of the con!ition terminal of the While0loop.
2ata can be communicated in, out and around the loop usin tunnels and shift reisters. +unnels allo" the
passae of data in and out of the WhileFloo!. Ciure 1.1G sho"s an input node passin a scalar data into
the loop. +unnels are automaticall# made "hen nodes outside the WhileFloo! are connected to the nodes
inside the WhileFloo!.

Figure 1. 1*. 5on0in!e3e! !ata tunnel in While0loop.
+unnels are to be discussed in detail on the next article. Cor no", it is sufficient to %no" that the input
tunnel 0a tunnel "hich inputs data into the "hile loop1 and the output tunnel 0a tunnel "hich passes data
from the "hile loop to another node outside1 are non&indexed b# default in WhileFloo!.
+he shift reister stores the result of the current iteration and passes it to the next iteration for use. 9hift
reister comes in pair, that is, an output shift reister is paired "ith an input shift reister. +he shift reister
can have an initial value b# passin a data into the input shift reister. +his initial value is the value used b#
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 24

the WhileFloo! in its first iteration of calculation. If the value of the shift reister is not initiali/ed, it uses the
value stored in the output shift reister carried out from the previous execution of the VI as the initial value.
Ciure 1.1H sho"s the WhileFloo! "ith a shift reister. +o add a shift reister to a WhileFloo!, riht&clic%
on the ede of the WhileFloo! then choose A&& Shi1t -egister#

Figure 1. 1/. While0loop with a shift register.
+he "hile loop structure, as "ell as other execution structures in LabVIEW "ill be discussed in more detail
in future topics! for no", "e cover the basic thins one must %no" "hen usin a WhileFloo!. +he next
example uses a WhileFloo! to implement a numerical solution called the Ee"ton&Daphson method.
Eam!le "#G
@iven the follo"in e.uations for a catenar#
s = a sinh
L
a


"here s is half of the rope lenth a is the parameter related to the mass of the rope and the acceleration
due to ravit#, and L is half the distance of the posts supportin the rope. +he sa of the rope is iven as
u = a _cosh
L
a
1]

@iven s = S8.7S and L = Su, find u usin LabVIEW.

Catenary#)i
Cront panel:

Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 25

,loc% diaram:


Eam!le "#".
$se the statistical functions of LabVIEW to enerate the follo"in
a. an arra# of 1uu uniforml# distributed random numbers bet"een u and 1.
b. an arra# of 1uu uniforml# distributed random numbers bet"een 1 and 1.
c. an arra# of 1uu normall# distributed random numbers.
d. an arra# of 1uu normall# distributed random numbers "ith a mean of 2.8 and a standard deviation
of 2.S.
In all of the cases, find the mean, standard deviation, variance, s%e"ness and root mean s.uare 0D*91,
and then usin the $istogram#)i, plot the historams of each set of random numbers.







Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 26

-an&om#)i
Cront panel:


,loc% diaram:







Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 27

Eam!le "#""
+he front panel of #our VI for the .uadratic e.uation solver 0Cua&raticE@uationSol)er#)i, drill problem 1.:
item number 11 miht loo%ed somethin li%e the one belo", "ith four indicators, since #ou are not allo"ed
to use complex functions.

+his time, use onl# t"o indicators and use complex functions to build Cua&raticE@uationSol)er/#)i, "ith
the front panel loo%in li%e the one belo":


-int: 9et the indicators to displa# numbers usin complex double precision floatin&point format.

0rill Problems "#:
1. $sin the Euler5s formula, the trionometric and h#perbolic functions for the complex number z = x +
jy can be established, and "ill sho" that the t"o functions are actuall# related thru the complex
number. 2erive a formula to find the follo"in: sinh(x +jy) ! cosh(x + jy) ! sin(x + jy) and
cos(x + jy), and then create a VI that "ould numericall# prove #our derivations. Eame the VI as
TrigAn&$y!#)i.
7. 2e *oivre5s theorem is a formula that is useful in findin the po"er and roots of complex numbers. It is
stated as
z
n
= (x + jy)
n
= |i(cos + j sin )]
n
= i
n
(cos n + j sinn)
Cor fractional n, the riht&hand side expression is multivalued and becomes
z
1n
= (x + jy)
1n
= |i(cos +j sin)]
1n
= i
1n
_cos
+ 2k
n
+ j sin
+ 2k
n
]
"here k = u,1,2 .n 1. ,uild a VI that computes the fourth root of a complex number. +he user is
allo"ed to input numbers: the real part and the imainar# part of the complex number z. +he VI must
solve the four roots of the number z, in complex number form. Implement the VI in t"o "a#s:
a. usin trionometric functions 0name the VI as 0e5oi)reTrig#)i1, and
b. usin complex number functions 0name the VI as 0e5oi)reCom!le#)i1
:. +he +a#lor series expansion for the h#perbolic sine function is iven as
sinh x = x +
x
3
S!
+
x
5
S!
+
x
7
7!
+ =
x
2n+1
(2n + 1)!

n=0

Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 28

"hile for the h#perbolic cosine is
cosh x = 1 +
x
2
2!
+
x
4
4!
+
x
6
6!
+ =
x
2n
(2n)!

n=0

"here n is the number of terms to be added to the series. 'reate a VI that "ould compute the sum of
the first ten terms of the +a#lor series expansion for the h#perbolic sine and h#perbolic cosine of an
input x, callin this VI as $y!Taylor#)i $se WhileFloo!, and follo" the follo"in steps:
1. Input x.
7. Cor the first iteration 0i = u1, compute the first term of the series.
:. 9tore the first term into the shift reister.
<. Cor the second iteration 0i = 11, compute the second term of the series. Add this to the first term
stored in the shift reister and save their sum into the shift reister.
=. Depeat step < until the number of iterations reaches 1u 0i = 91.
?. 2ispla# the sum.
Cor comparison, compute the h#perbolic sine and h#perbolic cosine. Eotice that as x ro"s larer, the
discrepanc# bet"een the +a#lor series enerated and the function enerated values ro"s larer.
<. 9imulate the follo"in random events b# creatin a VI :
a. +ossin of coins. +he output should either be a J-eadK or a J+ailK. 'all the VI as TossCoin#)i.
b. +ossin of a dice. +he output should be an inteer number from 1 to 6. 'all the VI as 0ice.)i.
c. 9electin six numbers out of SS numbers from 1 to SS. +he output is an arra# of six numbers, li%e
pic%in six numbers to place a bet on the lotter#. 'all the VI as Lotto?;;#)i. Eote that the VI miht
return repeated numbers in an arra#. +his "ill be o%a# for no".
=. 2etermine the lo"est positive root of f(x) = 8e
-x
sin(x) 1
a. usin Ee"ton&Daphson method.
b. usin fixed&point iteration. $se the fixed&point iteration formula x
I+1
= x
I
+ 8e
-x

sin(x
I
) 1.
2etermine the root correct to three decimal places. Also, determine ho" man# iterations are re.uired
for each method. Which method arrives at the ans"er faster?
Sel1 Assessment3 Date #our level of achievement for the follo"in outcomes:
Outcome
Can4t &o

+.,
5arginal
Per1ormance
+",
Acce!table
Per1ormance
+/,
Ece!tional
Per1ormance
+6,
$se LabVIEW5s different elementar# math,
statistical and complex number functions

$se "hile loops "ith shift reister and
tunnels "ith different modes

Write #our o"n thouhts and reflections on this topic.

1.=. *atrices and arra#s in LabVIEW
At the end of this lesson, the student shall be able to:
a. understand ho" LabVIEW roups data into a sinle container!
b. enerate arra#s and matrices usin WhileFloo! and %orFloo!! and
c. operate and manipulate matrices and arra#s.
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 29

LabVIEW provides three "a#s to roup data:
'luster F a cluster is a roupin of potentiall# different data t#pes! for example, information about
an individual that includes:
o Eame 0strin1
o ,irthdate 0dateItime1
o Ae 0inteer numeric1
o -eiht and "eiht 0floatin&point numeric1
o ;hotoraph 0imae1
can be stored on a sinle container called a cluster. We "ill deal "ith clusters later on.
Arra# F an arra# is a roup of data "ith the same data t#pe. Arra#s can have as man# dimensions.
+he list of scores in a .ui/ of a class of Su is a one&dimensional arra# 0can be a ro" vector or a
column vector1. If the list contains not onl# the scores of a particular class, but of all classes "ho
too% the same .ui/, the list is a t"o&dimensional arra#.
*atrix F a matrix is a t"o&dimensional arra# "hich onl# contains numeric data. A t"o&dimensional
arra# "hose elements are all numeric can be considered a matrix, ho"ever, LabVIEW
differentiates the t"o b# havin arra# operations and matrix math operations. Cor most cases, both
operations have the same meanin and hence can be used interchaneabl#.
In this chapter, "e "ill deal mostl# "ith arra# manipulations and operations, "hich also appl# to matrix
manipulations and operations. We "ill 4ust mention specific cases "hen needed.
Eam!le "#"/
'reate an arra# control, a matrix control, an arra# indicator and a matrix indicator in the front panel.

+he next example sho"s ho" a WhileFloo! can be used to create a t"o&dimensional arra#.
Eam!le "#"6
0a1 ,uild a 1u S t"o&dimensional arra# "hose elements are uniforml# distributed random numbers
bet"een u and Su rounded off as inteers.
0b1 ,uild a S 1u t"o&dimensional arra# "hose elements are uniforml# distributed random numbers
bet"een u and Su rounded off as inteers.
0c1 9ho" ho" the number of columns and ro"s of the t"o&dimensional arra# can be controlled b# the user.
$se WhileFloo!s in 0a1 and 0b1.





Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 30

ArrayHsingWhile#)i
Cront panel:

,loc% 2iaram:


Another structure that can be used in the eneration of arra#s is the %orFloo!. +he %orFloo! executes the
code inside the structure for a number of times. A condition can also stop a %orFloo! from runnin b#
insertin a condition terminal inside a %orFloo!. +he %orFloo! stops "hen this condition is met, or "hen
the number of iterations has been reached, "hichever comes first.
2ata in and out of the %orFloo! can also be transferred via data tunnels. +hese tunnels are basicall# the
same as that of WhileFloo!. +he basic difference onl# is that the default tunnel mode for WhileFloo! is the
latest value, "hile that for the %orFloo!, the default is indexin.
Eam!le "#":
0a1 ,uild a 1u S t"o&dimensional arra# "hose elements are uniforml# distributed random numbers
bet"een u and Su rounded off as inteers.
0b1 ,uild a S 1u t"o&dimensional arra# "hose elements are uniforml# distributed random numbers
bet"een u and Su rounded off as inteers.
0c1 9ho" ho" the number of columns and ro"s of the t"o&dimensional arra# can be controlled b# the user.
$se %orFloo!s in 0a1 and 0b1.

Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 31

ArrayHsing%or#)i
Cront ;anel:

,loc% 2iaram:


Another mode for the tunnel is the concatenatin mode, "hich concatenates the recentl# enerated arra#
into the previousl# enerated arra#. +he use of such mode can be demonstrated usin the follo"in
example.
Eam!le "#";
@iven an arra# |
1 2 S 4
], produce the follo"in arra#s:
0a1 _
1 2 S 4
1 2 S 4
1 2 S 4
_
0b1 |
1 2 S 4 1 2 S 4 1 2 S 4
]





Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 32

In&eingVsConcatenating#)i
Cront panel:


,loc% diaram:


O!erations on arrays an& matrices# Arra#s and matrices can be operated on arithmeticall# 4ust li%e
scalars.
Eam!le "#"?
+hrouh an example VI, sho" ho" arithmetic operations "or% for scalars and arra#s.

A&&ingArrays#)i
Cront panel:


Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 33

,loc% diaram:


*atrices enerall# follo" the same rules as that of arra# operation, except for multiplication and division.
Eam!le "#"A
+hrouh a VI, demonstrate the difference bet"een arra# multiplication and matrix multiplication.

Array5ultVs5atri5ult#)i
Cront panel:

Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 34

,loc% diaram:


Eam!le "#"E
De&implement the VI for computin the standard deviation, improvin "hat St&0e)"#)i and St&0e)/#)i can
do. +his time, St&0e)6#)i should be able to compute the standard deviation for an# number of data.

St&0e)6#)i
Cront panel


,loc% 2iaram


Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 35

Array 5ani!ulation# LabVIEW provides various functions to manipulate arra#s. Ciure 1.78 sho"s the
Arra# palette "hich contains functions for arra# manipulation.

Figure 1. 20. The 4rra( 6alette.
Eam!le "#"G
@iven the follo"in arra#s,

do the follo"in:
0a1 2etermine the si/e of an# one of these arra#s.
0b1 'reate a 72 arra# "hose elements of the first, second and third ro"s are the elements of "0 Array ",
"0 Array /, and "0 Array 6, respectivel#. 2etermine the si/e of this 72 Arra#.
0c1 'reate a 72 arra# "hose elements of the first, second and third columns are the elements of "0 Array
", "0 Array /, and "0 Array 6, respectivel#. 2etermine the si/e of this 72 Arra#.
0d1 Extract the fourth, sixth and tenth element of "0 Array ".
0e1 Extract the elements at the fifth ro" of /0 Array in 0b1. Also, extract the elements of the second column
of /0 Array.
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 36

0f1 Extract a >&b#&7 arra# from /0 Array startin from the second ro", first column element.
01 'reate a =&b#&? arra# from /0 Array.
0h1 2etermine the maximum and minimum values of /0 Array as "ell as their positions.

5ani!ulatingArrays#)i
Cront panel:

,loc% diaram:


*atrices can also be manipulated usin functions under the 5atri palette. +he students are expected to
tr# on these functions and see ho" the# "or%.
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 37

As an application, "e tr# to implement the matrix multiplication via arra#s. Demember that arra#
multiplication is different from matrix multiplication in the sense that the latter has more rules. +he matrix
product of t"o matrices A and B "hose si/es are m n and n p respectivel# is the expression
(AB)
Ij
= A
Ik
B
kj
m
k=1

+he follo"in example implements matrix multiplication usin arra#s.
Eam!le "#/.
Implement an alorithm for matrix multiplication usin arra#s onl#. +hen find the matrix product of the
matrices
A = _
8 1 6
S S 7
4 9 2
_ and B = _
1 1 1
1 2 S
1 S 6
_

5atri5ulti!licationViaArrays#)i
Cront panel

,loc% diaram


Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 38

0rill Problems "#;
1. -o" does LabVIEW roup data? 9ho" ho" each data roups are made usin a VI called
0ata<rou!s#)i
7. 'reate a VI that "ould perform arithmetic operations 0add, subtract, multipl# and divide1, as "ell as
mathematical functions 0trionometric, exponential, h#perbolic1 and statistical functions to matrices and
arra#s. 2esin #our front panel as if it "ill loo% li%e a scientific calculator for arra#s and matrices. It
"ould be ood if the user is informed "hether an operation is invalid and "h#. 'reate separate VIs for
arra#s 0ArrayCalculator#)i1 and matrices 05atriCalculator#)i1
:. 'reate #our o"n reshape alorithm that reshapes a iven 72 arra# into another arra# "hose si/e is to
be specified b# the user. Decall that the reshape function of LabVIEW reshapes an arra# thru ro"&"ise
re&arranement of elements. Bour reshape function should do this column&"ise. $se WhileFloo!
0-esha!eHsingWhile#)i1 and %orFloo! 0-esha!eHsing%or#)i1.
<. +"o more commonl# done operations on matrices, specificall# on s.uare matrices, are findin
determinants and findin the inverse. $sin arra#s, create a VI that "ould evaluate the determinant of
a 72 s.uare arra# as user input! call this VI as 0eterminants#)i. 'reate a separate VI "hich "ill
evaluate the inverse of a 72 s.uare arra# of numeric data usin co&factors and expansion b# minors!
call the VI as In)erse5atri#)i. 'hec% #our results usin matrices and matrix functions 0%unctions 77
5athematics 77 Linear Algebra1
=. @auss and @auss&)ordan elimination are alorithms "hich reduces a matrix into an upper trianular
matrix and identit# matrix respectivel#. Implement the t"o alorithms in LabVIEW 0<aussElims#)i and
<aussIor&anElims#)i1 usin matrices.
Sel1 Assessment3 Date #our level of achievement for the follo"in outcomes:
Outcome
Can4t &o

+.,
5arginal
Per1ormance
+",
Acce!table
Per1ormance
+/,
Ece!tional
Per1ormance
+6,
$nderstand ho" LabVIEW roups data into
a sinle container!

@enerate arra#s and matrices usin WhileF
loo! and %orFloo!! and

6perate and manipulate matrices and
arra#s.

Write #our o"n thouhts and reflections on this topic.

1.? @raphin in LabVIEW
At the end of this lesson, the student shall be able to:
a. understand the difference bet"een LabVIEW5s chart and raph!
b. displa# data and "aveforms into a chart or raph! and
c. confiure charts and raphs suitable for presentin data.
LabVIEW provides a number of chartin and raphin options for producin data plots. +he table belo"
summari/es the most commonl# used chart and raph t#pes in LabVIEW.
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 39

Table 1. 3. #ost commonl( use! charting an! graphing t(pes in LabVIEW.

+hese chart and raph indicators are available on the controls palette.
Waveform chart and "aveform raphs differ b# the manner the# can displa# and update data.
A *a)e1orm chart remembers and displa#s a certain number of points b# storin these points in a buffer.
When the buffer ets full, the chart starts over"ritin the old values "ith the ne" ones. When ne" data
points become available, the# are appended to the old ones. Waveform charts are used to displa# real&time
data points, thouh it also accepts arra#s and displa#s the points all at once.
A *a)e1orm gra!h ho"ever, accepts arra# as an input and displa#s these as data points all at once. It
does not accept sinle value points. It is assumed that the points in the arra# are e.uall# spaced "hen the#
are accepted as an input to a "aveform raph.
+he follo"in example illustrates the difference bet"een a "aveform chart and a "aveform raph.
Eam!le "#/"
;lot the function y = sinx for u x 2 usin a "aveform chart and a "aveform raph.








Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 40

ChartVs<ra!h#)i
Cront panel:

,loc% diaram


A "aveform chart has three update modes
9trip 'hart: +his mode has a scrollin displa# that is similar to a paper tape strip chart recorder.
+his mode first plots values from left to riht. Crom here, it continues to plot ne" points at the
rihtmost point and shifts old values to the left.
9cope 'hart: +his mode has a retracin displa# similar to an oscilloscope. As it receives each ne"
value, it plots the value to the riht of the last value. When the plot reaches the riht border of the
plottin area, it erases the plot and beins plottin aain from the left border.
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 41

9"eep 'hart: +his mode acts much li%e the scope chart, but the plot is not erased "hen the plot
hits the riht border. Instead, a movin vertical line mar%s the beinnin of ne" data and moves
across the displa# from left to riht as it adds ne" data.
Eam!le "#//
Explore the difference bet"een the three update modes of "aveform chart.

+he "aveform chart and the "aveform raph can be confiured usin the Pro!erties dialo box.
Eam!le "#/6
9ho" ho" charts and raphs can be confiured usin the Pro!erties dialo box.

Con1iguringChartAn&<ra!h#)i
Cront panel:


Eam!le "#/:
;lot the sine "ave y = sinx and the cosine "ave y = cos x for u x 2 on the same "aveform
chart and raph.



Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 42

5ulti!lePlots#)i
Cront panel

,loc% diaram:


In the foreoin discussions, the data plotted mostl# are time&based data, that is, the x&axis "as dedicated
to time. +his is not reall# the case ho"ever. Cor "aveform charts and "aveform raphs, "e assume that
the variable in x&axis is e.uall# spaced. 9o if #ou are to plot a data, not necessaril# time&based data, but
the data points are enerated "ith e.ual spacin, "aveform charts and "aveform raphs provide a ood
"a# to plot these data points. Cor une.uall# spaced x&axis, JK <ra!hs can be used.



Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 43

Eam!le "#/:
;lot the pol#nomial f(x) = A + Bx + Cx
2
+Bx
3
"ith A = 4, B = S.7, C = 1.9 and B = u.17 for
the follo"in 12 arra#s of x.
a. u x 9
b. x = |
u 1.u 2.7 S.u 4.2 S.u 6.S 7.S 8.1 9.u
]

PlottingHsingJK<ra!h#)i
Cront panel

,loc% diaram


Eam!le "#/;
$se raphical method to find the approximate roots of the e.uation x
3
9.4x
2
+ 22.9Sx 1u.6u2 =
u. +he roots of this e.uation are the values of x "hich satisf# the e.uation. Eote that since the deree of
the pol#nomial in the e.uation is S, there "ill be three roots.


Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 44

%in&ing-oots<ra!hically#)i
Cront panel

,loc% diaram


LabVIEW also has tools for plottin in three dimensional. In the first example, a surface plot is enerated
usin parametric values.
Eam!le "#/?
'reate a surface plot for a torus. A torus is a rin "ith t"o parameters: the distance bet"een the center of
the torus to the center of the tube R, and the radius of the tube i, as sho"n in the fiure belo".

With these definitions, the torus is defined b# the follo"in e.uations:
x = (R + i cos u) cos v
y = (R + i cos u) sinv
z = i sinv
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 45

"here u and v are parameters "ith rane from u up to 2. +he Cor R = 1u and i = 2, and usinSu data
points for u and v, plot a torus in LabVIEW.

PlottingATorus#)i
Cront panel

,loc% diaram




Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 46

0rill Problems "#?
1. 0a1 @enerate a @aussian distributed random number "ith a mean of 1u and a standard deviation of 2.
Bour VI "ould onl# stop eneratin a random number "hen a Sto! button is pressed. +he VI should
onl# enerate 1uu data points per second. ;lot the random numbers as the# are enerated and after
pressin the Sto! button. Eame the VI as WhiteNoise#)i.
0b1 A movin averae filter is a %ind of filter "hich aims to smoothen out variations in sinals. It "or%s in
the follo"in manner: the current value and a number of previous values are averaed to enerate a
ne" value. +he number of values to be enerated depends on the "indo" si/e of the filter. If for
example, the "indo" si/e is 1u, then the current value plus 9 previous values of the input sinal are
averaed. With this, create a movin averae filter for the input sinal enerated in part 0a1. +he
"indo" si/e of the movin averae filter is S. ;lot the input sinal and the filtered sinal on the same
set of axes. +he VI should stop "hen a Sto! button is pressed. 'all this VI as the
5o)ingA)erage%ilter#)i. 0Hint: Use shift registers.1
0+here is a video called WhiteNoise#*m) and 5o)ingA)erage%ilter#*m) "hich demonstrates ho"
these VIs should "or%.1
7. Cor a set of correlated data, a straiht line that best fits the data is iven as y = a
1
x + a
0
, "here
a
1
=
n_x

-_x

_y

n_x

2
-(_x

)
2
and a
0
= y a
I
x 0x and y are the means of x and y respectivel#1. @iven the
data belo" "hich tries to determine if there is a relationship bet"een the lenth of the tail 0TLength1
of a fox in inches to the "eiht 0Weight1 of the fox in pounds.

Cor these data, build a VI to do the follo"in:
a. ;lot the data in a raph. Eote that as this point, there is no relationship bet"een the t"o sets of
data and therefore, the data points should not be connected in an# "a#.
b. $sin the VI, compute the line that best fits the t"o data sets, "ith the tail lenth the independent
variable and the "eiht as the dependent variable.
c. ;lot the best fit line into the same axes as that of the plot in 0a1 "ith x bet"een u and SS.
d. @raphicall# determine the approximate "eiht in pounds of the fox if the tail lenth is 0i1 S in! 0ii1
12 in! 0iii1 18 in! 0iv1 22 in and 0v1 Su in. 9ave these values in an arra# indicator.
e. 2oes the line ma%e sense? Wh# or "h# not? ;ut #our ans"er here as an annotation to #our VI.
'all the VI as Best%itLine#)i
:. 'reate a VI that "ould plot the follo"in functions into a chart and a raph: the exponential function
y = e
x
, the loarithmic function y = lnx, h#perbolic cosine function y = cosh x and the cosine
function y = cos x for u x S. 'hoose appropriate spacin to ensure smooth plot. 'hoose the
appropriate scalin for the x and y axes so that the user "ill have an idea on ho" the function behaves
as x ets larer. *a%e sure also that the user "ill be able to discern "hich plot is "hich. Cinall#, choose
"hich is the better tool to plot such functions so that the user "ill be able to use the plots for better
understandin of the behavior of the function. 'all this VI as %unctionPlotter#)i.
Fundamentals of LabVIEW Programming

Basic LabVIEW Concepts Page 47

<. +he PlottingATorus#)i in the example used *ath9cript node to enerate the needed arra#s. 9ho"
ho" the nodes and structures of LabVIEW can be used to accomplish such tas%. *a%e the VI
interactive too, that is the user can specif# the value of R and i, as "ell as the spacin for the
parameters u and v. +a%e note that as a re.uirement R > i or the torus "ill not be the familiar torus.
Interate this into the VI so that "hen the user enters a value of R and i such that R i, the arra#s
"ill return empt#. 'all the VI as PlottingATorus/#)i
=. 9ho" ho" the follo"in functions can be plotted as a surface for S x, y S:
a. f(x, y) = sinc x
2
+ y
2
! +he sinc x function is e.ual to the expression sinx x.
b. f(x, y) = exp(x
2
y
2
).
c. f(x, y) = (cos x)(siny)
d. f(x, y) = ln (x
2
+y
2
)
e. f(x, y) = sinh x + cosh y
'all the VI as Sur1acePlots#)i.

Potrebbero piacerti anche