-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ktest.m
46 lines (33 loc) · 1.15 KB
/
Ktest.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
function [x,y,newKparams] = Ktest(input,Kparams,ang)
% change ang so that it depends on your knn
startpos = input.startHandPos;
ang
ho = Kparams
% Gaussian filtering
w = gausswin(10);
spikes = filter(w,1,input.spikes(:,end));
A = Kparams(ang).A;
H = Kparams(ang).H;
W = Kparams(ang).W;
Q = Kparams(ang).Q;
if (isempty(input.decodedHandPos))
x_est_true_init = startpos;
P_post_init = zeros(2);
else
x_est_true_init = Kparams(ang).x_est_true_init;
P_post_init = Kparams(ang).P_post_init;
end
x_est = A*x_est_true_init;
P = A*P_post_init*transpose(A) + W;
% Kalman gain matrix
K = (P*transpose(H)) / (H*P*transpose(H) + Q);
% Final estimate
predictedpos = x_est + K*(spikes - H*x_est);
x = predictedpos(1);
y = predictedpos(2);
% Posterior error covariance matrix
P_post = (eye(2) - K*H)*P;
newKparams = Kparams;
newKparams(ang).P_post_init = P_post;
newKparams(ang).x_est_true_init = predictedpos;
end