This topic shows how to use the Analog Input Recorder app to view and record data from an NI USB-6218 device.
To open the Analog Input Recorder, on the MATLAB® Toolstrip, on the Apps tab, in the Test and Measurement section, double-click the Analog Input Recorder.
Upon opening, the Analog Input Recorder attempts to find all your attached analog input devices.
Opening the Analog Input Recorder deletes all your existing data acquisition sessions in MATLAB.
The data acquisition session created by the Analog Input Recorder is not accessible from the MATLAB command line.
If you plug in a device while the app is open, you must refresh the listing for access to the device. On the Devices tab, click Refresh. Use the same procedure to remove a device from the listing after unplugging it.
Select the device you want to use in the Device List. The app immediately starts a preview of the analog input using default settings.
Modify any scan and channel settings for your specific needs. The following image shows the app displaying three channels of the device. Notice that the Max Rate value has changed with the number of channels; this relationship depends on the device.
Set values for Number of Scans or Duration, and Rate.
Check Continuous if you want to override the duration or number of scans. In this mode, recording will continue until you explicitly stop it.
When you are ready to start recording data, click Record.
When recording is complete, either because the specified number of scan is recorded or you click Stop, the logged data is assigned to the indicated MATLAB Workspace variable. By default, the variable starts as DAQ_1, and its name is incremented with every recording, but you can specify any valid MATLAB variable name. The variable is assigned an M-by-N timetable, where M is the number of scans and N is the number of channels.
The following commands show the beginning of the acquired timetable for a multiple channel recording.
Name Size Bytes Class Attributes DAQ_4 1000x3 33315 timetable
View the first four rows of the timetable.
ans = 4×3 timetable Time ai0 ai1 ai2 _________ _______ ________ _______ 0 sec 0.59036 1.1226 1.6268 0.001 sec -1.0661 -0.49113 0.07001 0.002 sec -2.6327 -2.0683 -1.4901 0.003 sec -4.0592 -3.5349 -2.9738
The timestamp elements of the table are relative to the first scan. The absolute time of
the first scan is available in the timetable
UserData property. For
In the Analog Input Recorder, click Generate Code for the app to
open the MATLAB editor and display code for recording data. The following code is generated
for the finite (non-continuous) 3-channel recording of this example. Notice that this code
startForeground function; a continuous recording would use
% Auto-generated by Data Acquisition Toolbox Analog Input Recorder on 27-Jun-2017 14:05:11 %% Create Data Acquisition Session % Create a session for the specified vendor. s = daq.createSession('ni'); %% Add Channels to Session % Add channels and set channel properties, if any. addAnalogInputChannel(s,'Dev1','ai0','Voltage'); addAnalogInputChannel(s,'Dev1','ai1','Voltage'); addAnalogInputChannel(s,'Dev1','ai2','Voltage'); %% Acquire Data % Start the session in foreground. [data, timestamps, starttime] = startForeground(s); %% Log Data % Convert the acquired data and timestamps to a timetable in a workspace variable. ai0 = data(:,1); ai1 = data(:,2); ai2 = data(:,3); DAQ_4 = timetable(seconds(timestamps),ai0,ai1,ai2); %% Plot Data % Plot the acquired data on labeled axes. plot(DAQ_4.Time, DAQ_4.Variables) xlabel('Time') ylabel('Amplitude (V)') legend(DAQ_4.Properties.VariableNames) %% Clean Up % Clear the session and channels, if any. clear s