-
Notifications
You must be signed in to change notification settings - Fork 0
/
shannonise.m
83 lines (75 loc) · 2.65 KB
/
shannonise.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
function events = shannonise(recording, timeconst, timeStep)
arrayLength = floor((recording.ts(end)-recording.ts(1))/timeStep);
events.activityOn = zeros(1, arrayLength+1);
events.activityOff = zeros(1, arrayLength+1);
factor = exp(-timeStep/timeconst);
starttime = recording.ts(end) - arrayLength * timeStep;
returnTimestamps = linspace(starttime, recording.ts(end), arrayLength+1);
% ON
tOn = recording.ts(recording.p == 1);
recording.activityOn = recording.activityOn(recording.p == 1);
i = 1;
while returnTimestamps(i) < tOn(1)
events.activityOn(i) = (recording.activityOn(1)-1)/exp(-(tOn(1)-starttime)/timeconst);
i = i + 1;
end
for j = 1:length(tOn)
regularTS = tOn(j);
while regularTS > starttime + (i+1) * timeStep
if i == 1
events.activityOn(i) = recording.activityOn(j-1) * exp(-(starttime - tOn(j-1))/timeconst);
else
events.activityOn(i) = events.activityOn(i-1) * factor;
end
i = i + 1;
end
scaledTS = starttime + (i-1) * timeStep;
if scaledTS > regularTS
continue
elseif scaledTS == regularTS
events.activityOn(i) = recording.activityOn(j);
i = i + 1;
else
events.activityOn(i) = recording.activityOn(j-1) * exp(-(scaledTS - tOn(j-1))/timeconst);
i = i + 1;
end
end
while i <= arrayLength + 1 && returnTimestamps(i) > tOn(end)
events.activityOn(i) = recording.activityOn(end) * exp(-((starttime + i*timeStep) - tOn(end))/timeconst);
i = i + 1;
end
% OFF
tOff = recording.ts(recording.p == 0);
recording.activityOff = recording.activityOff(recording.p == 0);
i = 1;
while returnTimestamps(i) < tOff(1)
events.activityOff(i) = (recording.activityOff(1)-1)/exp(-(tOff(1)-starttime)/timeconst);
i = i + 1;
end
for j = 1:length(tOff)
regularTS = tOff(j);
while regularTS > starttime + (i+1) * timeStep
if i == 1
events.activityOff(i) = recording.activityOff(j-1) * exp(-(starttime - tOff(j-1))/timeconst);
else
events.activityOff(i) = events.activityOff(i-1) * factor;
end
i = i + 1;
end
scaledTS = starttime + (i-1) * timeStep;
if scaledTS > regularTS
continue
elseif scaledTS == regularTS
events.activityOff(i) = recording.activityOff(j);
i = i + 1;
else
events.activityOff(i) = recording.activityOff(j-1) * exp(-(scaledTS - tOff(j-1))/timeconst);
i = i + 1;
end
end
while i <= arrayLength + 1 && returnTimestamps(i) > tOff(end)
events.activityOff(i) = recording.activityOff(end) * exp(-((starttime + i*timeStep) - tOff(end))/timeconst);
i = i + 1;
end
events.ts = returnTimestamps;
end