AddFlexIOAnalogData()

Description

Reads the current Flex I/O analog data file into memory, and adds it to a Bpod behavior data structure.

Adding analog data is a long operation and is typically run once at the end of each session.

Note: This function will only work with state machine r2+ or other models with Flex I/O channels.

Syntax

BehaviorDataOut = AddFlexIOAnalogData(BehaviorDataIn, [sampleFormat], [addSamplesByTrial])

% Note: [ ] indicates an optional argument

Parameters

  • BehaviorDataIn: a Bpod behavior data structure.

    • During a session, use BpodSystem.Data.

    • To add analog data post-hoc (e.g. for a crashed session) BehaviorDataIn is the data structure loaded to the workspace

  • sampleFormat: a string indicating the format to import

    • 'Volts' (default): Samples are imported as double type (8 bytes per sample). Units = volts.

    • 'Bits': Samples are imported as uint16 type in range 0-4095 (2 bytes per sample). Bits represent volts in range 0-5.

    • Note: Store samples as bits for smaller data files, and convert to volts at analysis time:

      • Volts = (double(Bits)/4095)*5

  • addSamplesByTrial:

    • 1 = add a cell array with a cell for each experimental trial, where each cell contains all samples acquired during that trial. This can also be done by user code at analysis time to save disk space.

    • 0 = Do not add trial-aligned duplicate data

Returns

  • BehaviorDataOut: the Bpod behavior data structure passed into the function, with added analog data

Examples

% 1. This code will import the current Flex I/O analog data into the primary behavior data structure

% at the end of a behavior session.

% Samples are stored as bits to save space, and a cell array of samples per trial is added.

if BpodSystem.Status.BeingUsed == 0

BpodSystem.Data = AddFlexIOAnalogData(BpodSystem.Data, 'Bits', 1); Adds FlexI/O analog data to BpodSystem.Data

SaveBpodSessionData; % Saves BpodSystem.Data to the current data file

return

end


% 2. This code will add previously acquired analog data offline.

% Note: This must be done on the same PC that acquired the data, and assumes that the data has not % been moved from its original location on the disk.

load MyDataFile; % MyDataFile is a .mat file of saved Bpod session data. A struct called SessionData is % created in the local workspace.

SessionData = AddFlexIOAnalogData(SessionData, 'Volts'); % Import the analog data as volts