You are on page 1of 21

Signals, Spectra and Signal Processing

Name:__________________________________ Date Performed: _________________________ Rating:__________________________ Date Submitted: __________________

Signals, Spectra and Signal Processing GETTING FAMILIAR WITH LABVIEW (PART I) Activity No. 1 I. INTENDED LEARNING OUTCOMES 1. Familiarize oneself with the programming environment of LabVIEW. 2. Build a simple virtual instrument (VI) that uses commonly-used functions, controls and indicators of LabVIEW. 3. Create sub-VIs and use them in the development of more complex VIs. 4. Use the While-Loop structure in the development of a continuously running VIs. 5. Create a VI using an array and For-Loop. 6. Use the Help function of LabVIEW. II. BACKGROUND INFORMATION LabVIEW (Laboratory Virtual Instrumentation Engineering Workbench) is a graphical programming environment developed by National Instruments (NI), which allows high-level or system-level designs. It uses a graphical programming language to create so-called Virtual Instruments (VI) blocks in an intuitive flowchart-like manner. A design is achieved by integrating different components or subsystems within a graphical framework. LabVIEW provides data acquisition, analysis and visualization features well suited for various applications. It is also an open environment accommodating C and MATLAB codes, as well as ActiveX and DLLs (Dynamic Link Libraries).

LabVIEW constitutes a graphical programming environment that allows one to design and analyze a system in a shorter time as compared to text-based programming environments. LabVIEW graphical programs are called virtual instruments (VIs). VIs run based on the concept of data flow programming. This means that execution of a block or a graphical component is dependent on the flow of data, or more specifically a block executes when a data is made available at all of its inputs. Output data of the block are

Activity No. 1 Getting Familiar with LabVIEW (Part I)

Page 1

Signals, Spectra and Signal Processing


then sent to all other connected blocks. Data flow programming allows multiple operations to be performed in parallel since its execution is determined by the flow of data and not by sequential lines of code.

In this activity as well as in the next activity, the LabVIEW environment will be explored and basic VIs will be created.

III. LEARNING ACTIVITIES Activity 1.1 Building a Simple VI. 1. Open LabVIEW by double clicking the LabVIEW icon in the desktop or access it through the Start button of the Windows. The Getting Started window appears. Click on the Blank VI option to start from scratch.

2. Two new windows should appear: the Block Diagram (BD) window and the Front Panel (FP) window, as shown below.

Activity No. 1 Getting Familiar with LabVIEW (Part I)

Page 2

Signals, Spectra and Signal Processing


Save this VI by clicking on File > Save. The Name the VI dialog box appears. Indicate the location in which the file will be saved in the Save in: dropdown menu. Name the file as act01-01. Note that VIs has a .vi extension.

Note: It is encouraged that a folder be created where VIs can be organized by activity. It is possible that future activities will use VIs that were created in earlier activities. Also, ensure that a regular back-up of files be done as the computers in the laboratory are shared by everyone.

An FP contains the user interfaces of a VI shown in BD. Inputs to a VI are represented by so-called controls. Knobs, pushbuttons and dials are a few examples of controls. Outputs from a VI are represented by so-called indicators. Graphs, LEDs (light indicators), and meters are a few examples of indicators.

Numeric Controls palette

Buttons and Switches palette

Activity No. 1 Getting Familiar with LabVIEW (Part I)

Page 3

Signals, Spectra and Signal Processing

Text Controls palette

LEDs palette

Numeric Indicators palette

Text Indicators palette

Graph Indicators palette

All of these can be accessed via the controls palette by right-clicking on an empty space on the front panel or via View > Controls Palette. A BD contains terminal icons, nodes, wires and structures. Terminal icons are interfaces through which data are exchanged between an FP and a BD. Terminal icons correspond to controls or indicators that appear on an FP. Whenever a control or indicator is placed on an FP, a terminal icon gets added to the corresponding BD. Place a numeric control on the front panel (right-click on an empty space on FP or View > Controls Palette, Express, Numeric Control). Click on Num Ctrl and then drop onto the FP.

Activity No. 1 Getting Familiar with LabVIEW (Part I)

Page 4

Signals, Spectra and Signal Processing

Notice that when a numeric control is placed onto the FP, a terminal icon of the same name appeared on the BD, as shown. The FP and BD windows can be switched by pressing Ctrl+E. Note: When opening saved VIs, only the FP appears (try this by closing act01-01.vi and then opening the file again). Use Ctrl+E to make BD appear in this case.

Rename this Numeric Control as x by typing x when the Numeric label is selected (at the instance that a control or indicator is placed, its label is automatically selected). Note that the numeric control FP and its corresponding terminal icon in the BD are renamed. Put another Numeric Control and two Numeric Indicators and name them as y, Sum, and Average respectively.

Activity No. 1 Getting Familiar with LabVIEW (Part I)

Page 5

Signals, Spectra and Signal Processing


Note: Rename terminal icon labels by double-clicking its label and typing the new label. The label of the icons is the same as the variable name in text-based programming languages. Note: Notice the asterisk after the filename in the title bar of the BD and FP windows. This indicates that there are changes in the BD and FP which have not been saved. It disappears once the VI has been saved. To save VIs, click File > Save or use Ctrl+S. Note: In the FP, notice that numerical controls have white background while numerical indicators have gray background. This is to indicate that numbers in the numerical control can be changed by the user (user input) while the numbers on the numerical indicator depends on the operations performed on the inputs (output). Remember, in LabVIEW, controls are to inputs as indicators are to outputs. Note: In the BD, notice that the arrows of the control icons are pointing outwards the icon, while that of the indicator icons are pointing into the icon. This indicates the manner by how data is transferred to and/or from the icon. An arrow pointing out of the icon indicates that the data it holds is an input to another, while an arrow pointing into the icon indicates that it accepts data from an input.

3. A node represents an object which has input and/or output connectors and performs a certain function. A subVI (a VI that is used in another VI) and functions are examples of nodes. Functions and subVIs can only be placed in the BD. The Functions palette be accessed by clicking View > Functions Palette or by right-clicking empty space in the BD.

Activity No. 1 Getting Familiar with LabVIEW (Part I)

Page 6

Signals, Spectra and Signal Processing

Place an Add function in the block diagram. This can be accessed in the Functions > Express > Arith & Comparison > Numeric. Click and drop the Add node in the BD.

Note: Use the Search button in the Functions palette to search for BD functions. Type the name of the function (or some parts of it) and look for it in the list that the query generates. Then either double-click the selection to open the location of the function, or drag and drop the name from the list onto the BD.

Activity No. 1 Getting Familiar with LabVIEW (Part I)

Page 7

Signals, Spectra and Signal Processing

Place a Divide function in the BD. The Add function will get the sum of the two inputs x and y, while the Divide function will divide the sum by 2 to get their average.

Note: Make the label of the nodes visible by right-clicking the node, select Visible Items and checking the Label option. 4. Wires establish the flow of data in the BD. To connect the x control icon with the Add function, click on the x terminal icon, and then click on the one of the inputs of the Add function.
Activity No. 1 Getting Familiar with LabVIEW (Part I) Page 8

Signals, Spectra and Signal Processing


Note: When the mouse pointer is placed over an icon or a node, the cursor automatically changes to a wiring mouse pointer, and the inputs and/or outputs of an icon or node appears.

When it is fully connected, it becomes a solid line, whose color depends on the data type that it carries. There are basically three data types that LabVIEW supports: numeric, Boolean, and string. Numeric data represent numbers, which can be floating-point numbers (numbers with fractional parts) or integers (whole numbers). Boolean data represent those that have only two states: 1 or 0. String data represent alphanumeric characters. The table below summarizes the wire color representation of data types and their dimensions.

Note: These color representations are also applicable to the borders of terminal icons.
Activity No. 1 Getting Familiar with LabVIEW (Part I) Page 9

Signals, Spectra and Signal Processing


Wire the y input to the Add function, and the output of the Add function to the Divide function. Also, wire the output of the Add function to the input of the Sum indicator, and the output of the Divide function to the Average indicator. Refer to the illustration below.

Note: Broken wires occur for a variety of reasons, such as when two objects with incompatible data types are wired. Broken wires can be removed by pressing Ctrl+B.

Note: Terminal icons, by default, are viewed as icon. For more compact BDs, right-click on a terminal icon, then uncheck the View As Icon option.

Activity No. 1 Getting Familiar with LabVIEW (Part I)

Page 10

Signals, Spectra and Signal Processing

Since the average of x and y must be taken and displayed in the Average indicator, the sum of the two inputs should be divided by two. The first input to the Divide function is the sum of the two inputs; the second input should be a constant. To insert a constant, right-click on the other input of the Divide function and choose Create > Constant. Type the number 2 when the constant node appears.

Note: Observe all the screenshots before the above screenshot. The Run arrow in the previous screenshots are broken, which means that the program contains error and it cannot be executed. Once the program is error-free, the icon appears like the one shown above. 5. Save the program. Test the functionality of the program by putting values in the controls of the FP and clicking the Run button.

Activity No. 1 Getting Familiar with LabVIEW (Part I)

Page 11

Signals, Spectra and Signal Processing

Note: After building the block diagram, it can be made more compact and professional looking by clicking the Clean Up Diagram icon in the BD window.

Activity 1.2 Creating SubVI 1. A subVI is a VI that is used in a higher-level VI. If a VI is to be used as a subVI, its connector pane needs to be configured. A connector pane assigns inputs and outputs of a subVI to its terminals through which data are exchanged. The icon at the top-right corner of the FP or BD is the icon that represents the VI once it is used as a subVI.

Activity No. 1 Getting Familiar with LabVIEW (Part I)

Page 12

Signals, Spectra and Signal Processing


A connector pane can be displayed by right-clicking this icon in the FP and selecting Show Connector from the menu. The default pattern of a connector pane is determined based on the number of controls and indicators. In general, the terminals on the left side of a connector pane pattern are used for inputs, and the ones on the right side are for outputs. Terminals can be added to or removed from a connector pane by right-clicking and choosing Add Terminal or Remove Terminal from the menu. If a change is to be made to the number of inputs/outputs or to the distribution of terminals, a connector pane pattern can be replaced with a new one by right-clicking and choosing Patterns from the shortcut menu. In this case there are two inputs and two outputs. Choose the connector pane pattern that appropriately describes this case.

2. To assign controls and indicators to the connector pane, click on one of the slots of the pane and click a control or indicator to be assigned on that slot. Remember, controls are assigned to the left of the connector pane while indicators are assigned to the right.

Activity No. 1 Getting Familiar with LabVIEW (Part I)

Page 13

Signals, Spectra and Signal Processing


Continue assigning controls and indicators until all are assigned. Save the VI. 3. If this VI is to be used in a higher-level VI, it is important to edit the subVI icon for it to be explicitly identified. Double-click the VI icon. The Icon Editor window appears. The icon can be edited using the tools of this editor, which is very similar to the tools used in the Microsoft Paint. Try to edit the icon as shown below, then click OK.

Note: A subVI can also be created from a section of a VI. Use the Help function of LabVIEW to find out how to do this. Click Help > LabVIEW Help, or press Ctrl+? or F1 to bring out the Help window of LabVIEW. On the left pane, select the Search tab, then type Creating SubVIs from Sections of a VI to list topics related to this. This should generate an article about creating subVIs from a section of a VI. Activity 1.3 Using Structures and SubVIs 1. Create a new VI named as act01-03. This VI will show the sum and average of two input values in a continuous fashion. The two inputs can be altered by the user. If the average of the two inputs becomes greater than a preset threshold value, a LED warning light is lit.

Activity No. 1 Getting Familiar with LabVIEW (Part I)

Page 14

Signals, Spectra and Signal Processing


2. Create the FP as shown.

Input 1 and Input 2 are Knobs. The size of the knobs can be adjusted by selecting it and dragging the edges of the selection to the desired size. Right-click the Input 1 knob and choose Properties; the Knob Properties window appears. Click the Data Type tab. The default data type of this control is Double Precision (DBL). Change this to Byte (I8) type. Click OK. Note: This step can also be accomplished by right-clicking the knob then choosing Representation > Byte (I8). For the Input 2 knob, leave the data type as double precision. For both of the knobs, set both to zero, right-click the knob, then choose Data Operations > Make Current Value Default to make the default value of the knobs 0. The Warning LED is a Rounded LED indicator. The Average is a Gauge. The Sum is a Numeric Indicator. Place all of these in the FP and resize them accordingly.

3. At this point, there should be five terminal icons in the BD, corresponding to the controls and indicators in the FP. Build the BD as shown.

Activity No. 1 Getting Familiar with LabVIEW (Part I)

Page 15

Signals, Spectra and Signal Processing


The Sum and Average subVI, which is the VI created in the previous activities, can be obtained by right-clicking an empty space in the BD, then choose Select a VI.., which brings the Select a VI to Open window. Choose act01-01.vi. Note that this VI has two inputs and two outputs. To verify the labels of the inputs and outputs, roll the mouse over the VI. The Sum output of the subVI is connected to the Sum indicator, while the Average output is connected to the Average indicator. To enable the LED warning when the average reaches a value of at least 9, a Greater Or Equal? node is used. The first input of the Greater Or Equal? node should be the Average output of the Sum and Average subVI, while the second output is a constant 9. Note: The color of the Warning data is green, indicating it only accepts 1 or 0 as input (Boolean data type).

4. For the VI to run continuously, the program must be enclosed in a While structure. The While structure makes the function inside it run continuously (or stop indefinitely) until a condition is met. In this case, it is required that the program runs until a Stop button is pressed. The While structure is accessed by rightclicking an empty space in the BD, choose Express > Exec Control > While Loop. Drag the mouse until the entire program in the BD is enclosed within the While structure. The final FP and BD should look like the one below.

Note: Notice that when the While structure is placed, a Stop button is automatically inserted. This is the necessary condition that the loop will terminate. In general, a While loop must have a terminating condition or it will run indefinitely. A structure in LabVIEW is represented by a graphical enclosure. The graphical code enclosed by a structure is repeated or executed conditionally. A loop structure is equivalent to a for-loop or a while-loop statement encountered in text-based programming languages, while a case structure is equivalent to an if-

Activity No. 1 Getting Familiar with LabVIEW (Part I)

Page 16

Signals, Spectra and Signal Processing


else statement. To learn more about For Loop and While Loop Structure, as well as Case Structure references are available in the LabVIEW help. 5. Save and run the VI. Adjust the knob and verify the functionality of the VI. Question: How does the VI work? Discuss the functionality as observed from running the VI. _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ 6. Set the value of the Input 2 knob to zero. Note: The value at which the knob is set can be seen while it is being adjusted. Make adjustments to the knob of Input 1 and observe the value at the Sum numeric indicator. Question: What can be said about the set of values that the Input 1 takes? What is the data type of Input 1? What, then, can be inferred with the set of values that is represented by the data type like that of Input 1? _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ Question: Differentiate I64, I32, I16 and I8 data types. _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ 7. Set the value of Input 1 knob to zero, then make adjustments to the knob of Input 2, while observing the value of the numeric indicator. Question: What is the data type of Input 2? Compare the observations that have been made with the data types of Input 1 and Input 2. _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________
Activity No. 1 Getting Familiar with LabVIEW (Part I) Page 17

Signals, Spectra and Signal Processing


Question: Differentiate the data types EXT, DBL, SGL, and FXP. _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ 8. Stop the program from running by pressing the Stop button in the FP or by clicking the Stop icon in the BD or FP. Place a numeric indicator in the FP and in the BD then connect the output of the Greater or Equal? node to the input of this indicator. Question: What happens? Why? What are the possible indicators that can replace this numeric one? _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ Activity 1.4 Create an Array 1. In this activity, a set of random numbers will be generated containing ten elements. VIs having this function can be accomplished using an array and a For-Loop. To do this, create a VI whose name is act0104.vi. 2. Build the BD as shown.

Activity No. 1 Getting Familiar with LabVIEW (Part I)

Page 18

Signals, Spectra and Signal Processing


Place the Random Number (0-1) function in the BD. The Random Number (0-1) function generates a random number from 0 to 1. Create an indicator in the output of the Random Number (0-1) function and name it as Current Output. Place a Time Delay function in the BD. The Time Delay function causes the execution to be delayed by specified amount of time. When the Time Delay block is placed in the BD, the Configure Time Delay dialog box appears. Put 0.1 in the Time Delay (seconds) input box to set the time delay of the program execution to 0.1 seconds. Place a For-Loop structure in the BD, enclosing all blocks created so far inside. The For-Loop structure is used to repeat a certain operations n times, which is an input to the Loop Count indicator (N) in the For-Loop. To learn more about the For structure, refer to the LabVIEW Help. Create a constant in the Loop Count parameter of the For-Loop. Set this constant to 10. Wire the output of the Random Number (0-1) function to the border of the For-Loop. A tunnel is created. A tunnel interfaces the inside of the For-Loop to the outside. The tunnel created here should contain a [ ] inside. Note: The [ ] inside the tunnel indicates that the data type is array. By default, auto-indexing is enabled in a For-Loop and disabled in a While-Loop. Create another tunnel out of the For-Loop structure, this time, with the auto-indexing disabled. To disable auto-indexing, right-click the tunnel, then click Disable Indexing. Create indicators for each tunnel named Output with Indexing for the tunnel with enabled autoindexing and Output without Indexing for other one.

Question: Compare the wires connecting the indicators to the tunnels. Why is this so? _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________

Activity No. 1 Getting Familiar with LabVIEW (Part I)

Page 19

Signals, Spectra and Signal Processing


2. There should be three indicators in the FP which correspond to the nodes terminal icons in the BD. Build the FP as shown.

Expand the boxes for the Current Output and Output without Indexing. Drag the Output with Indexing downwards until ten indicators appear. Note: The Output with Indexing is an array indicator; it holds values in an array. The number of elements that is held by this array depends on how many iterations the For-Loop has, which in this case, ten. The index of an array always starts from zero; thus the first element of the Output with Indexing array has an index of zero, and the last element has an index of nine. 3. Save the VI and run the program. Question: Describe the functionality of the program. Compare the output of the Output with Indexing and Output without Indexing indicators. _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________

Activity No. 1 Getting Familiar with LabVIEW (Part I)

Page 20

Signals, Spectra and Signal Processing


IV. CONCLUSIONS _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ V. MACHINE PROBLEM Create a virtual instrument that uses the functions described in this activity. The requirements are: The VI must be applicable to real-life situations. The VI must have an appealing and interactive front panel. The VI must have a sound and logical block diagram that can be easily understood. Basic functions and structures used in this activity must be present in the created VI. Name the VI for this case study as macpro01.vi VI. REFERENCE Kehtarnavaz, N. & Kim, N. (2005). Digital Signal Processing System-Level Design Using LabVIEW. Oxford, United Kingdom: Elsevier, Inc.

Activity No. 1 Getting Familiar with LabVIEW (Part I)

Page 21

You might also like