| Data Acquisition Toolbox | Search  Help Desk |
Previewing Data
Before you begin extracting and processing acquired data, you may want to examine (preview) the data as it is being acquired. Previewing the data allows you to determine if the hardware is performing as expected and if your acquisition process is set up correctly. Once you are convinced that your data acquisition session is configured correctly, you may still want to monitor the data even as it is being analyzed or saved to disk. Previewing data is managed with thepeekdata function. After start is issued, peekdata can be called. Since peekdata is a nonblocking function that immediately returns control to the MATLAB environment, some data may be missed or repeated. The syntax for peekdata is
data = peekdata(obj, samples);
samples is the number of samples to preview.
If the number of samples requested is greater than the number of samples available in the engine, the most recent samples are returned along with a warning message stating that all the requested samples were not available. peekdata does not remove samples from the engine.
peekdata and Data Blocks
When a trigger is issued, acquired data fills data blocks in the engine. Data blocks are discussed in "The Data Block". When apeekdata function call is processed, the most recent samples requested are immediately returned but the data is not removed from the engine. That is, a "snapshot" of the most recent requested samples are returned. This situation is illustrated below where block 1 is the first block filled with data and block n is the most recent block filled with data.

Example: Polling the Data Block
Under certain circumstances, you may want to poll the data block. Polling the data block is useful when callingpeekdata since this function does not block execution control. For example, you can issue peekdata calls based on the number of samples acquired by polling the SamplesAcquired property.
An example that polls the data block is given below.
Initialization: Create the analog input object AI for a sound card. The available adaptors hardware ID's are found with daqhwinfo.
Configuration: Add one hardware channel toAI = analoginput('winsound');%AI = analoginput('nidaq', 1);
AI, define a ten second acquisition, set up a plot, and store the plot handle and title handle in the variables P and T, respectively.
addchannel(AI, 1);
%addchannel(AI, 0);
duration = 10; % Ten second acquisition
ActualRate = get(AI, 'SampleRate');
set(AI, 'SamplesPerTrigger', duration*ActualRate);
figure
set(gcf, 'doublebuffer', 'on'); %Reduce plot flicker
P = plot(zeros(1000,1));
T = title([sprintf('daqdoc4\\_2\nNumber of peekdata calls: '),
num2str(0)]);
xlabel('Samples'); axis([0 1000 -1 1]); grid on
Execution: Start AI and update the display for each 1000-sample block stored in the engine by polling SamplesAcquired. The drawnow command forces MATLAB to update the plot. Since peekdata is used, all acquired data may not be displayed.
start(AI) i = 1; while AI.SamplesAcquired < AI.SamplesPerTriggerTermination: Deletewhile AI.SamplesAcquired < 1000*ienddata = peekdata(AI, 1000);set(P, 'ydata', data); set(T, 'String', [sprintf('daqdoc4\\_2\nNumber of peekdata calls: '), num2str(i)]); drawnow i = i + 1; end while strcmp(AI.Running, 'On') end
myAI.
delete(AI)
As you run this example, you may not preview all 80,000 samples stored in the engine. This is because the engine is filled with data faster than it can be displayed, and peekdata does not guarantee that all requested samples are processed.