-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransformAndFilterPosition.m
More file actions
34 lines (33 loc) · 2.38 KB
/
transformAndFilterPosition.m
File metadata and controls
34 lines (33 loc) · 2.38 KB
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
function [posTime, pos] = transformAndFilterPosition(data)
posTime = data.kinematics.PlexonTime;
if(~isfield(data.kinematics,'CursorPosition'))
data.kinematics.CursorPosition = data.kinematics.Markers;
end
pos = data.kinematics.CursorPosition;
cursor_transform = data.header.CursorTransform(1:3,:);
cursor_transform(1,:) = cursor_transform(1,:) ./ abs(sum(cursor_transform(1,1:3)));
pos = [pos ones(size(pos,1),1)] * cursor_transform';
% Guess values for out of view
outOfView = sqrt(sum(pos.^2,2))>5;
outStart = find(diff(outOfView)==1);
outEnd = find(diff(outOfView)==-1);
if(outOfView(1))
outEnd = outEnd(2:end);
end
if(outOfView(end))
outStart = outStart(1:end-1);
end
for outSeg=1:length(outStart)
n = outEnd(outSeg)-outStart(outSeg)+1;
pos(outStart(outSeg):outEnd(outSeg),:) = repmat(pos(outStart(outSeg),:),n,1);
end
% Filter to 5 Hz because we are going the resolution of the snips is as low
% as 10 Hz
% 5 Hz lowpass, avoid using signal processing toolbox
lowpass = [0.00287069502053623;0.0125137645091286;0.0141319571105206;0.0204376608231961;0.0236619749588536;0.0245307573219288;0.0217374297453639;0.0154678727436827;0.00660185663579138;-0.00311954489262610;-0.0114985124762593;-0.0164283060538055;-0.0164747231883649;-0.0113835310788653;-0.00228827641421961;0.00842602613307847;0.0176224257022110;0.0222503864500440;0.0202089467050588;0.0111010713169085;-0.00340212164381136;-0.0197059099847521;-0.0329689106040541;-0.0382204243153856;-0.0315719995688486;-0.0113358295436590;0.0212927589441535;0.0622537207638255;0.105271067359807;0.143072513227035;0.168936144512676;0.178127495922495;0.168936144512676;0.143072513227035;0.105271067359807;0.0622537207638255;0.0212927589441535;-0.0113358295436590;-0.0315719995688486;-0.0382204243153856;-0.0329689106040541;-0.0197059099847521;-0.00340212164381136;0.0111010713169085;0.0202089467050588;0.0222503864500440;0.0176224257022110;0.00842602613307847;-0.00228827641421961;-0.0113835310788653;-0.0164747231883649;-0.0164283060538055;-0.0114985124762593;-0.00311954489262610;0.00660185663579138;0.0154678727436827;0.0217374297453639;0.0245307573219288;0.0236619749588536;0.0204376608231961;0.0141319571105206;0.0125137645091286;0.00287069502053623;];
if(median(diff(posTime))<1/50) % hand control only
pos = filter(lowpass,1,pos);
pos = pos(end:-1:1,:);
pos = filter(lowpass,1,pos);
pos = pos(end:-1:1,:);
end