labview graph, chart

20

Upload: sundari-muthu

Post on 04-Oct-2015

15 views

Category:

Documents


0 download

DESCRIPTION

graph, chart and array

TRANSCRIPT

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 1

    EKT314/4 ELECTRONIC INSTRUMENTATION

    LabVIEW Graphs, Charts, Arrays, and ClustersPREPARED BY:

    DR. ZULKIFLI HUSIN

    Instructors Portion

    SummaryThe students will learn about the differences and similarities betweengraphs and charts and when to use each. They will also write simple VIsto incorporate arrays and clusters in LabVIEW as a means of combiningdata.

    UsesThis homework applies to all general instrumentation courses.

    Equipment ListComputer with LabVIEW

    ReferencesLabVIEW Users Manual. November 20xx. Part Number 320999D-01.LabVIEW Student Edition.

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 2

    Students Portion

    IntroductionIn this homework, you will learn about the differences and similaritiesbetween graphs and charts and when to use each. You will also writesimple VIs to incorporate arrays and clusters in LabVIEW as a means ofcombining data.

    ObjectiveLearn the difference between a chart and a graph.Differentiate between the three update modes of a chart.Learn how to create an array and manipulate it.Learn the difference between a cluster and an array.

    TheoryLabVIEW Graphs, Charts, Arrays, and ClustersIntroductionIn this section you will learn about graphs and charts, their similarities anddifferences, and when to use each. You will also study arrays and clusters,two ways to group data.Graphs and Charts

    Use graphs and charts to display plots of data in a graphical form.

    Graphs and charts differ in the way they display and update data. VIs withgraphs usually collect the data in an array and then plot the data to thegraph, which is similar to a spreadsheet that first stores the data then

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 3

    generates a plot of it. In contrast, a chart appends new data points to thosealready in the display. On a chart, you can see the current reading ormeasurement in context with data previously acquired.

    The graphs and charts located on the ControlsGraph palette include thefollowing types:

    Waveform Chart and GraphDisplays data acquired at a constantrate.

    XY GraphDisplays data acquired at a non-constant rate, such as dataacquired when a trigger occurs.

    Intensity Chart and GraphDisplays 3D data on a 2D plot by usingcolor to display the values of the third dimension.

    Digital Waveform GraphDisplays data as pulses or groups of digitallines. Computers transfer digital data to other computers in pulses.

    (Windows) 3D GraphsDisplays 3D data on a 3D plot in an ActiveXobject on the front panel.

    You customize the appearance of graphs and charts by showing or hidingoptions. Right-click the graph or chart and select Visible Items from theshortcut menu to display or hide the following options:

    Plot LegendDefines the color and style of the plot(s). Resize thelegend to display multiple plots.

    Scale LegendDefines labels for scales and configures scale properties.

    Graph PaletteChanges scaling and formatting while a VI is running.

    X Scale and Y ScaleFormats the x- and y-scales.

    Cursor Legend (graph only)Displays a marker at a defined pointcoordinate. You can display multiple cursors on a graph.

    Scrollbar (chart only)Scrolls through the data in the chart. Use thescroll bar to view data that the buffer does not currently display.

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 4

    Arrays

    Arrays group data elements of the same type. An array consists ofelements and dimensions. Elements are the data that make up the array. Adimension is the length, height, or depth of an array. An array can haveone or more dimensions and as many as 231 1 elements per dimension,memory permitting.

    You can build arrays of numeric, Boolean, path, string, waveform, andcluster data types. Consider using arrays when you work with a collectionof similar data and when you perform repetitive computations. Arrays areideal for storing data you collect from waveforms or data generated inloops, where each iteration of a loop produces one element of the array.

    You cannot create arrays of arrays. However, you can use amultidimensional array or create an array of clusters where each clustercontains one or more arrays.

    IndexesTo locate a particular element in an array requires one index perdimension. In LabVIEW, indexes let you navigate through anarray and retrieve elements, rows, columns, and pages from anarray on the block diagram.

    Examples of ArraysAn example of a simple array is a text array that lists the nineplanets of our solar system. LabVIEW represents this as a 1D arrayof strings with nine elements.

    Array elements are ordered. An array uses an index so you canreadily access any particular element. The index is zero-based,which means it is in the range 0 to n 1, where n is the number ofelements in the array. For example, n = 9 for the nine planets, sothe index ranges from 0 to 8. Earth is the third planet, so it has anindex of 2.

    Another example of an array is a waveform represented as anumeric array in which each successive element is the voltagevalue at successive time intervals.

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 5

    A more complex example of an array is a graph represented as anarray of points where each point is a cluster containing a pair ofnumerics that represent the X and Y coordinates.

    The previous examples use 1D arrays. A 2D array stores elementsin a grid. It requires a column index and a row index to locate anelement, both of which are zero-based.

    For example, a chessboard has eight columns and eight rows for atotal of 64 positions. Each position can be empty or have one chesspiece. You can represent a chessboard as a 2D array of strings.Each string is the name of the piece that occupies thecorresponding location on the board, or an empty string if thelocation is empty.

    Restrictions for ArraysYou can create an array of almost any data type, with the followingexceptions:

    You cannot create an array of arrays. However, you can use amultidimensional array or use the Build Cluster Array function tocreate an array of clusters where each cluster contains one or morearrays.

    You cannot create an array of non-XY graphs because a graph isan array data type and an array cannot contain another array.However, you can have an array of non-XY graphs if the graph isin a cluster.

    You cannot create an array of charts.

    Creating Array Controls, Indicators, and ConstantsCreate an array control or indicator on the front panel by placingan array shell on the front panel and dragging a data object orelement, which can be a numeric, Boolean, string, path, refnum, orcluster control or indicator, into the array shell.

    The array shell automatically resizes to accommodate the newobject, whether a small Boolean control or a large 3D graph.

    To display a particular element on the front panel, either type theindex number in the index display or use the arrows on the indexdisplay to navigate to that number.

    To create an array constant on the block diagram, selectFunctionsArrayArray Constant to place the array shell on the

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 6

    front panel, then place a string constant, numeric constant, orcluster constant in the array shell. You can use an array constant asa basis for comparison with another array.

    Array Index DisplayA 2D array contains rows and columns. The upper display of thetwo boxes on the left is the row index and the lower display is thecolumn index. The combined display to the right of the row andcolumn displays shows the value at the specified position.

    Rows and columns are zero-based, meaning the first column iscolumn 0, the second column is column 1, and so on. Changing theindex display for the following array to row 1, column 2 displays avalue of 6.

    If you try to display a column or row that is out of the range of thearray dimensions, the array control is dimmed to indicate that thereis no value defined, and LabVIEW displays the default value of thedata type. The default value of the data type depends on the datatype of the array.

    Use the Positioning tool to show more than one row or column at atime.

    Array Functions

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 7

    Use the Array functions located on the FunctionsArray palette tocreate and manipulate arrays, such as the following tasks:

    Extract individual data elements from an array.

    Insert, delete, or replace data elements in an array.

    Split arrays.

    Automatically Resizing Array FunctionsThe Index Array, Replace Array Subset, Insert Into Array, DeleteFrom Array, and Array Subset functions automatically resize tomatch the dimensions of the input array you wire. For example, ifyou wire a 1D array to one of these functions, the function shows asingle index input. If you wire a 2D array to the same function, itshows two index inputsone for the row and one for the column.

    You can access more than one element, or subarray (row, column,or page) with these functions by using the Positioning tool tomanually resize the function. When you expand one of thesefunctions, the functions expand in increments determined by thedimensions of the array wired to the function.

    If you wire a 1D array to one of these functions, the functionexpands by a single index input. If you wire a 2D array to the samefunction, the function expands by two index inputsone for therow and one for the column.The index inputs you wire determine the shape of the subarray youwant to access or modify. For example, if the input to an IndexArray function is a 2D array and you wire only the row input, youextract a complete 1D row of the array. If you wire only thecolumn input, you extract a complete 1D column of the array. Ifyou wire the row input and the column input, you extract a singleelement of the array. Each input group is independent and canaccess any portion of any dimension of the array.

    To access multiple consecutive values in an array, expand theIndex Array function, but do not wire values to the index inputs ineach increment. For example, to retrieve the first, second, and thirdrows from a 2D array, expand the Index Array function by threeincrements and wire 1D array indicators to each sub-array output.

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 8

    Clusters

    Clusters group data elements of mixed types, such as a bundle of wires, asin a telephone cable, where each wire in the cable represents a differentelement of the cluster. A cluster is similar to a record or a struct in text-based programming languages.

    Bundling several data elements into clusters eliminates wire clutter on theblock diagram and reduces the number of connector pane terminals thatsubVIs need. The connector pane has, at most, 28 terminals. If your frontpanel contains more than 28 controls and indicators that you want to useprogrammatically, group some of them into a cluster and assign the clusterto a terminal on the connector pane.

    Although cluster and array elements are both ordered, you must unbundleall cluster elements at once rather than index one element at a time. Youalso can use the Unbundle By Name function to access specific clusterelements. Clusters also differ from arrays in that they are a fixed size. Likean array, a cluster is either a control or an indicator. A cluster cannotcontain a mixture of controls and indicators.

    Most clusters on the block diagram have a pink wire pattern and data typeicon. Clusters of numerics, sometimes referred to as points, have a brownwire pattern and data type icon. You can wire brown numeric clusters toNumeric functions, such as Add or Square Root, to perform the sameoperation simultaneously on all elements of the cluster.Cluster elements have a logical order unrelated to their position in theshell. The first object you place in the cluster is element 0, the second iselement 1, and so on. If you delete an element, the order adjustsautomatically. The cluster order determines the order in which theelements appear as terminals on the Bundle and Unbundle functions on theblock diagram. You can view and modify the cluster order by right-clicking the cluster border and selecting Reorder Controls In Clusterfrom the shortcut menu.

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 9

    To wire clusters, both clusters must have the same number of elements.Corresponding elements, determined by the cluster order, must havecompatible data types. For example, if a double-precision floating-pointnumeric in one cluster corresponds in cluster order to a string in the othercluster, the wire on the block diagram appears broken and the VI does notrun. If numerics of different representations, LabVIEW coerces them tothe same representation.

    Use the Cluster functions located on the FunctionsCluster palette tocreate and manipulate clusters, such as the following tasks:

    Extract individual data elements from a cluster.

    Add individual data elements to a cluster.

    Break a cluster out into its individual data elements.

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 10

    Homework ProcedurePart 1. Temperature Monitor VIComplete the following steps to build a VI that uses a While Loop and awaveform chart to acquire and display data.1. Open a new VI.

    2. Build the following front panel.

    a. Select the vertical toggle switch on the ControlsBooleanpalette and place it on the front panel. You will use the switch tostop the acquisition.

    b. Type 4S[IV inside the label and click outside the label or clickthe Enter button on the toolbar.

    c. Select a waveform chart on the ControlsGraph palette andplace it on the front panel. The waveform chart will display thetemperature in real time.

    d. Type 8IQTIVEXYVI ,MWXSV] inside the label and clickoutside the label or click the Enter button.

    e. The waveform chart legend labels the plot 4PSX . Use theLabeling tool to triple-click 4PSX in the chart legend, type

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 11

    8IQT, and click outside the label or click the Enter button torelabel the legend.

    f. The temperature sensor measures room temperature. Use theLabeling tool to double-click in the y-axis, type , andclick outside the label or click the Enter button to rescale thechart.

    g. Change z in the y-axis to .

    h. Label the y-axis 8IQT (IK * and the x-axis 8MQI WIG.3. SelectWindowShow Diagram to display the block diagram.

    4. Enclose the two terminals in a While Loop, as shown in the followingblock diagram.

    a. Select the While Loop on the FunctionsStructures palette.

    b. Click and drag a selection rectangle around the two terminals.

    c. Use the Positioning tool to resize the loop, if necessary.

    5. Select FunctionsTutorialDigital Thermometer.vi. This VI returnssimulated temperature measurements.

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 12

    6. Wire the block diagram objects as shown in the previous block diagram.

    7. Save the VI as 8IQTIVEXYVI 1SRMXSVZM.

    8. Display the front panel by clicking it or by selectingWindowShow Panel.

    9. Use the Operating tool to click the vertical toggle switch and turn it tothe ON position.

    10. Run the VI.

    The section of the block diagram within the While Loop border, orsubdiagram, executes until the specified condition is TRUE. For example,while the switch is on (TRUE), the Thermometer VI takes and returns anew measurement and displays it on the waveform chart.

    11. Click the vertical toggle switch to stop the acquisition. The conditionis FALSE, and the loop stops executing.

    12. Format and customize the X and Y scales of the waveform chart.a. Right-click the chart and select Y ScaleFormatting from theshortcut menu. A dialog box appears.

    b. Click the Scale Style icon and select different styles for the y-axis. You also can select different mapping modes, grid options,scaling factors, and formats and precisions.

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 13

    c. Select the options shown in the previous dialog box and click theOK button.

    13. Right-click the waveform chart and select Data OperationsClearChart from the shortcut menu to clear the display buffer and reset thewaveform chart. If the VI is running, you can select Clear Chart from theshortcut menu.

    14. Modify the vertical toggle switch so temperature is plotted on thegraph each time you run the VI.

    a. Stop the VI if it is running.

    b. Use the Operating tool to click the vertical toggle switch andturn it to the ON position.

    c. Right-click the switch and select Data OperationsMakeCurrent Value Default from the shortcut menu. This sets the ONposition as the default value.

    d. Right-click the switch and selectMechanical ActionLatchWhen Pressed from the shortcut menu.

    15. Run the VI.

    16. Use the Operating tool to click the vertical switch to stop theacquisition. The switch changes to the OFF position and changes back toON after the conditional terminal reads the value.

    When this VI runs, the While Loop executes as quickly as possible.Complete the following steps to take data at certain intervals, such as onceevery half-second, as shown in the following block diagram.

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 14

    a. Place the Wait Until Next ms Multiple function located on theFunctionsTime & Dialog palette. This function makes sure thateach iteration occurs every half-second (500 ms).

    b. Right-click the millisecond multiple input of the Wait UntilNext ms Multiple function, select CreateConstant from theshortcut menu, type , and press the key. The numericconstant specifies a wait of 500 ms so the loop executes once everyhalf-second.

    c. On the front panel, right-click the chart and select XScaleFormatting from the shortcut menu. Change the X value to because you added a 500 ms wait between loop iterations.

    17. Save the VI.

    18. Run the VI.

    19. Try different values for the numeric constant and run the VI again.

    20. Close the VI.

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 15

    Part 2. Temperature Analysis VI

    In Part 2, you will use charts, graphs, arrays, and clusters to build a VI thatmeasures temperature every 0.25 s for 10 s. During the acquisition, the VIdisplays the measurements in real time on a waveform chart. After theacquisition is complete, the VI plots the data on a graph and calculates theminimum, maximum, and average temperatures. The VI displays the bestfit of the temperature graph.

    1. Open a new VI and build the following front panel using the followingtips.

    Set the point style of the waveform chart plot to a small x.

    Hide the plot legend of the waveform chart.

    Right-click the waveform chart, select X ScaleFormatting from theshortcut menu, and change .X to 0.25 and Digits of Precision to 2.

    Use the Positioning tool to resize the plot legend of the waveform graph.

    Use the Labeling tool to rename Plot 0 to Temp and Plot 1 to Fitted.

    Set the point style of the waveform graph Temp plot to a small square.

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 16

    Do not create theMean,Max, andMin indicators yet.

    2. Build the following block diagram.

    a. Select FunctionsTutorialDigital Thermometer.vi. This VIreturns simulated temperature measurements.

    b. Place the Wait Until Next ms Multiple function located on theFunctionsTime & Dialog palette and create a constant of 250.This function causes the For Loop to execute every 0.25 s (250ms).

    c. Place the Array Max & Min function located on theFunctionsArray palette. This function returns the maximum andminimum temperature.

    d. Place the Mean VI located on theFunctionsMathematicsProbability and Statistics palette. ThisVI returns the average of the temperature measurements.

    e. Right-click the output terminals of the Array Max & Minfunction and Mean VI and select CreateIndicator from theshortcut menu to create theMax,Min, andMean indicators.

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 17

    f. Place the General Polynomial Fit VI located on theFunctionsMathematicsCurve Fitting palette. This VI returnsan array that is a polynomial fit to the temperature array.

    g. Place the Bundle function located on the FunctionsClusterpalette. Press the key while you drag the function to copy it.This function assembles the plot elements into a single cluster.

    The elements include the initial x value (0), the .x value (0.25), andthe y array of temperature data. The .x value of 0.25 is required sothat the VI plots the temperature array points every 0.25 s on thewaveform graph.

    h. Place the Build Array function located on the FunctionsArraypalette. This function creates an array of clusters from thetemperature cluster and the best fit cluster.

    3. Save the VI as 8IQTIVEXYVI %REP]WMWZM.

    4. Display the front panel and run the VI.

    The graph displays both the temperature data and best fit curve of thetemperature waveform.

    5. Try different values for the polynomial order constant on the blockdiagram and run the VI again.

    6. Change the appearance of plots by modifying the plot styles and fillstyles.

    a. Right-click the Temp plot display in the plot legend and selectCommon PlotsScatter Plot from the shortcut menu, the topmiddle option.

    b. Right-click the Fitted plot display in the plot legend, select BarPlots from the shortcut menu, and select the second option in themiddle row.

    7. Save and close the VI.

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 18

    Part 3. Find Mid Value VI

    In Part 3, you will apply your knowledge of arrays to write a VI toimplement various array functions.

    Build a VI that first accumulates an array of temperature values using theDigital Thermometer VI. Incorporate these items:

    Set the array size with a control on the front panel.

    Initialize an array using the Initialize Array function of thesame size where all the values are equal to .

    Add the two arrays, calculate the size of the final array, andextract the middle value from the final array.

    Display the Temperature Array, Initialized Array, FinalArray, andMid Value.

    Save the VI as *MRH 1MH :EPYIZM.

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 19

    Homework ReportSubmit your report according the standard format and include alsothe answers to the questions below. Due on .

    Data SheetQuestions1. How is a chart different from a graph?

    2. What are the three update modes of a chart? Briefly describe each.

    3. How do you create an array?

    4. Below is a 2D array:2 4 7 5 16 9 3 4 52 5 8 4 9

    a. What number is at index [1,3]?b. If you used an Array Subset function on the above array, and assignedthe following input values (in order):index: 2length: 3index: 3length: 2

    What value(s) would be returned? Would it be a 1D or 2D array?

  • UNIVERSITI MALAYSIA PERLISSCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING

    Semester II, 2014/2015 20

    5. How is a cluster different than an array?

    6. What is the difference between the Bundle and Bundle by Namefunctions? Unbundle and Unbundle by Name?