Data acquisition using Matlab – Session-based interface

Goal

The purpose with this “home” laboratory assignment is to give you experience of using Matlab for sampling data with the NI USB-6009 device.

Instructions

The specific data you choose to sample can either be a signal from any source you find suitable in terms of signal levels etc allowed by the DAQ device or a signal generated by one of the signal generators in the “Practical test”/”Praktiskt prov” room. The course has six NI USB-6009 devices which you can use for this assignment. You have to take turns using them. For practical reasons we will keep 3 of them in the practical test room. Please note that these devices may NOT leave the room! However, if you decide to sample another signal than what can be generated with the signal generators in the practical test room, you may borrow one of the other three devices to take home for maximum 1 day. Come to Josefin and she will sort you out. You will have to sign an agreement, stating that you will bring the device back the next day.

Task

Specifically, your task is to write two Matlab scripts. Script 1 samples the signal with one of the AI channels and stores the sampled data on the harddrive.

Script 2 loads the data and plots the signal in two graphs, one time-amplitude plot and one power spectrum plot.

Refer to the Matlab Documentation Centre for detailed instructions of how to:

1. Set up an acquisition “session” add “channels” to the session 2. Acquire data on the channels 3. Stop and clear the session http://www.mathworks.se/help/daq/using-the-session-based-interface.html

Before you start, make sure that the required drivers are installed on your . You will need both the “Data Acquisition Toolbox” for Matlab and the NI DAQmx driver for communicating with the DAQ device. Type “ver” in the Matlab command window to check if the Data Acquisition Toolbox is installed on your computer. If it is not listed there, re- install Matlab using the university site license. It is included there. Open LabVIEW and the Measurement I/O tab to check if the NI-DAQmx VI:s are there. If they are not, download the driver from the www.ni.com webpage or borrow an installation dvd at the course secretary office. Please bring your computer there and do the installation at the department, do not take the dvd home with you!

Below follows some main steps to get you going. Please note that there will be additional steps in between the points in the list which you will have to do too.

1. Type daq.getDevices in the command window 2. Read the output and make sure you understand it 3. Open a blank m-file 4. Create a session (s = daq.createSession('ni');) 5. Add a channel to the session (s.addAnalogInputChannel('Dev1','ai0','Voltage')) 6. Set up the channel properly (sample rate, number of samples to acquire/number of seconds to sample data etc) 7. Acquire the data 8. Save the data 9. Load the data in another m-file designated for the analysis 10. Perform proper signal processing algorithms to the signal 11. Plot your results

If you need more information about how to use the commands, this is how you should proceed. 1) visit the home page http://www.mathworks.se/help/daq/using-the-session-based- interface.html and search for information there, 2) click the help button and search for documentation of the command there, 3) search for answers online at forums, 4) ask Josefin. The idea is to challenge you to find your answers yourself since this is what you will have to do in the “real world”.

Report

Write a 1-2 page report, describing how you solved the task. Include the plots from the scripts in the report and the m-files as an Appendix. The report should contain a detailed description of the signal you measured, how it was generated and your reflection on the use of this data acquisition system. Use the following questions as a guide (but do feel free to make your own reflections, other than these!). What are the possible drawbacks and advantages of using Matlab instead of LabVIEW? Give other examples of applications where you could use this approach. What would you have to do if you want to use transducers to measure a signal? E- mail the report and the m-files as three separate files to [email protected] no th later than 16 of December, 2014.