NIMH DAQ Toolbox (NIMH DAQ) is a pacakge of MATLAB scripts and mex binaries that enable MATLAB to acquire digital samples or generate analog/TTL output through data acquisition hardware. There is MATLAB's own Data Acquisition Toolbox (MATLAB DAQ) for this purpose already, but MATLAB DAQ does not support its legacy interface on 64-bit MATLAB nor in the releases later than R2015b. NIMH DAQ is developed to extend the legacy interface to 64-bit MATLAB and continue to support it in the latest version of MATLAB so that users can keep running mission-critical codes written with the legacy DAQ interface.
NIMH DAQ includes some improvements in DAQ functions to support near-realtime behavior monitoring and stimulation that are required in neuroscience research. For example, it does not require two DAQ boards to compensate long sample update intervals in MATLAB DAQ. For the details of the improvements, see this PDF document and Hwang et al. (2019).
For those devices that do not have a sample clock (NI digital input, parallel port, touchscreen, USB joystick, TCP/IP eye tracker, keyboard, mouse), NIMH DAQ performs millisecond-resolution data acquisition based on a software timer.
NIMH DAQ is included in NIMH ML and not distributed as a separate package. Copy the daqtoolbox directory from the NIMH ML package and add it to the MATLAB path. Install additional libraries as explained in this manual page.
NIMH DAQ is made compatible with the legacy interface of MATLAB DAQ Toolbox, although not all the functions are implemented. Basic commands are shown below. There are more example scripts in the daqtoolbox\examples directory.
>> devices = daqhwinfo
>> devices.InstalledAdaptors
ans =
2×1 cell array
{'nidaq' }
{'winsound'}
>> ni = daqhwinfo('nidaq' )
ans =
struct with fields:
AdaptorName: 'nidaq'
BoardNames: {'PCIe-6323'}
InstalledBoardIds: {'Dev1'}
ObjectConstructorName: {1×3 cell}
>> ai = analoginput('nidaq' ,'Dev1' )
>> daqhwinfo('ai' )
ans =
struct with fields:
AdaptorName: 'nidaq'
Bits: 16
Coupling: {'DC'}
DeviceName: 'PCIe-6323'
DifferentialIDs: [0 1 2 3 4 5 6 7 16 17 18 19 20 21 22 23]
...
>> ai = analoginput('nidaq' ,'Dev1' );
>> addchannel(ai,0:1);
>> getsample(ai)
>> ai.SampleRate = 1000;
>> ai.SamplesPerTrigger = 1000; % Or Inf, which requires calling stop(ai) to stop acquisition
>> start(ai); % Acquisition wiil stop after 1 s automatically
>> data = peekdata(ai); % Preview data without actually retrieving
>> data = getdata(ai); % Retrieve data
>> ai.TriggerType = 'manual' ;
>> start(ai); % Hardware is ready, but acquisition is not started yet
>> trigger(ai); % Triggered acquisition begins faster
>> ao = analogoutput('nidaq' ,'Dev1' );
>> addchannel(ao,0);
>> putsample(ao,5)
>> ao.SampleRate = 1000;
>> putdata(ao,sind(linspace(0,360,1000))'); % Load a waveform
>> start(ao); % Start generation
>> ao.TriggerType = 'manual' ;
>> putdata(ao,sind(linspace(0,360,1000))');
>> start(ao) % Hardware is ready, but generation is not started yet
>> trigger(ao); % Triggered generation begins faster
>> di = digitalio('nidaq' ,'Dev1' );
>> addline(di,0:3,0,'in' ); % Add Line 0-3 of Port 0 for input
>> do = digitalio('nidaq' ,'Dev1' );
>> addline(do,4:7,0,'out' ); % Add Line 4-7 of Port 0 for output
>> getvalue(di)
>> putvalue(do,12)
>> putvalue(do,[0 0 1 1]) % The same operation as the above line