-
Notifications
You must be signed in to change notification settings - Fork 2
/
binitb.m
105 lines (95 loc) · 2.78 KB
/
binitb.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
function [time,psth,rawspikes,sums,rawstruct]=binitb(sd,binwidth,startmod,endmod,starttrial,endtrial,wrapped,cor)
% This function will take an lsd structure file and construct a
% timebase and psth at a given binwidth, wrapped or unwrapped.
% binwidth needs to be called *10 as data here is in 10th's ms
% The binning algorithm is taken from the VS manual
%
% [time,psth]=binitb(file,binwidth,startmod,endmod,wrapped);
% where wrapped is 1 (yes) or 0(no)
%
% THIS IS MODIFIED TO BIN BURST ANALYSIS OUTPUT
global data
rawspikes=[];
sums=[];
rawstruct=[];
xcinuse=0;
if endmod>sd.nummods || endmod<1
endmod=sd.nummods;
end
if endtrial>sd.totaltrials || endtrial<1
endtrial=sd.totaltrials;
end
if startmod<1 || startmod>endmod
startmod=1;
end
if starttrial<1 || starttrial>endtrial
startmod=1;
end
if exist('cor','var')
xcinuse=1;
end
if (xcinuse==1)
global xdata
if isfield(xdata,'modtime')
modtime=xdata.modtime;
else
modtime=round(sd.maxtime/sd.nummods);
end
else
if isfield(data,'modtime')
modtime=data.modtime;
else
modtime=round(sd.maxtime/sd.nummods);
end
end
if wrapped==1 % Wrapped is ON
time=0:binwidth:modtime;
psth=zeros(1,size(time,2));
a=1; %we use this because lsd2 has already removed the trials, so we reset the index
sloop=1;
for i=starttrial:endtrial
for j=startmod:endmod
reftime=sd.trial(a).modtimes(j); % The reference time is each modtime
x=sd.btrial(a).mod{j};
sums=[sums;length(x)];
rawspikes=[rawspikes;x-reftime];
rawstruct(sloop).trial=(x-reftime)/10;
x=(x-reftime)/binwidth;
x=floor(x);
x=x+1; % We need to do this because binning starts from 0, but the index starts from 1
%add the spikes into the accumulation buffer
for k=1:size(x,1)
psth(x(k))=psth(x(k))+1; % Add the spikes into the accumulation buffer
end
sloop=sloop+1;
end
a=a+1;
end
else % Wrapped is OFF, we thus don't care about mod selection
time=0:binwidth:sd.maxtime;
psth=zeros(1,size(time,2));
a=1;
for i=starttrial:endtrial
sumst=[];
rawtemp=[];
for j=1:sd.nummods
reftime=sd.trial(a).modtimes(1); % The reference time is the 1st modtime
x=sd.btrial(a).mod{j};
sumst=[sumst;length(x)];
rawspikes=[rawspikes;x-reftime];
rawtemp=[rawtemp;x-reftime];
x=(x-reftime)/binwidth;
x=floor(x);
x=x+1; % We need to do this because binning starts from 0, but the index starts from 1
x(x>length(psth)) = [];
for k=1:size(x,1)
psth(x(k))=psth(x(k))+1;
end
end
sums=[sums;sum(sumst)];
rawstruct(a).trial=rawtemp/10;
a=a+1;
end
end
rawspikes=sort(rawspikes/10);
time=time/10; %convert back to ms