% Jon Newman
% Multi-parameter activity assay for cultures transfected with
% optical exciters and silencers

% File name
close all
figure
fid = 'paired-pulse_2012-04-07_hoss-r3_tommy_358_01';
d = loaddig([fid '.dig']);
pre = 50; %msec
post = 500; %msec

% Decode the digital file
b = dec2bin(d.state);
trig = str2num(b(:,end));
c0 = str2num(b(:,end-1));
c1 = str2num(b(:,end-2));

% Blue on time
bon = d.time(trig == 1 & c0 == 1);
yoff = d.time(trig == 0 & c1 == 1);

% Gather raw data
R = [];
F = [];

figure()
hold on
for i = 1:length(bon)
    [r t] = loadraw([fid '.raw'],10,[bon(i)-pre/1000, yoff(i)+post/1000]);
    [f t]= loadraw([fid '.spkflt'],10,[bon(i)-pre/1000, yoff(i)+post/1000]);
    
    plot(t-bon(i),f,'k')
end


