-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathstepCounterScript.m
More file actions
95 lines (76 loc) · 2.87 KB
/
stepCounterScript.m
File metadata and controls
95 lines (76 loc) · 2.87 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
% Function to process a matlab data file and run it through the walking
% algorithm
clear all;close all
addpath('Data')
[FileName,PathName] = uigetfile({'Data/;*.mat;*.csv;*.xlsx'},'Choose Sentral Log File');
disp(FileName)
newResP = 0;resampledHtData = newResP; %initialize in case file doesn't have said data
trueSteps = 0;startTime = 1;endTime = 0;
titles = [FileName];
if FileName(end) == 't' % process .mat file
load([PathName FileName])
resultData = data_rec.dataSimRec.data_result_ay;
timeAy = resultData(:,1); % in seconds
accelAy = resultData(:,5:7);
listValues = zeros(size(timeAy));
j = 1;
listValues(j) = 1;
% remove repeated samples
for i = 2:length(listValues)
if all(accelAy(i,:) == accelAy(i-1,:))
else
listValues(j) = i;
j = j + 1;
end
end
% basic values
listValues = listValues(1:(j-1));
time = uint32(timeAy(listValues)*1000); % scale to milliseconds
acal = accelAy(listValues,:);% scaled in g's
filetype = 1;
elseif FileName(end) == 'x' || FileName(end) == 'v'
[rawData,header] = xlsread(FileName);
whichInds = rawData(:,4) == 1;
aDataRaw = rawData(whichInds,[1 5 6 7]);
acal = aDataRaw(:,2:4)/9.81;%convert m/s2 to g's
tRaw = aDataRaw(:,1);
t2 = tRaw - tRaw(1,:); % time from zero in counts
time = t2/10^6; % go from picoseconds to microseconds
filetype = 2;
ssts = find(rawData(:,4) == 104);
tts = rawData(:,4) == 103;
try
trueSteps = rawData(tts,8);
if length(trueSteps) > 1
trueSteps = max(trueSteps);
end
catch;end
try
indices = find(aDataRaw(:,1) <= rawData(ssts(1),1));
startTime = indices(end);
if isempty(startTime);startTime=0;end
catch;end
try
indices = find(aDataRaw(:,1) >= rawData(ssts(2),1));
endTime = indices(1);
if isempty(endTime);startTime=0;end
catch;end
else
disp('Invalid file selected. Exiting.')
filetype = 0;
return
end
aR = sqrt(acal(:,1).^2 + acal(:,2).^2 + acal(:,3).^2); %accel radius in g's
walkStruct = stepCounter_struct_init;
walkStruct.LIthrW = single(1.03); % change important threshold if needed
for k = 1:length(time)
% run with accel data
walkStruct = walkAlg3(walkStruct,acal(k,:),[0 0 0],time(k),1);
% run with accel radius
% walkStruct = walkAlg3(walkStruct,aR(k,:),0,time(k),1);
end
stepcount= sprintf('detected steps = %d',walkStruct.HLI);
disp('Total number of steps detected')
disp(walkStruct.HLI)
figure(1);plot(time/1000,acal);legend('Accel X','Accel Y', 'Accel Z', 'Location','Best');title(titles,'Interpreter','none');text(2,.75,stepcount);ylabel('g-force');xlabel('seconds');
figure(2);plot(time/1000,aR);title(titles,'Interpreter','none');legend('Accel Radius','Location','Best');ylabel('3-Axis Root-Sum-Square (g-force)');text(3,.75,stepcount);xlabel('seconds');