This repository has been archived by the owner on Sep 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frontforkanalysisrun1.m
243 lines (182 loc) · 4.61 KB
/
frontforkanalysisrun1.m
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
clear all; close all; clc;
data = importdata('H3LIS331DL_front_run_1_2_26_pm.csv');
% Obtain time index
t = data.data(:,1);
%import acceleration data
ax = 9.81*data.data(:,2);
ay = 9.81*data.data(:,3);
az = 9.81*data.data(:,4);
% apply filter: Standards
fs = 1000; % Sampling rate in Hz
T = 1/fs;
CFC = 166.62;
wd = 2 * pi * CFC * 2.0775;
wa = sin(wd * T/2) / cos(wd * T/2);
a0 = wa^2 / (1 + sqrt(2) * wa + wa^2);
a1 = 2 * a0;
a2 = a0;
b1 = -2 * (wa^2 - 1) / (1 + sqrt(2) * wa + wa^2);
b2 = (-1 + sqrt(2) * wa - wa^2) / (1 + sqrt(2) * wa + wa^2);
% Coefficient vectors
a = [a0 a1 a2];
b = [1 -b1 -b2];
% Display transfer function in command window
sys = tf(a,b);
% Filter Inputs
x = filtfilt(a,b,ax);
y = filtfilt(a,b,ay);
z = filtfilt(a,b,az);
maxaccelx = max(x)
maxaccely = max(y)
maxaccelz = max(z)
% plot raw data vs filterd data
figure
subplot(3,1,1)
plot(t,ax,'LineWidth',2)
hold on
plot(t,x,'LineWidth',1.2)
xlabel('time (s)')
ylabel('accel (m/s^2)')
legend('x-axis raw data','x-axis filtered')
subplot(3,1,2)
plot(t,ay,'LineWidth',2)
hold on
plot(t,y,'LineWidth',1.2)
xlabel('time (s)')
ylabel('accel (m/s^2)')
legend('y-axis raw data','y-axis filtered')
subplot(3,1,3)
plot(t,az,'LineWidth',2)
hold on
plot(t,z,'LineWidth',1.2)
xlabel('time (s)')
ylabel('accel (m/s^2)')
legend('z-axis raw data','z-axis filtered')
suptitle('raw and filtered acceleration vs time graphs')
%% integration
step = 0.0000001;
%find bounds manually with fitted function
% [fitx, pox] = PowerFitSplineDefault(t, x,0)
% curve fitted the data 'run1x' is the function
[fitx,pox] = run1x(t,x);
% bound where max oscilation occurs after peak but before 2nd zero
lbx = 3.604;
ubx = 3.61;
pt = [lbx:0.00001:ubx];
px = feval(fitx,pt);
plot(pt,px)
%if no zero choose min
% minqx = [4.293:0.00001:4.295];
% [mina,indexx] = min(feval(fitx,minqx))
%
% qx = minqx(indexx)
qx = fzero(fitx,[lbx,ubx])
% finding max acceleration between zeros
boundx = [qx:0.00001:ubx];
aboundx = feval(fitx,boundx);
[maxax,indx] = max(abs(aboundx))
% time where max a occurs
sx = boundx(indx);
%step for cumtrapz
% v and d integration from when a =0 to max a
vx = cumtrapz([qx:step:sx],[feval(fitx,[qx:step:sx])]);
dx = cumtrapz([qx:step:sx],vx);
if ubx == sx
error('upper bound not right')
end
%%
[fity,poy] = run1y(t,y);
% bound where max oscilation occurs after peak but before 2nd zero
lby = 3.607;
uby = 3.61;
pty = [lby:0.00001:uby];
py = feval(fitx,pty);
figure
plot(pty,py)
%if no zero choose min
% minqy = [4.293:0.00001:4.295];
% [minay,indexy] = min(feval(fity,minqy))
%
% qy = minqy(indexy)
qy = fzero(fity,[lby,uby])
% finding max acceleration between zeros
boundy = [qy:0.00001:uby];
aboundy = feval(fity,boundy);
[maxay,indy] = max(abs(aboundy))
% time where max a occurs
sy = boundy(indy);
%step for cumtrap
% v and d integration from when a =0 to max a
vy = cumtrapz([qy:step:sy],[feval(fity,[qy:step:sy])]);
dy = cumtrapz([qy:step:sy],vy);
if uby == sy
error('upper bound not right')
end
%%
[fitz,poz] = run1z(t,z);
% bound where max oscilation occurs after peak but before 2nd zero
lbz = 3.428;
ubz = 3.431;
%if no zero choose min
% minqz = [4.293:0.00001:4.295];
% [minaz,indexz] = min(feval(fitz,minqz))
%
% qz = minqz(indexz)
qz = fzero(fitz,[lbz,ubz])
% finding max acceleration between zeros
boundz = [qz:0.00001:ubz];
aboundz = feval(fitz,boundz);
[maxaz,indz] = max(abs(aboundz))
% time where max a occurs
sz = boundz(indz);
%step for cumtrapz
% v and d integration from when a =0 to max a
vz = cumtrapz([qz:step:sz],[feval(fitz,[qz:step:sz])]);
dz = cumtrapz([qz:step:sz],vz);
if ubz == sz
error('upper bound not right')
end
%%
%plot velocity and displacement curves
figure
subplot(6,1,1)
plot([qx:step:sx],vx)
xlabel('time (s)')
ylabel('velocity (m/s)')
title('velocity x-axis')
subplot(6,1,2)
plot([qx:step:sx],dx)
xlabel('time (s)')
ylabel('displacement (m)')
title('displacement x-axis')
subplot(6,1,3)
plot([qy:step:sy],vy)
xlabel('time (s)')
ylabel('velocity (m/s)')
title('velocity y-axis')
subplot(6,1,4)
plot([qy:step:sy],dy)
xlabel('time (s)')
ylabel('displacement (m)')
title('displacement y-axis')
subplot(6,1,5)
plot([qz:step:sz],vz)
xlabel('time (s)')
ylabel('velocity (m/s)')
title('velocity z-axis')
subplot(6,1,6)
plot([qz:step:sz],dz)
xlabel('time (s)')
ylabel('displacement (m)')
title('displacement z-axis')
format short
qx
qy
qz
sx
sy
sz
format long
ex = dx(end)
ey = dy(end)
ez = dz(end)