Introduction to Modern Data Acquisition with Labview and MATLAB

Introduction to Modern Data Acquisition with Labview and MATLAB

Introduction to Modern Data Acquisition with LabVIEW and MATLAB By Matt Hollingsworth Introduction to Modern Data Acquisition Overview.......... 1 LabVIEW Section1.1:IntroductiontoLabVIEW.......... 3 Section1.2:ASimpleLabVIEWProgram.......... 5 Section1.3:StructuresandExecutionControl.......... 10 Section1.4:DataandExecutionFlow.......... 17 Section1.5:InteractiveLabVIEWPrograms.......... 20 Section1.6:SubVI’s.......... 23 Section1.7:SavingData.......... 27 Section1.8:DataAcquisition.......... 29 Section1.9:ClosingComments.......... 31 MATLAB Section2.1:IntroductiontoMATLAB.......... 33 Section2.2:SimpleMathwithMATLAB.......... 35 Section2.3:MatricesandVectors.......... 37 Section2.4:M-Files.......... 40 Section2.5:VisualizingData.......... 42 Section2.6:ImportingData.......... 45 Section2.7:ClosingComments.......... 46 Lab Section3.1:Introduction.......... 48 Section3.2:Equipment.......... 49 Section3.3:Goals.......... 50 Section3.4:MATLABandLabVIEWTips.......... 52 TableofContents Overview Goal:Tolearntousethevariouscomputertoolsavailabletoacquireandanalyzeexperimen- taldata. Materials: •ComputerwithLabVIEWandMATLAB •NIUSB-6008 •SummaSketchIII •Conductivepaperwithelectrodes •Variouscables •Brain Thislabexerciseismeanttogiveasweepingoverviewofacoupleofthetoolsavailabletoa modernexperimentalphysicist.ThetoolsthatthisexercisewillfocusuponareLabVIEWandMAT- LAB. Ingeneral,LabVIEWisausefulprogramminglanguagewhenyouneedtoproducesomecode thatwillacquiresomedatainalabenvironment.Youcanquicklycreatecodethatwillallowyou toacquiresomedata,dosomedataanalysis,displayreal-timeresultsofthatdata,andexportit inaformatthatwillbecapableofbeingreadbyotherdataanalysissoftware(suchas,inourcase, MATLAB). MATLAB,ontheotherhand,isahandymathematicaltoolboxthatcomeswithmanyfeatures thatareusefulfordataanalysis.Itisalsoawidelyacceptedindustrystandard,soLabVIEWcomes withbuilt-insupportfordirectlyinterfacingwiththescriptserverforMATLAB.Thisallowsyouto inputcommandsfromLabVIEWdirectlyintotheMATLABkernelandhavethemexecutedasifyou weretypingthemintheMATLABcommandwindow.Wewillbeexploitingthisfeatureinorderto generate some detailed visualization of the electric field between two electrodes. Thispaperwillnotbutscratchthesurfaceofthefunctionalityavailabletoyouthroughthe LabVIEWandMATLABplatforms;however,mygoalistomakeyouconversantenoughtowhereyou knowwhatquestionstoask/documentationtosearchforandyoucanunderstandtheanswersthat youaregiven.Themoreacutefunctionalityisleftforyoutodiscoveryourselfasyouneedit. Furthermore,ifyoualreadyknowsomethingthatIamdiscussingintheLabVIEWand/orMAT- LABsections,feelfreetoskipitandmoveontosomethingelse.Therearenoexercisesorany- thing in those two sections; the most important thing is that you are able to perform the final task presentedtoyouintheactuallab. In case you are having trouble, each example has its corresponding .vi or .m file on my web siteathttp://www.evanescenthorizons.com/. To find the examples, look under Labs > Introduc- tiontoModernDataAcquisition. Ifyougetstuckorhaveanyquestions,comments,complaints,orcorrections,feelfreetoe- [email protected]’dbemorethanhappytohelp,andIwelcomeyourfeedback. Overvew LabVIEW Section 1.1: Introduction to LabVIEW LabVIEWisagraphicalprogramminglanguage/IDEcombinationthatistailoredforuseina labenvironment.ThebasicanalogythroughoutLabVIEWisthatofavirtualinstrumentorVI.Ina LabVIEWprogram,justlikearealinstrument,youhavecontrols(input),indicators(output),and logic to define the relationship between input and output. Here is a sample of a very basic LabVIEW program: Figure 1.1.1 Asyoucanprobablyalreadytell,thisprogramtakestwonumbers,xandy,andoutputsits sum. In LabVIEW, the lines that show data flow (in this case, they are thin orange lines, meaning theyaresinglelength,doubleaccuracynumbers)arecalledwires.Inputsarecalledcontrolsand outputsarecalledindicators.TheplussigninsidethetriangleiscalledasubVI,whichisanalogous toasubroutineorfunctionintext-basedlanguages.Inthiscase,thesumsubVIacceptstwonum- bersasargumentsandoutputsthesum. Secton.:IntroductontoLabVIEW LogicandinterfacearetwoseparateentitiesinaLabVIEWprogram.Theinterfaceiscalled the front panel, while the programming logic itself is called the block diagram. Here is the front panelfortheprogrampicturedabove: Figure 1.1.2 Inordertorunaprogram,yousimplyclicktherunarrowinthetopleftcorner.Totoggle loopedexecution,clickthebuttonwiththerevolvingarrows(thiscausestheprogramtoruncon- tinuously).Themainprogramexecutionbuttonsaredetailedbelow. Figure1.1.3-TypicalExecutionBar :RunButton :RunContinuouslyButton :AbortButton :PauseButton Secton.:IntroductontoLabVIEW Section 1.2: A Simple LabVIEW Program TobeginwritinganewLabVIEWprogram,simplystartupLabVIEW,clicknew,andselectblank VIwhenyouareaskedforatemplate.Younowhaveablankfrontpanelandablankblockdia- gram.Navigatetothemenubaratthetopofthescreen,clickwindow,andselect“ShowBlock Diagram”(orpressCtrl+E).Rightclickanywhereinthewhitespaceoftheblockdiagramtopop upthefunctionsmenu.Click“AllFunctions”inthebottomrightofthepopupwindow,andthen clickthethumbtackinthetoprightcornertokeepthefunctionswindowopen.Yourscreenshould looksomethinglikethis: Figure 1.2.1 Clickonthenumericboxinthefunctionspallet(theonwiththe+andthe123init).Click anddragasumsubVIandamultiplicationsubVIontotheblockdiagram.Nowwehavesomepro- Secton.:ASmpleLabVIEWProgram gramlogic,butweneedsomethingtoinputdata.Navigatebacktothefrontpanelbyselect- ing Window > Show Front Panel from the menu bar at the top. Right click anywhere on the front panel,selectthe“NumCtrls”box,andclickanddraga“NumCtrl”ontothefrontpanel.Repeat sothattherearetwonumericcontrolsonthefrontpanel.Doubleclickonthelabelofoneofthe controls(“Numeric”bydefault)tochangethenameofthecontrolto“x”.Changetheotherto “y”.Afterallissaidanddone,yourfrontpanel/blockdiagramshouldlooksomethinglikethis: Figure 1.2.2 Secton.:ASmpleLabVIEWProgram Now,wewilltellLabVIEWtooutputz,wherez=(x+y)*x.Todothis,wewirexandytothe sumsubVI,wiretheoutputofsumtooneoftheinputsofmultiply,andthenwirextotheother inputofmultiply,likeso: Figure 1.2.3 *Side Note* Ifyoueverseewiresappearasdottedlineswithx’sinvariousplacesonthem, youwiredsomethingwrong.Ifthishappensyoumayeitherrightclickthewireandtellittodelete the wire branch, left-click somewhere on the wire and finish wiring it properly, or hit Ctrl + B to removeallbrokenwiresfromtheblockdiagram. Nowallthatisleftistocreateanindicator.Youcanreturntothefrontpanelandcreatea numericindicatorthesamewaythatyoucreatedthenumericcontrols,butthereisaquickerway. RightclickontheoutputofthemultiplicationsubVI(therightmosttipofthetriangle).You’llsee a menu pop up; select Create > Indicator. LabVIEW adds and automatically wires an indicator the output.Forfuturereference,youmaydothesamethingwhencreatingbothindicatorsandcon- stantterms. Here is the completed VI: Secton.:ASmpleLabVIEWProgram Figure 1.2.4 Theprogramisnowcomplete.Now,totestyournewVIsimplyclicktherunbutton( )to runyourVI.Everytimethatyouchangex/yandruntheVI,youshouldseeanoutput,called“out- put”inourprogram,thatcorrespondstooutput=x*(x+y) Ifyourprogramisnotfunctioningproperly,youmayalwaysclickthelittlelightbulbthatis by the pause button in the menu bar of the block diagram. When this button is toggled, “Highlight ExecutionMode”isturnedon.Thisallowsyoutoseeyourprogramexecutestepbystep—avery usefuldebuggingfeature. Furthermore, you may go to Window > Show Tools Palette, and place a probe on a wire by clickingthe buttonandthenclickingonawireofwhichyouwouldliketomonitortheoutput. Here is what a probed VI with execution highlighting turned on looks like. Secton.:ASmpleLabVIEWProgram Figure 1.2.5 Itisnotnecessarythateveryinitialinputbeeithertheoutputofacontrolortheoutputof anothersubVI.Ifdesired,youmayalsowireaconstanttoaninputofasubVI.Toaddanumerical constant, go to the numerical palette and find the numerical constant object (the blue box with 123init).Putitontheblockdiagram.Youcanthenrightclickonitandgoto“Representation” tochoosethedatatype(doubleprecision,longinteger,shortinteger,etc).Youcanthenwirethis constanttoanynumericalinputofasubVI.Thereareothertypesofconstants,suchasarraycon- stants,enumconstants,ringconstants,etc.,andtheyallworkthesameway. Finally, if you ever get stuck, you should turn on the Context Help feature. To enable this feature, go to the help menu and click “Show Context Help.” As long as this mode is on, whenever youhoveroverasubVIawindowwillshowyouhelpinformationpertainingtotheusageofthat particularVI.ThisisquiteusefulasaquickreferencefortimesinwhichyouknowwhatasubVI does,butdon’tknowexactlyhowtouseit. Secton.:ASmpleLabVIEWProgram Section 1.3: Structures and Execution Control Justaswithanyotherprogramminglanguage,LabVIEWcomescompletewithforloopsand whileloops.A“forloop”loopssomecodeasetnumberoftimes,anda“whileloop”loopsuntila certainconditionismet.InLabVIEW,loopsarerepresentedbyaboxthatsurroundsthecodethat isbeinglooped.Forexample,thefollowingcodecountsfrom1to10on1secondintervals: Figure 1.3.1 0 Secton.:StructuresandExecutonControl Thedemonstratedloopisaforloop.Nisthenumberofiterationsyouwouldliketodo,and iisthezerobasedindexofthecurrentiteration.Anequivalentwaytoformulatethisalgorithm, usingawhileloopinstead,canbedonelikeso: Figure 1.3.2 Inawhile loop,thestopsignistheterminationcondition.Inthiscase,thestopconditionisthattheitera- tionindex+1=10,whichisequivalenttoaforloopwithN=10.Bydefault,theloopterminates if the condition is true. However, you may change this to continue as long as the condition is true Secton.:StructuresandExecutonControl byrightclickingonthestopsignandselected“continueiftrue.”Thiscodetakesthelogisticmap,

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    57 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us