-
Notifications
You must be signed in to change notification settings - Fork 0
/
modification.asv
119 lines (106 loc) · 4.45 KB
/
modification.asv
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
clear all
clc
allData = dlmread('L:\Beloozerova\Joey\MH\7.27.13(VZ File)\FLAT\Toe.txt', '', 31, 0); % Import data portion, keep consistent
i = 0; % Between scripts
j = 1;
while i == 0 % Find frame 1 in first column
if allData(j,1) ~= 1
j = j + 1;
else
i = 1;
end
end
data = allData(j:1:end,[1 2 4:6]);
clear allData i j;
specificRangeFilter = 1;
lwrLim = -700;
uprLim = -489;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ng = find(data(:,3)); % Finds all of the indexes that are nonzero of the data
for n = 100:length(ng)-2 % Starts a for loop going through all of the indexes
w = ng(n+1) - ng(n); % If consecutive elements have a difference of one, no flicker
if w == 1
elseif w < 37 %16 % Else, there is a flicker, if flicker is less than 37, interpolates
t = [ng(n) ng(n+1)]; % and replaces the flickers
x = data(t,3);
y = data(t,4);
z = data(t,5);
tt = ng(n):ng(n+1);
%% here we could use more previous data for spline: instead of just
%% t, ng(n)-50:5:ng(n) and ng(n+1):5:ng(n+1)+50
data(tt , 3) = spline(t, x, tt);
data(tt , 4) = spline(t, y, tt);
data(tt , 5) = spline(t, z, tt);
%%use this part if you need V and accelaration
for i = ng(n)-1:ng(n+1)
data(i+1,6) = ((data(i+1,3)-data(i,3))/(data(i+1,2)-data(i,2)))*100;
data(i+1,7) = ((data(i+1,4)-data(i,4))/(data(i+1,2)-data(i,2)))*100;
data(i+1,8) = ((data(i+1,5)-data(i,5))/(data(i+1,2)-data(i,2)))*100;
end
for i = ng(n)-1:ng(n+1)
data(i+1,9) = ((data(i+1,6)-data(i,6))/(data(i+1,2)-data(i,2)))*100;
data(i+1,10) = ((data(i+1,7)-data(i,7))/(data(i+1,2)-data(i,2)))*100;
data(i+1,11) = ((data(i+1,8)-data(i,8))/(data(i+1,2)-data(i,2)))*100;
end
end
end
if specificRangeFilter % Uses same process as above, but searches for values outside
% of range and interpolates for those if less than
% 60 in length.
ng = find((data(:,3) > lwrLim & data(:,3) < uprLim) | data(:,3) == 0);
for n = 2:length(ng)-2
w = ng(n+1) - ng(n);
if w == 1
elseif w < 60 %16
t = [ng(n) ng(n+1)];
x = data(t,3);
y = data(t,4);
z = data(t,5);
tt = ng(n):ng(n+1);
data(ng(n):ng(n+1),3) = spline(t, x, tt);
data(ng(n):ng(n+1),4) = spline(t, y, tt);
data(ng(n):ng(n+1),5) = spline(t, z, tt);
for i = ng(n)-1:ng(n+1)
data(i+1,6) = ((data(i+1,3)-data(i,3))/(data(i+1,2)-data(i,2)))*100;
data(i+1,7) = ((data(i+1,4)-data(i,4))/(data(i+1,2)-data(i,2)))*100;
data(i+1,8) = ((data(i+1,5)-data(i,5))/(data(i+1,2)-data(i,2)))*100;
end
for i = ng(n)-1:ng(n+1)
data(i+1,9) = ((data(i+1,6)-data(i,6))/(data(i+1,2)-data(i,2)))*100;
data(i+1,10) = ((data(i+1,7)-data(i,7))/(data(i+1,2)-data(i,2)))*100;
data(i+1,11) = ((data(i+1,8)-data(i,8))/(data(i+1,2)-data(i,2)))*100;
end
end
end
end
% Same as above, but searches for spikes by searching for differences from
% a moving median that are larger than 1%.
xdata = data(:,3);
medData = medfilt1(xdata,51); % Add argument to limit blocksize and conserve memory, will take longer % 37
ng = find((xdata) > (1.01*medData) & (xdata) < (0.99*medData));
%ng = find(data(:,3)>0);
for n = 2:length(ng)-2
w = ng(n+1) - ng(n);
if w == 1
elseif w < 37 %16
t = [ng(n) ng(n+1)];
x = data(t,3);
y = data(t,4);
z = data(t,5);
tt = ng(n):ng(n+1);
data(ng(n):ng(n+1),3) = spline(t, x, tt);
data(ng(n):ng(n+1),4) = spline(t, y, tt);
data(ng(n):ng(n+1),5) = spline(t, z, tt);
for i = ng(n)-1:ng(n+1)
data(i+1,6) = ((data(i+1,3)-data(i,3))/(data(i+1,2)-data(i,2)))*100;
data(i+1,7) = ((data(i+1,4)-data(i,4))/(data(i+1,2)-data(i,2)))*100;
data(i+1,8) = ((data(i+1,5)-data(i,5))/(data(i+1,2)-data(i,2)))*100;
end
for i = ng(n)-1:ng(n+1)
data(i+1,9) = ((data(i+1,6)-data(i,6))/(data(i+1,2)-data(i,2)))*100;
data(i+1,10) = ((data(i+1,7)-data(i,7))/(data(i+1,2)-data(i,2)))*100;
data(i+1,11) = ((data(i+1,8)-data(i,8))/(data(i+1,2)-data(i,2)))*100;
end
end
end
out = data;