Digital Signal Processing with
LabVIEW 8.6
Lab # 02
Structures
Designed by
Adnan Niazi
Lab Engineer
Signal Processing/Signal & Systems Lab
CECOS University of IT & Emerging Sciences
13th- 14th Feb 2009
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Agenda
What are Loops
What is shift register
What are Sequence structures
What is case structure
What are tunnels
What is Mathscript window
What is Mathscript node
What is formula node
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Loops
Loops are used to perform some task over and over
again
Loops help in creating a compact code
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Loops
While Loop
Most widely used loop in LabVIEW
Used whenever the number of times a loop will execute,
is unknown before runtime
Current loop
Conditional stop
count
terminal
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Shift Register
Shift register shifts the output of one iteration of the
loop to the next iteration
Right click on the loop boundary and select Add Shift
Register
Shift register
Loop
iteration
Conditional terminal
count
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
While loop
Scenario: Design a VI that adds 2 to the results of the
previous iteration of the loop until a stop button is pressed
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
While loop with no timing controls
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Loops
Untimed Loops: loop with no timing controls
Untimed loops Run without any time interval between
successive iteration
This results in a 100% processor Usage which leaves no
processor real-estate for other processes
Always use some kind of timing controls in untimed
loops or use timed loops instead.
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
While loop with no timing controls
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Timing control
Insert delay between two successive loop iterations
using timing control
Wait (ms)
Timer value(ms)
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
While loop with timing controls
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Loops
For Loop
Used whenever the number of times a loop will execute
is known to you
Loop count starts from 0 to N-1 in LabVIEW
Number of Iterations
Current loop count
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
For Loop
Scenario: Design a VI that blinks an LED 10 times
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
For Loop
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Case Structure
Case structure is used different sections of code
depending on value of the select terminal
By default the select terminal is Boolean so there are
only two cases , TRUE and FALSE
There must always be a default case
Select terminal can be of 4 types:
Boolean
Numeric
String
Enum
008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Case Structure
Scenario: Design a VI that performs 10+5 if the user
selects True and 10- 5 if the user selects False
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Case Structure
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Tunnels
Tunnel are used to transport the data into and out of the
loops
Output
Input
Tunnel
Tunnels
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Case Structure
Scenario: We need to add, sub and multiply two
numbers(constants) depending on the value of the
numeric input that the user specifies
If the numeric input is 0, then add the two numbers
If the numeric input is 1 ,then subtract the two numbers
If the numeric input is 2, then multiply the two numbers
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Case Structure
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Sequence Structure
Executes sections of code in a sequence
Type of sequence structures
Flat Sequence Structures
Stacked Sequence Structure
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Flat Sequence Structure
Flat Sequence Structure
Used to execute code in a left to right sequence
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Flat Sequence Structure
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Stacked Sequence Structure
Stacked Sequence Structure
Works the same as flat sequence structure
Sequences are stacked over one another rather than
being spread from left to right
Results in more compact code than in flat sequence
structure
Being more compact, its difficult to understand
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Stacked Sequence Structure
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Mathscript Window
Its a Matlab like window where Matlab code could
written, tested and debugged just as in standard Matlab
Matlab Engine run behind the scene
Not all Matlab functions are supported in Mathscript
However, with each new release of LabVIEW, the support
for Matlab functions grows
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Mathscript Window
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Mathscript Node
Mathscript node allows you to integrate Matlab code
within the block diagram
You can copy existing Matlab code and paste it within
Mathscript node in block diagram
This integration of Matlab within block diagram reduces
the need to reinvent the wheel
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Mathscript Node
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Formula Node
Formula node is used to integrate C-like code within
LabVIEW
Its very cumbersome to graphically write complex and
long equations such as
Use formula node for writing these cumbersome and
long equation
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Formula Node
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Formula Node
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Task 1
Design a VI that takes two numeric inputs x and y and
one string input from the user.
If the string entered is add then the vi display x+y in the
result indicator
If the string entered is sub then the vi displays x-y in the
result indicator
In the string entered is mean or any other string (including
the empty string) then the result displayed is (x+y)/2
Refer to Task 1.vi in the Tasks folder if you have any
confusion about how the VI should behave
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Hints for task 1
Use case structure
Use string as a case selector
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Lab report for Task 1
The lab report must contain
Picture of the front panel
Picture of the add case
Picture of the sub case
Picture of the mean case
Note: Always write the question before beginning the
answer
©2008
09 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Task 2
Answer the following question
Question 1: What is an Array in LabVIEW
Question 2: In which situation an array is likely to be
used
Question 3: What is Cluster in LabVIEW
Question 4: In which situation a cluster is likely to be
used
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Lab Report for Task 2
The lab report for task 2 must contain
Give precise answers to the questions asked
No long stories required
Include pictures if possible
Instead of long paragraphs use bullets format
Important point 1
Important point 2
Important point 3
Note: Always write the question in the lab report so that I
can know which question are you answering to
©2008
09 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Ball Sorting Demo at NI week 2005
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences