NIMH DAQ Toolbox

  1. Introduction
  2. 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).

  3. Supported devices
    • National Instruments multifunction I/O device
    • Sound card
    • Parallel port
    • Touchscreen (MonkeyLogic Graphics Library required)
    • USB joystick
    • TCP/IP eye tracker
    • Keyboard
    • Mouse
    • Webcam
    • Serial port

    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.

  4. Installation
  5. 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.

  6. Usage
  7. 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.

    1. Hardware Discovery
    2. Analog Input
    3. Analog Output
    4. Digital Input/Output

    1. Hardware Discovery
      1. Find all installed adapters
      2. >> devices = daqhwinfo >> devices.InstalledAdaptors ans = 2×1 cell array {'nidaq' } {'winsound'}

      3. Information about an installed adapter
      4. >> ni = daqhwinfo('nidaq') ans = struct with fields: AdaptorName: 'nidaq' BoardNames: {'PCIe-6323'} InstalledBoardIds: {'Dev1'} ObjectConstructorName: {1×3 cell}

      5. Information about a particular device
      6. >> 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] ...

    2. Analog Input
      1. Create an analog input object
      2. >> ai = analoginput('nidaq','Dev1'); >> addchannel(ai,0:1);

      3. Acquire a single sample
      4. >> getsample(ai)

      5. Acquire continuous samples
      6. >> 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

      7. Triggered sampling
      8. >> ai.TriggerType = 'manual'; >> start(ai); % Hardware is ready, but acquisition is not started yet
        >> trigger(ai); % Triggered acquisition begins faster

    3. Analog Output
      1. Create an analog output object
      2. >> ao = analogoutput('nidaq','Dev1'); >> addchannel(ao,0);

      3. Send out a single sample
      4. >> putsample(ao,5)

      5. Generate a waveform
      6. >> ao.SampleRate = 1000; >> putdata(ao,sind(linspace(0,360,1000))'); % Load a waveform >> start(ao); % Start generation

      7. Triggered generation
      8. >> 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

    4. Digital Input/Output
      1. Create a digital I/O object
      2. >> 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

      3. Read a value
      4. >> getvalue(di)

      5. Write a value
      6. >> putvalue(do,12) >> putvalue(do,[0 0 1 1]) % The same operation as the above line

The National Institute of Mental Health (NIMH) is part of the National Institutes of Health (NIH), a component of the U.S. Department of Health and Human Services.