This repository has been archived by the owner on Sep 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
plot_signal_process.py
85 lines (60 loc) · 1.53 KB
/
plot_signal_process.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
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
import matplotlib.pyplot as plt
import numpy as np
from sklearn.preprocessing import scale
from scipy.interpolate import interp1d
import sys
'''
Author: Federico Terzi
This module simply plots a signal.
You can specify the signal filename as a parameter in the terminal.
This is a work in progress...
'''
ALL_AXES=False
filename = sys.argv[1]
sample_size_fit = 50
data_raw = [map(lambda x: int(x), i.split(" ")[1:-1]) for i in open(filename)]
data = np.array(data_raw).astype(float)
f, axarr = plt.subplots(3)
axarr[0].set_title("Raw Data")
if ALL_AXES:
axarr[0].plot(data)
else:
axarr[0].plot(data[:,1])
#print data
data_norm = scale(data)
axarr[1].set_title("Y Normalized Data")
if ALL_AXES:
axarr[1].plot(data_norm)
else:
axarr[1].plot(data_norm[:,1])
acx = data_norm[:,0]
acy = data_norm[:,1]
acz = data_norm[:,2]
gx = data_norm[:,3]
gy = data_norm[:,4]
gz = data_norm[:,5]
x = np.linspace(0, data.shape[0], data.shape[0])
f_acx = interp1d(x, acx)
f_acy = interp1d(x, acy)
f_acz = interp1d(x, acz)
f_gx = interp1d(x, gx)
f_gy = interp1d(x, gy)
f_gz = interp1d(x, gz)
xnew = np.linspace(0, data.shape[0], sample_size_fit)
acx_stretch = f_acx(xnew)
acy_stretch = f_acy(xnew)
acz_stretch = f_acz(xnew)
gx_stretch = f_gx(xnew)
gy_stretch = f_gy(xnew)
gz_stretch = f_gz(xnew)
axarr[2].set_title("X Normalized to 50 samples")
axarr[2].plot(acx_stretch)
if ALL_AXES:
axarr[2].plot(acy_stretch)
axarr[2].plot(acz_stretch)
axarr[2].plot(gx_stretch)
axarr[2].plot(gy_stretch)
axarr[2].plot(gz_stretch)
plt.show()
# print data
# print data_norm