forked from JD-Kidd/7_DataAnalysisSuite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimportTrimbleData.m
More file actions
140 lines (110 loc) · 3.66 KB
/
importTrimbleData.m
File metadata and controls
140 lines (110 loc) · 3.66 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
function [ t, x, y, z, u, v, w ] = ...
importTrimbleData( filepath, delimiter, headerRowNumber )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Author: Marshall Herr
%%%
%%% Purpose: Takes in a path to a Trimble GPS text file and outputs the
%%% position and velocity data along with the time vector.
%%%
%%% Inputs:
%%% - filepath: The pagth to the *.txt file from the current directory
%%% - delimiter: Optional, specify the delimiter, defualt is ' '
%%% - headerRowNumber: Optional, specify what line of the text file
%%% contains the header, default is 1
%%%
%%% Outputs:
%%% - t: Time vector in seconds
%%% - x: East position from origin in meters
%%% - y: North position from origin in meters
%%% - z: Zenith position from origin in meters
%%% - u: Eastward velocity from origin in meters per second
%%% - v: Northward velocity from origin in meters per second
%%% - w: Zenith-ward velocity from origin in meters per second
%%%
%%% Date Created: 21 Feb 2019
%%% Last Editted: 21 Feb 2019
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Note: datafiles are created in 10 minute blocks (E.G. from 1:00 to 1:10),
% thus the day cannot change during a dataset, nor the hour, nor the month,
% year, etc. If this happens in your dataset, this code will be bugged!!!
%% Setup
minutesToSeconds = 60 / 1; % s min^-1
if nargin < 3
headerRowNumber = 1;
end
if nargin < 2
delimiter = ' ';
end
% This will exclude data points more that 'sigmaExclude' standard
% deviations away from the median of x, y, and z
sigmaExclude = 10;
%% Data Extraction
% Export data from text file
dataStruct = importdata( filepath, delimiter, headerRowNumber );
% Export position/velocity data from struct
data = dataStruct.data;
% Export timetamps as chars
chars = dataStruct.textdata;
% Chop 1st data point because it is always wrong
t = chars( headerRowNumber + 2 : end, 4 );
x = data(2:end,1);
y = data(2:end,2);
z = data(2:end,3);
u = data(2:end,4);
v = data(2:end,5);
w = data(2:end,6);
%% Data Cleanup
while isinf( std(x) )
badData = abs( x - median(x) ) == max( abs( x - median(x) ) );
t = t( ~badData );
x = x( ~badData );
y = y( ~badData );
z = z( ~badData );
u = u( ~badData );
v = v( ~badData );
w = w( ~badData );
end
while isinf( std(y) )
badData = abs( y - median(y) ) == max( abs( y - median(y) ) );
t = t( ~badData );
x = x( ~badData );
y = y( ~badData );
z = z( ~badData );
u = u( ~badData );
v = v( ~badData );
w = w( ~badData );
end
while isinf( std(z) )
badData = abs( z - median(z) ) == max( abs( z - median(z) ) );
t = t( ~badData );
x = x( ~badData );
y = y( ~badData );
z = z( ~badData );
u = u( ~badData );
v = v( ~badData );
w = w( ~badData );
end
badData = ( abs( x - median(x) ) > sigmaExclude * std(x) ) | ...
( abs( y - median(y) ) > sigmaExclude * std(y) ) | ...
( abs( z - median(z) ) > sigmaExclude * std(z) );
while ~isempty( find( badData, 1 ) )
t = t( ~badData );
x = x( ~badData );
y = y( ~badData );
z = z( ~badData );
u = u( ~badData );
v = v( ~badData );
w = w( ~badData );
badData = ( abs( x - median(x) ) > sigmaExclude * std(x) ) | ...
( abs( y - median(y) ) > sigmaExclude * std(y) ) | ...
( abs( z - median(z) ) > sigmaExclude * std(z) );
end
% Transform hr:min:sec cells into seconds
t = cell2mat(t);
[ ~, ~, ~, ~, Minute, Second ] = datevec( t );
t = Second + minutesToSeconds * Minute;
t = t - t(1);
x = x - x(1);
y = y - y(1);
z = z - z(1);
end