Data Acquisition Toolbox | ![]() ![]() |
Example: Logging and Retrieving Information
This example illustrates how to log information to a disk file and then retrieve the logged information to MATLAB using various calls to daqread
.
A sound card is configured for stereo acquisition, data is logged to memory and to a disk file, four triggers are issued, and 2 seconds of data are collected for each trigger at a sampling rate of 8 kHz. You can run this example by typing daqdoc8_1
at the MATLAB command line.
ai
for a sound card. The installed adaptors and hardware IDs are found with daqhwinfo
.
ai
.
file00.daq
.
duration = 2; % Two seconds of data for each trigger set(ai,'SampleRate',8000) ActualRate = get(ai,'SampleRate'); set(ai,'SamplesPerTrigger',duration*ActualRate) set(ai,'TriggerRepeat',3) set(ai,'LogFileName','file00.daq') set(ai,'LoggingMode','Disk&Memory')
ai
, wait for ai
to stop running, and extract all the data stored in the log file as sample-time pairs.
subplot(211), plot(data) title('Logging and Retrieving Data') xlabel('Samples'), ylabel('Signal (Volts)') subplot(212), plot(time,data) xlabel('Time (seconds)'), ylabel('Signal (Volts)')
Make sure ai
has stopped running before cleaning up the workspace.
ai
, you should remove it from memory and from the MATLAB workspace.
Retrieving Data Based on Samples
You can retrieve data based on samples using the Samples
property. To retrieve samples 1000 to 2000 for both sound card channels:
Plot the data and label the figure axes.
subplot(211), plot(data); xlabel('Samples'), ylabel('Signal (Volts)') subplot(212), plot(time,data); xlabel('Time (seconds)'), ylabel('Signal (Volts)')
Retrieving Data Based on Channels
You can retrieve data based on channels using the Channels
property. To retrieve samples 1000 to 2000 for the second sound card channel:
Plot the data and label the figure axes.
subplot(211), plot(data); xlabel('Samples'), ylabel('Signal (Volts)') subplot(212), plot(time,data); xlabel('Time (seconds)'); ylabel('Signal (Volts)')
Alternatively, you can retrieve data for the second sound card channel by specifying the channel name.
Retrieving Data Based on Triggers
You can retrieve data based on triggers using the Triggers
property. To retrieve all the data associated with the second and third triggers for both sound card channels:
Plot the data and label the figure axes.
subplot(211), plot(data); xlabel('Samples'), ylabel('Signal (Volts)') subplot(212), plot(time,data); xlabel('Time (seconds)'), ylabel('Signal (Volts)')
Retrieving Data Based on Time
You can retrieve data based on time using the Time
property. Time
must be specified in seconds and Time=0
corresponds to the first logged sample. To retrieve the first 25% of the data acquired for the first trigger:
Plot the data and label the figure axes.
subplot(211), plot(data); xlabel('Samples'), ylabel('Signal (Volts)') subplot(212), plot(time, data); xlabel('Time (seconds)'), ylabel('Signal (Volts)')
Retrieving Event, Object, Channel, and Hardware Information
You can retrieve event, object, channel, and hardware information by specifying the appropriate arguments to daqread
. For example, to retrieve all event information, you must return all the logged data.
[data,time,abstime,events,info] = daqread('file00.daq'); {events.Type} ans = 'Start' 'Trigger' 'Trigger' 'Trigger' 'Trigger' 'Stop'
If you retrieve part of the data, then only the events associated with the requested data are returned.
[data,time,abstime,events,info] = daqread('file00.daq', 'Trigger',[1 3]); {events.Type} ans = 'Trigger' 'Trigger' 'Trigger'
You can retrieve the entire event log as well as object and hardware information by including info
as an input argument to daqread
.
To return the event log information:
![]() | Retrieving Logged Information | softscope: The Data Acquisition Oscilloscope | ![]() |