an updated version of the code:
d = daq.getDevices;
s = daq.createSession('ni');
s.Rate = 20000; % sample rate
s.DurationInSeconds = 1;
ch3=addAnalogInputChannel(s,'Dev1','ai7','Voltage'); % record camera output through analog input channel
ch3.TerminalConfig = 'Differential';
ch1 = addCounterOutputChannel(s,'Dev1','ctr0','PulseGeneration'); % camera trigger / digital output
ch1.Frequency =1;
ch1.DutyCycle = 0.5;
ch2=addCounterInputChannel(s,'Dev1','ctr1','EdgeCount'); % counter input channel (counts camera shots)
[data, time] = startForeground(s);
hold on
plot(time,data(:,1)) % analog version of the camera output signal
scatter(time(find(diff(data(:,2))==1)),zeros(numel(time(find(diff(data(:,2))==1))),1),'filled','r') % shots timestamps
I've managed to get the timestamps for these pulses. See image below:
However, the device receiving these TTL pulses (camera) seems to respond more times than the actual pulse train (23 times -> 20 Hz train, 12 times -> 10 Hz, 6 times -> 5Hz train, 2 times -> 1Hz train). this issue seems to depend on the MATLAB code, if I trigger the camera using the NI-MAX software no additional shots (camera responses to the trigger) are present.
Also it seems that the issue does not depend on the pulse duty cycle. Neither it depends on the session duration. For instance if I have a 5Hz pulse train, the camera shoots always one addition shot (6, if the session lasts 1 sec, 11 for 2 sec, 26 for 5 sec, etc.)