-
Notifications
You must be signed in to change notification settings - Fork 1
/
velerror.m
48 lines (37 loc) · 1.06 KB
/
velerror.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
function values = velerror(decodedvel, vel, tdecode)
%returns an error in cm/s (vel) for each decoded time.
%inputs should be:
%decoded vell from decodeVel.m
%computed vel from velocity.m
%decoded time bin in s
%returns: values = [alldiff; realvel; time];
%difference in decoded speed versus actual
%mean actual speed in the bin
%time of decoding
decodedvel = decodedvel(1,:);
actualvel = vel(1,:);
time = vel(2,:);
tdecodesec = tdecode;
samprate = length(vel)./(max(vel(2,:))-min(vel(2,:)));
samprate = (samprate);
tdecode = round(samprate*tdecode);
average_vel = [];
diff = [];
decodedtime = [];
realtime = [];
tm = 1;
j = 1;
while tm<=(length(time)-tdecode)
average_vel(end+1) = nanmean(actualvel(tm:tm+tdecode));
diff(end+1) = abs(decodedvel(j)-average_vel(end));
decodedtime(end+1) = time(j);
j = j+1;
if tdecodesec>=1
tm = tm+(tdecode/2); %overlap
else
tm = tm+tdecode;
end
end
values = [diff; average_vel; decodedtime];
median_is = nanmedian(diff);
mean_is = nanmean(diff);