-
Notifications
You must be signed in to change notification settings - Fork 3
/
localize.m
48 lines (40 loc) · 1.18 KB
/
localize.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
function [ lat long ] = localize(gps, aps, data)
% this function localizes one particular point of data
% basically using a modified version of the LWLR algorithm
% In this case it takes into account both the geometric
% distance as well as the GP distance. It then creates a
% grid of likelihoods and selects the highest.
%[xcoord ycoord] = toMeters(gps(1), gps(2), data);
xcoord = gps(1);
ycoord = gps(2);
tau = 100;
len = size(data.Y,1);
threshold = .3;
largest = max(data.Y);
largest = largest * largest';
% first we get the weights from all the corresponding
% distances.
W = zeros(len,1);
for i =1:len
dist = (data.X(i,:) - aps)*(data.X(i,:) - aps)';
W(i) = sqrt(dist);
end
W = W / max(W);
W = (1 - W.^3).^3;
P = zeros(xcoord + 10 , ycoord + 10);
for i = 1:len
if W(i) < threshold
continue;
end
for j = (xcoord - 10):(xcoord + 10)
for k = (ycoord - 10):(ycoord + 10)
dist = (xcoord - data.Y(i,1))^2 + (ycoord - data.Y(i,2))^2
sigma = data.E(i)/3;
if sqrt(dist) < sigma*3
P(j,k)=P(j,k)+W(i)*exp(-dist/(2*sigma^2))/(2*sigma^2);
end
end
end
end
[row, col] = find(P==max(P));
end