forked from JD-Kidd/7_DataAnalysisSuite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrash.m
More file actions
302 lines (236 loc) · 6.98 KB
/
trash.m
File metadata and controls
302 lines (236 loc) · 6.98 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
%% VICON Error Characterization
try load('VICON_err.mat')
catch me
filename = './Data/VICON Error_2.csv';
m_to_ft = 3.28084; % ft m^-1
pos = 0:25; % ft
n = 26;
err = cell(n,1);
[ sis_err, sig_err ] = deal( zeros(n,1) );
for i = 1 : n
fprintf( [ num2str(pos(i)/m_to_ft), ' m\n' ] );
[ ~, p, ~, ~ ] = importTruthData( filename, 1 );
err{i} = pos(i) - p .* m_to_ft;
sis_err(i) = mean( err{i} );
sig_err(i) = std( err{i} );
end
err_str.err = err;
err_str.sis_err = sis_err;
err_str.sig_err = sig_err;
err_str.pos = pos;
save( 'VICON_err.mat', err_str )
end
clearvars;
close all;
clc;
m_to_ft = 3.28084; % ft m^-1
load( 'VICON_err.mat' )
err_full = [];
g = [];
for i = 1 : length( err_str.err )
err_full = [ err_full; err_str.err{i} ];
g = [ g; err_str.pos(i) .* ones( length( err_str.err{i} ), 1 ) ];
end
figure;
boxplot( err_full / m_to_ft * 100, g )
xlabel( 'Distance from Origin [ft]' )
ylabel( 'Error [cm]' )
grid on
grid minor
saveMeSomeFigs(0,'./Figures/VICON_Error_characterization_1.pdf',gcf)
figure;
subplot(1,2,1)
boxplot( err_full( g <= 17 ) / m_to_ft * 100, g( g <= 17 ) )
xlabel( 'Distance from Origin [ft]' )
ylabel( 'Error [cm]' )
grid on
grid minor
subplot(1,2,2)
boxplot( err_full( g > 17 ) / m_to_ft * 100, g( g > 17 ) )
xlabel( 'Distance from Origin [ft]' )
ylabel( 'Error [cm]' )
grid on
grid minor
saveMeSomeFigs(0,'./Figures/VICON_Error_characterization_2.pdf',gcf)
figure;
subplot(1,2,1)
plot( err_str.pos, err_str.sis_err / m_to_ft * 100, '*k' )
xlabel( 'Distance from Origin [ft]' )
ylabel( 'Systematic Error [cm]' )
grid on
grid minor
subplot(1,2,2)
plot( err_str.pos, err_str.sig_err / m_to_ft * 100, '*k' )
hold on
fill( [ min( err_str.pos ), max( err_str.pos ), max( err_str.pos ), ...
min( err_str.pos ) ], [ 0, 0, std( err_str.sig_err )*100, ...
std( err_str.sig_err )*100 ], 'b', 'FaceAlpha', 0.25, ...
'EdgeAlpha', 0.5 )
fill( [ min( err_str.pos ), max( err_str.pos ), max( err_str.pos ), ...
min( err_str.pos ) ], [ 0, 0, ...
std(err_str.sig_err([1:23,25:end]))*100, ...
std(err_str.sig_err([1:23,25:end]))*100 ], 'g', 'FaceAlpha', 0.25, ...
'EdgeAlpha', 0.5 )
xlabel( 'Distance from Origin [ft]' )
ylabel( 'Random Error Standard Deviation [cm]' )
grid on
grid minor
saveMeSomeFigs(0,'./Figures/VICON_Error_characterization_3.pdf',gcf)
%% GPS Error Characterization
[ ~, x, y, z ] = importTruthData( './Data/120C.txt' );
x = x - mean(x);
y = y - mean(y);
z = z - mean(z);
x = x.*1000;
y = y.*1000;
z = z.*1000;
figure;
subplot(1,2,1)
hold on
plot(x,y,'.k')
% Shoutout to my homie Tobin!
% Calculate covariance matrix
P = cov( x, y );
mean_x = mean(x);
mean_y = mean(y);
% Calculate the define the error ellipses
n = 100; % Number of points around ellipse
p = 0 : pi / n : 2 * pi; % angles around a circle
[ eigvec, eigval ] = eig(P); % Compute eigen-stuff
xy_vect = [ cos(p'), sin(p') ] * sqrt(eigval) * eigvec'; % Transformation
x_vect = xy_vect(:,1);
y_vect = xy_vect(:,2);
% Plot the error ellipses overlaid on the same figure
plot( x_vect+mean_x, y_vect+mean_y, 'b', 'LineWidth', 2 )
plot( 2 * x_vect+mean_x, 2 * y_vect+mean_y, 'g', 'LineWidth', 2 )
plot( 3 * x_vect+mean_x, 3 * y_vect+mean_y, 'r', 'LineWidth', 2 )
xlabel( 'East Distance [mm]' )
ylabel( 'North Distance [mm]' )
grid on
grid minor
subplot(1,2,2)
hold on
histfit(z,15)
xlabel( 'Zenith Distance [mm]' )
ylabel( 'Counts' )
grid on
grid minor
saveMeSomeFigs(0,'./Figures/GPS_Error_characterization_1.pdf',gcf)
%% VICON Test Expected Data
[ t, x, y, z ] = importTruthData( './Data/24Feb_Rack2_Test1.csv' );
% Rotation onto principal, horizontal, vertical axes
% Principal axis is the one which minimizes mean(H) and mean(Z),
% I.E. it is the axis that points along the average position
% Horizontal is the axis perpendicular to Principal with no z
% component
% Vertical is the remaining axis perpendiculat to both Principal
% and Horizontal
p = [x-x(1),y-y(1),0.*z];
p = mean(p);
p = p / norm(p);
h = cross( [0,0,1], p );
k = cross( p, h );
p = dot( [x,y,z], p.*ones( size( [x,y,z] ) ), 2 );
h = dot( [x,y,z], h.*ones( size( [x,y,z] ) ), 2 );
k = dot( [x,y,z], k.*ones( size( [x,y,z] ) ), 2 );
figure;
subplot(1,2,1)
plot(t,p,'-k','Linewidth',2)
xlabel( 'Time [s]' )
ylabel( 'Principal Direction [m]' )
grid on
grid minor
subplot(1,2,2)
scatter(100.*h,100.*k,1,t-t(1))
xlabel( 'Horizontal Direction [cm]' )
ylabel( 'Vertical Direction [cm]' )
c = colorbar('southoutside');
caxis( [ 0, t(end)-t(1) ] )
c.Label.String = 'Time [s]';
colormap(fliplr(jet));
grid on
grid minor
saveMeSomeFigs(0,'./Figures/VICON_Expected_Data_1.pdf',gcf)
figure;
subplot(1,3,1)
plot( t, gradient(p,t), '-k' )
xlabel( 'Time [s]' )
ylabel( 'Principal Velocity [m/s]' )
subplot(1,3,2)
histfit( 100.*gradient(h,t), 15 )
xlabel( 'Horizontal Velocity [cm/s]' )
ylabel( 'Counts' )
subplot(1,3,3)
histfit( 100.*gradient(k,t), 15 )
xlabel( 'Vertical Velocity [cm/s]' )
ylabel( 'Counts' )
saveMeSomeFigs(0,'./Figures/VICON_Expected_Data_2.pdf',gcf)
%% GPS Test Expected Data
try load( 'GPSExpected.mat' )
catch me
[ t, x, y, z ] = importTruthData( './Data/600.txt', 1 );
save( 'GPSExpected.mat', 't', 'x', 'y', 'z' )
end
% Rotation onto principal, horizontal, vertical axes
% Principal axis is the one which minimizes mean(H) and mean(Z),
% I.E. it is the axis that points along the average position
% Horizontal is the axis perpendicular to Principal with no z
% component
% Vertical is the remaining axis perpendiculat to both Principal
% and Horizontal
p = [x,y,0.*z];
p = mean(p);
p = p / norm(p);
h = cross( [0,0,1], p );
k = cross( p, h );
p = dot( [x,y,z], p.*ones( size( [x,y,z] ) ), 2 );
h = dot( [x,y,z], h.*ones( size( [x,y,z] ) ), 2 );
k = dot( [x,y,z], k.*ones( size( [x,y,z] ) ), 2 );
load( 'GPSExpected.mat' )
f = fit(p-p(1),k-k(1),'smoothingspline','SmoothingParam',0.07);
figure;
subplot(1,2,1)
plot( p-p(1), feval( f, p-p(1) ), '-k', 'Linewidth', 2 )
hold on
scatter(p-p(1),k-k(1),1,t-t(1))
xlabel( 'Principal Direction [m]' )
ylabel( 'Vertical Direction [m]' )
c = colorbar('southoutside');
caxis( [ 0, t(end)-t(1) ] )
c.Label.String = 'Time [s]';
colormap(fliplr(jet));
grid on
grid minor
subplot(1,2,2)
histfit(100.*h,15)
hold on
plot( std(100.*h).*[1,1], [0,max(get(gca,'YLim'))], '-r', 'LineWidth', 2 )
plot( -std(100.*h).*[1,1], [0,max(get(gca,'YLim'))], '-r', 'LineWidth', 2 )
xlabel( 'Horizontal Direction [cm]' )
ylabel( 'Counts' )
grid on
grid minor
saveMeSomeFigs(0,'./Figures/GPS_Expected_Data_1.pdf',gcf)
figure;
subplot(1,3,1)
plot( t, gradient(p,t), '.k' )
hold on
plot( [ t(1), t(end) ], mean( gradient(p,t) ) .* [1,1], '-g', ...
'LineWidth', 2 )
xlabel( 'Time [s]' )
ylabel( 'Principal Velocity [m/s]' )
grid on
grid minor
subplot(1,3,2)
histfit( 100.*gradient(h,t), 15 )
xlabel( 'Horizontal Velocity [cm/s]' )
ylabel( 'Counts' )
grid on
grid minor
subplot(1,3,3)
histfit( 100.*gradient(k,t), 15 )
xlabel( 'Vertical Velocity [cm/s]' )
ylabel( 'Counts' )
grid on
grid minor
saveMeSomeFigs(0,'./Figures/GPS_Expected_Data_2.pdf',gcf)