-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaximum.py
46 lines (39 loc) · 1.52 KB
/
maximum.py
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
import numpy as np
import matplotlib.pyplot as plt
# -------------- Import data ----------#
data = np.genfromtxt("D:/Work/SLIIT/Humain gait/data/New Analysis/MAL/200 Steps/IMU Data/new_F1T1.csv", delimiter=',',
skip_header=1, dtype=np.float)
# data [row,column], zero indexed # extract entire column [:, x] #extract entire row [x,:]
# -------------------------------------#
# ------------- data setup ------------#
gyro_z = data[:, 6]
time = data[:, 0]
rows = data.shape[0] # no. of rows in array
# -------------------------------------#
# ------- initialize numpy arrays -----#
dif = np.zeros((rows, 1))
max_number = np.zeros((rows, 1))
maximum = np.zeros((rows, 1))
# -------------------------------------#
for i in range(rows - 2):
# --------- Differentiation -------#
# v_dif = gyro_z[i+1]- gyro_z[i]
# t_dif = time[i+1] - time[i]
# dif[i] = v_dif/t_dif
# ---------------------------------#
# --------- Maximum ---------------#
if gyro_z[i] < gyro_z[i + 1] and gyro_z[i + 1] > gyro_z[i + 2]:
max_number[i] = 1 # iterable for total maximums
maximum[i + 1] = gyro_z[i + 1]
# ---------------------------------#
print('total number of maximums =', sum(max_number))
# ----------- Plot setup --------------#
plt.plot(time, gyro_z, label="original")
plt.plot(time, maximum, label="maximum")
plt.xlabel('x - axis')
plt.ylabel('y - axis')
plt.title('original vs. maximums ')
plt.legend()
# ----------- Display plot ------------#
plt.show()
# -------------------------------------#