-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.py
111 lines (82 loc) · 2.23 KB
/
data.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
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
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('./EMG_data/01/1_raw_data_13-12_22.03.16.txt', sep="\t")
# convert class column to integer type
df['class'] = df['class'].astype(int)
# extract data from dataFrame to separate numpy arrays
time_col = df.loc[:, 'time']
class_col = df.loc[:, 'class']
channel1_col = df.loc[:, 'channel1']
channel2_col = df.loc[:, 'channel2']
channel3_col = df.loc[:, 'channel3']
t = time_col.values
cl = class_col.values
ch = channel1_col.values
ch2 = channel2_col.values
ch3 = channel3_col.values
# multiply channel data by 1000 (convert to mV)
ch_mv = ch * 1000
ch_mv2 = ch2 * 1000
ch_mv3 = ch3 * 1000
# divide time data by 1000 (convert to sec)
t_sec = t / 1000
# plot1: ch_mv vs. t_sec
plt.ylabel('channel1 (mV)')
plt.xlabel('time in (s)')
plt.title('plot 1: EMG signal vs. time')
plt.plot(t_sec, ch_mv)
plt.show()
# plot 2: ch_mv vs. t_sec (red when class = 2)
# <----------------- yewon's attempt...? ----------------->
# sections of the signal where class = 2
first_signal = ch_mv[cl == 2]
first_time = t[cl == 2]
plt.plot(first_time, first_signal, color='red')
# sections of the signal where class != 2
first_signal = ch_mv[cl != 2]
first_time = t[cl != 2]
plt.plot(first_time, first_signal, color='blue')
# show the plot for the first signal
plt.show()
# plot 3: channel 1 to 3 plot (same colour)
plt.figure()
plt.subplot(311)
plt.ylabel('channel1')
plt.plot(t_sec, ch_mv)
plt.subplot(312)
plt.ylabel('channel2')
plt.plot(t_sec, ch_mv2)
plt.subplot(313)
plt.ylabel('channel3')
plt.plot(t_sec, ch_mv3)
plt.xlabel('time in s')
plt.show()
# plot 4: channel 1 to 3 plot (red when hand is clenched)
plt.figure()
plt.subplot(311)
plt.ylabel('channel1')
fs = ch_mv[cl == 2]
ft = t[cl == 2]
plt.plot(ft, fs, color='red')
fs = ch_mv[cl != 2]
ft = t[cl != 2]
plt.plot(ft, fs, color='blue')
plt.subplot(312)
plt.ylabel('channel2')
fs2 = ch_mv2[cl == 2]
ft2 = t[cl == 2]
plt.plot(ft2, fs2, color='red')
fs2 = ch_mv2[cl != 2]
ft2 = t[cl != 2]
plt.plot(ft2, fs2, color='blue')
plt.subplot(313)
plt.ylabel('channel3')
fs3 = ch_mv3[cl == 2]
ft3 = t[cl == 2]
plt.plot(ft3, fs3, color='red')
fs3 = ch_mv3[cl != 2]
ft3 = t[cl != 2]
plt.plot(ft3, fs3, color='blue')
plt.xlabel('time in s')
plt.show()