Closed weiglszonja closed 2 months ago
We received a MATLAB script from Shiva, based on that the imaging frames are aligned as:
vars
: the data from the .mat file
data
: the data from the .dat file continuing timestamps, daq times, velocity and brake states
data1
: the data from the DAQ .dat file
%% get CPU, DAQ time elapsed per loop and DAQ time
daq_sampleRate = 1000;
t1 = data(:,1); % time elapsed per loop based on CPU clock (logged every ~30ms)
t2 = cumsum(data(:,2))/daq_sampleRate; % time elapsed per loop based on DAQ clock (logged every ~30ms)
% shift DAQ time so it starts the same as CPU time bc DAQ gets initialized
% before tic starts so elapsed time is longer going into the loop
t = t2-(t2(1)-t1(1));
L_daq = size(data1,1);
t_daq = ((1:L_daq)/daq_sampleRate)-(t2(1)-t1(1)); % DAQ sampled at 1kHz, shifted so sampling starts the same as when CPU clock starts
%% find imaging bout
locs = find(data1(2:end,2)>.8 & data1(1:end-1,2)<.1);
locs = locs+1; % first high point of imaging pulse
% fake the frame times if there is no imaging data
% if isempty(locs)
% fake_rate = 30; % Hz
% locs = (1:round(vars.daq.sampleRate/fake_rate):L_daq)';
% locs = locs+1;
% end
%% get frame_times
frame_times = t_daq(locs); % time of first point of the high pulse
% correct frame_times to center of imaging frame rather than the beginning
dt = mean(diff(frame_times));
img_times = frame_times + dt/2;
DAQ file
camera pulses
shape = (1219981,)
imaging pulses
shape = (1219981,)
with a sample rate of1000.0
the imaging duration is1219.981
seconds (matches scan image)DLC: num frames
131930
Video: num frames
131930
TTL camera (from DAQ):
131932
(2 extra frames?)TTL imaging (from DAQ):
36000
(matches the num frames in scan image)behavior data (velocity, brakes):
shape = 40385
with atimestamps
array that should be already aligned with imaging