forked from rodralez/NaveGo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
navego_interpolation.m
executable file
·162 lines (125 loc) · 4.7 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
function [nav_i, ref] = navego_interpolation (nav, ref)
% navego_interpolation: interpolates navigation data using a reference time
% vector.
%
% INPUT:
% nav, navigation data structure to be interpolated.
% ref, reference data structure.
%
% OUTPUT
% nav_i, navigation data structure interpolated by reference time vector.
% ref, reference data structure adjusted by the nav 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: 004
% Date: 2019/01/10
% Author: Rodrigo Gonzalez <[email protected]>
% URL: https://github.com/rodralez/navego
D = max(size(nav.t));
R = max(size(ref.t));
if (D > R)
method = 'nearest';
else
method = 'spline';
end
%% Adjust reference data structure before interpolating
if (ref.t(1) < nav.t(1))
fprintf('navego_interpolation: adjusting first element of ref ... \n')
idx = find(ref.t >= nav.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) > nav.t(end))
fprintf('navego_interpolation: adjusting last element of ref... \n')
idx = 1;
fdx = find(ref.t <= nav.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
%% Interpolation
% If data is from INS/GNSS solution...
if (isfield(nav, 'roll') & isfield(ref, 'roll'))
fprintf('navego_interpolation: %s method to interpolate INS/GNSS solution\n', method)
nav_i.t = ref.t;
nav_i.roll = interp1(nav.t, nav.roll, ref.t, method);
nav_i.pitch = interp1(nav.t, nav.pitch, ref.t, method);
nav_i.yaw = interp1(nav.t, nav.yaw, ref.t, method);
nav_i.lat = interp1(nav.t, nav.lat, ref.t, method);
nav_i.lon = interp1(nav.t, nav.lon, ref.t, method);
nav_i.h = interp1(nav.t, nav.h, ref.t, method);
if (isfield(ref, 'vel') & isfield( nav, 'vel'))
nav_i.vel = interp1(nav.t, nav.vel, ref.t, method);
flag_vel = any(isnan(nav_i.vel));
else
flag_vel = false(1,3);
end
flag = any(isnan(nav_i.t)) | any(isnan(nav_i.roll)) | any(isnan(nav_i.pitch)) | any(isnan(nav_i.yaw)) | ...
any(isnan(nav_i.lat)) | any(isnan(nav_i.lon)) | any(isnan(nav_i.h)) | flag_vel;
% Test interpolated dataset
if(flag)
error('navego_interpolation: NaN value in INS/GNSS interpolated solution')
end
% If dataset is from a GNSS-only solution...
else
fprintf('navego_interpolation: %s method to interpolate GNSS-only solution\n', method)
nav_i.t = ref.t;
nav_i.lat = interp1(nav.t, nav.lat, ref.t, method);
nav_i.lon = interp1(nav.t, nav.lon, ref.t, method);
nav_i.h = interp1(nav.t, nav.h, ref.t, method);
if (isfield(ref, 'vel') & isfield( nav, 'vel'))
nav_i.vel = interp1(nav.t, nav.vel, ref.t, method);
flag_vel = any(isnan(nav_i.vel));
else
flag_vel = false(1,3);
end
flag = any(isnan(nav_i.t)) | any(isnan(nav_i.lat)) | any(isnan(nav_i.lon)) | ...
any(isnan(nav_i.h)) | flag_vel;
% Test interpolated dataset
if(flag)
error('navego_interpolation: NaN value in GNSS-only interpolated solution')
end
end
end