Data Acquisition Toolbox
  Function/Property:
    Search    Help Desk 

Extracting Data from the Engine

Many data acquisition applications require that data is acquired at a fixed (often high) rate, and that the data be processed in some way immediately after it is collected. For example, you may want to perform an FFT on the acquired data and then save it to disk. When processing data, you must extract it from the engine in a timely fashion so that no samples are missed.

Data is extracted from memory with the getdata function. getdata is a blocking function that returns control to the MATLAB environment only when the requested data is available. Therefore, samples are not missed or repeated.

The syntax for getdata is

where:

The relationship between the samples acquired and the relative time for each sample is shown below for m samples and n channels.


As soon as a trigger is issued and samples are stored in the engine, the SamplesAcquired property keeps a running count of the total number of samples per channel that have been acquired, while the SamplesAvailable property tells you how many samples can be extracted from the engine per channel with getdata. When a getdata call is issued, SamplesAvailable is reduced by the number of samples requested.

getdata and Data Blocks

When a trigger occurs, acquired data fills data blocks in the engine. Data blocks are discussed in "The Data Block". When a getdata function call is processed, the requested samples are returned when the data is available, and then removed from the engine. The situation for when getdata extracts a full block of data is shown below block 1 is the first block filled with data and block n is the most recent block filled with data.


If another getdata call is issued, then those samples are returned such that no data is missed. This situation is shown below.


Example: Previewing and Extracting Data

Suppose you have a time-consuming data acquisition application. By previewing the data, you can ascertain whether the acquisition is proceeding as expected without waiting for all the data to be acquired. If it is not, then you can abort the session and diagnose the problem.

The example below illustrates how you might use peekdata and getdata together in such an application.

Initialization: Create the analog input object AI for a sound card. The available adaptors are found with daqhwinfo.

Configuration: Add one hardware channel to AI, define a ten second acquisition, set up the plot and store the plot handle in the variable P. The amount of data displayed is given by preview.

Execution: Start AI and update the display using peekdata every time an amount of data given by preview is stored in the engine by polling SamplesAcquired. The drawnow command forces MATLAB to update the plot. After all data is acquired, it is extracted from the engine. Note that whenever peekdata is used, all acquired data may not be displayed.

Termination: Wait for AI to stop running, plot all the extracted data, and delete the device object.

The data is shown below.




[ Previous | Help Desk | Next ]