forked from Kingshida/NaveGo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnavego_interpolation.m
148 lines (114 loc) · 4.49 KB
/
navego_interpolation.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
function [ref_i, ref] = navego_interpolation (data, ref)
% navego_interpolation: interpolates data using reference time vector.
%
% Copyright (C) 2014, Rodrigo Gonzalez, all rights reserved.
%
% This file is part of NaveGo, an open-source MATLAB toolbox for
% simulation of integrated navigation systems.
%
% NaveGo is free software: you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License (LGPL)
% version 3 as published by the Free Software Foundation.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Lesser General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public
% License along with this program. If not, see
% <http://www.gnu.org/licenses/>.
%
% Version: 003
% Date: 2017/05/18
% Author: Rodrigo Gonzalez <rodralez@frm.utn.edu.ar>
% URL: https://github.com/rodralez/navego
D = max(size(data.t));
R = max(size(ref.t));
if (D > R)
method = 'nearest';
else
method = 'linear';
end
%% Adjust reference structure before interpolating
if (ref.t(1) < data.t(1))
fprintf('navego_interpolation: adjusting first element of ref ... \n')
idx = find(ref.t >= data.t(1), 1, 'first' );
if(isempty(idx))
error('navego_interpolation: idx empty index.')
end
ref.t = ref.t (idx:end);
ref.lat = ref.lat(idx:end);
ref.lon = ref.lon(idx:end);
ref.h = ref.h( idx:end);
if (isfield(ref, 'vel'))
ref.vel = ref.vel(idx:end, :);
end
if (isfield(ref, 'roll'))
ref.roll = ref.roll (idx:end);
ref.pitch = ref.pitch(idx:end);
ref.yaw = ref.yaw (idx:end);
end
end
if (ref.t(end) > data.t(end))
fprintf('navego_interpolation: adjusting last element of ref... \n')
idx = 1;
fdx = find(ref.t <= data.t(end), 1, 'last' );
if(isempty(fdx))
error('navego_interpolation: fdx empty index.')
end
ref.t = ref.t (idx:fdx);
ref.lat = ref.lat(idx:fdx);
ref.lon = ref.lon(idx:fdx);
ref.h = ref.h (idx:fdx);
if (isfield( ref, 'vel'))
ref.vel = ref.vel(idx:fdx, :);
end
if (isfield(ref, 'roll'))
ref.roll = ref.roll (idx:fdx);
ref.pitch = ref.pitch(idx:fdx);
ref.yaw = ref.yaw (idx:fdx);
end
end
%% Interpolate
if (isfield(data, 'roll') & isfield(ref, 'roll')) % If data is from INS/GPS solution...
fprintf('navego_interpolation: %s method to interpolate INS/GPS solution\n', method)
ref_i.t = ref.t;
ref_i.roll = interp1(data.t, data.roll, ref.t, method);
ref_i.pitch = interp1(data.t, data.pitch, ref.t, method);
ref_i.yaw = interp1(data.t, data.yaw, ref.t, method);
ref_i.lat = interp1(data.t, data.lat, ref.t, method);
ref_i.lon = interp1(data.t, data.lon, ref.t, method);
ref_i.h = interp1(data.t, data.h, ref.t, method);
if (isfield(ref, 'vel') & isfield( data, 'vel'))
ref_i.vel = interp1(data.t, data.vel, ref.t, method);
flag_vel = any(isnan(ref_i.vel));
else
flag_vel = logical(zeros(1,3));
end
flag = any(isnan(ref_i.t)) | any(isnan(ref_i.roll)) | any(isnan(ref_i.pitch)) | any(isnan(ref_i.yaw)) | ...
any(isnan(ref_i.lat)) | any(isnan(ref_i.lon)) | any(isnan(ref_i.h)) | flag_vel;
% Test interpolated dataset
if(flag)
error('navego_interpolation: NaN value in INS/GPS interpolated solution')
end
else % If dataset is from GPS-only solution...
fprintf('navego_interpolation: %s method to interpolate GPS-only solution\n', method)
ref_i.t = ref.t;
ref_i.lat = interp1(data.t, data.lat, ref.t, method);
ref_i.lon = interp1(data.t, data.lon, ref.t, method);
ref_i.h = interp1(data.t, data.h, ref.t, method);
if (isfield(ref, 'vel') & isfield( data, 'vel'))
ref_i.vel = interp1(data.t, data.vel, ref.t, method);
flag_vel = any(isnan(ref_i.vel));
else
flag_vel = logical(zeros(1,3));
end
flag = any(isnan(ref_i.t)) | any(isnan(ref_i.lat)) | any(isnan(ref_i.lon)) | ...
any(isnan(ref_i.h)) | flag_vel;
% Test interpolated dataset
if(flag)
error('navego_interpolation: NaN value in GPS-only interpolated solution')
end
end
end