Documentation Center

  • Trial Software
  • Product Updates

Managing Large Data Sets by Logging to Disk

This example shows how to log a data acquisition session. There are a number of reasons to do this: acquiring large data sets that would not normally fit into memory, or acquiring data samples that we plan on examining at a later time.

Note: This can only be run using the 32-bit version of MATLAB® and Data Acquisition Toolbox™. To learn more about using data acquisition devices on other platforms, see this example.

Creating and Configuring an Analog Input Object

Before acquiring any data, you must create an analog input object and specify the channels from which to acquire data. You may need to modify the following code to match your acquisition hardware.

ai = analoginput('winsound');
addchannel(ai, 1);

Configure the analog input object for acquisition. The configuration we will use is:

  • 1000 samples per trigger

  • repeat the trigger 20 times, for a total of 21 triggers

  • A sample rate of 44100 samples per second

set(ai, 'SamplesPerTrigger', 1000);
set(ai, 'TriggerRepeat', 20);
set(ai, 'SampleRate', 44100);

Configuring the Analog Input Object to Log to Disk

Now configure the acquisition to log to disk.

set(ai, 'LoggingMode', 'Disk');

When logging to disk, you can specify what file to write to. To alter the name of the log file, set the LogFileName property.

set(ai, 'LogFileName', 'LogFile.daq');

You can now begin your acquisition.

%Start the acquisition and wait for it to finish
wait(ai, 2);

Extracting Logged Data

When our data acquisition is complete, extract the data samples you have collected.

data = daqread('LogFile.daq');

You can also obtain a time vector that represents the time stamp of each data sample relative to the first trigger.

[data, time] = daqread('LogFile.daq');

In addition, you can obtain the hardware settings that were used during acquisition. This returns a structure composed of two fields containing all the hardware information at the time of acquisition. To obtain this, simply pass in the logged data file name with the info parameter to daqread.

info = daqread('LogFile.daq', 'info')
info = 

    ObjInfo: [1x1 struct]
     HwInfo: [1x1 struct]

Working with Subsets of Logged Data

So far you have seen only how to look at all the data collected. By using different parameter-value pairs, you can look at the data through a number of different constraints. This is useful when you are interested in only a portion of the data collected while working with large data files. For example, you can request only those samples that fall within a certain sample range. To do this, pass in the samples keyword along with the range of samples you want to daqread.

data = daqread('LogFile.daq', 'samples', [100 1200]);

You can request the data that occurred only in a specific time frame. To do this you use daqread with the time keyword paired with a time vector (in seconds).

[data, time] = daqread('LogFile.daq', 'time', [.1 .25]);
plot(time, data);

You can request the data that occurred only within a range of triggers. To do this, use daqread with the triggers keyword paired with either a trigger range or a single trigger.

data= daqread('LogFile.daq', 'triggers', [6 8]);

With these capabilities, daqread can be used to log data and acquisition information, as well as work with large data sets by extracting and operation on a subset of logged data at a time.

Was this topic helpful?