-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparsePowerSenseData_1.m
More file actions
45 lines (41 loc) · 2.05 KB
/
parsePowerSenseData_1.m
File metadata and controls
45 lines (41 loc) · 2.05 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
function [accel, gyro] = parsePowerSenseData(filename)
function userAccClean = cleanData(timestampsDesired, timestampsOrig, userAcc)
cleanInds = ~isnan(userAcc);
userAccClean = interp1(timestampsOrig(cleanInds), userAcc(cleanInds), timestampsDesired);
end
function cleaned = interpolateMissingValues(X)
time = X(:,1);
timestampsDesired = linspace(time(1), time(end), length(time));
cleaned = zeros(size(X));
cleaned(:,1) = timestampsDesired;
for i = 2 : size(X,2)
cleaned(:,i) = cleanData(timestampsDesired, X(:,1), X(:,i));
end
end
data = importdata(filename);
userAccInds = [];
userAccInds(end+1) = find(strcmp(data.textdata, 'user_acc_x(G)'));
userAccInds(end+1) = find(strcmp(data.textdata, 'user_acc_y(G)'));
userAccInds(end+1) = find(strcmp(data.textdata, 'user_acc_z(G)'));
gravityInds = [];
gravityInds(end+1) = find(strcmp(data.textdata, 'gravity_x(G)'));
gravityInds(end+1) = find(strcmp(data.textdata, 'gravity_y(G)'));
gravityInds(end+1) = find(strcmp(data.textdata, 'gravity_z(G)'));
gyroInds = [];
gyroInds(end+1) = find(strcmp(data.textdata, 'rotation_rate_x(radians/s)'));
gyroInds(end+1) = find(strcmp(data.textdata, 'rotation_rate_y(radians/s)'));
gyroInds(end+1) = find(strcmp(data.textdata, 'rotation_rate_z(radians/s)'));
timeinds = find(strcmp(data.textdata, 'timestamp(unix)'));
timeinds = timeinds(1);
% some of the time columns are all NaNs for some reason
[~, best] = max(sum(~isnan(data.data(:,timeinds))));
bestTimeInd = timeinds(best);
startInd = min(find(~isnan(data.data(:,bestTimeInd))));
data.data = data.data(startInd:end,:);
% iOS measures in units of gravities. We need to multiply by -9.8 to
% ensure that the signs match up between iOS and Android
accel = [data.data(:,bestTimeInd) -9.8*(data.data(:,userAccInds) + data.data(:, gravityInds))];
gyro = [data.data(:,bestTimeInd) data.data(:,gyroInds)];
accel = interpolateMissingValues(accel);
gyro = interpolateMissingValues(gyro);
end