Hi RosHa,
I looked at your code and data.
There's a point we should probably underscore in the docs:
https://sanworks.github.io/Bpod_Wiki/module-documentation/analog-input-module/#object-functions
A.getData()
does not automatically return the previous trial's data. Instead, it returns all data captured since the last command to start logging data (A.startLogging()
from the PC, or the 'L' command from the serial op menu:
https://sanworks.github.io/Bpod_Wiki/serial-interfaces/analogue-input-module-serial-interface/#state-machine-command-interface
In your protocol logging is started from MATLAB prior to each trial using A.startLogging()
, so logging begins before MATLAB calls RunStateMachine(), sending a USB instruction to start the trial. To make the first sample synchronous with trial time 0 (when the device receives the start command), you need to send the 'start logging' command directly from the state machine in your first trial. In your case, you'd add ['L' 1] to your serial messages:
LoadSerialMessages('AnalogIn1',{['=' 0 0],['=' 0 1],['=' 1 0],['=' 1 1], ['L' 1]});
add {'AnalogIn1', 5} to the output actions of your first state,
sma = AddState(sma, 'Name', 'TimerTrig3', ...
'Timer', 0,...
'StateChangeConditions', {'Tup', 'ITI1'},...
'OutputActions', {'AnalogIn1', 5, 'GlobalTimerTrig', '111'});
and omit A.startLogging;
from your main loop.
Please let me know if this fixes the issue!
One additional thing to consider - the "logging" capability of the analog module is a legacy function that relies on the analog input module's microSD card to record analog signals during the trial, and does not capture analog signals during the inter-trial interval when the logged data is returned. A better option for many scenarios is to use USB data streaming, which will continuously stream data back to the PC via USB, with live monitoring in the scope() GUI. This example protocol demonstrates synchronized data capture with USB streaming during a simple visual 2AFC task. Unlike logging, data capture is continuous, so the '#' command is used to mark each trial start time in the analog dataset.
Best,
-Josh