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
| ''' plot Engery figure ''' DB2_Dir = 'E:\\Datasets\\NinaPro\\DB5\\s1\\' E2 = scio.loadmat(DB2_Dir + 'S1_E2_A1.mat') E3 = scio.loadmat(DB2_Dir + 'S1_E3_A1.mat')
for i, label in enumerate(E2['stimulus']): if label != 0: E2['stimulus'][i] = label for i, label in enumerate(E3['stimulus']): if label != 0: E3['stimulus'][i] = label + 17
all_data = np.vstack((E2['emg'], E3['emg'])) all_label = np.vstack((E2['stimulus'], E3['stimulus'])) x = all_data[:,1] x1 = x[81200:81250] x2 = x[81400:81450] y1 = np.diff(x1)/0.005 y1 = np.insert(y1,0,0) y2 = np.diff(x2)/0.005 y2 = np.insert(y2,0,0)
plt.figure(1) plt.plot(all_data[:,1]) plt.figure(2) plt.plot(x1,y1) plt.plot(x2,y2) plt.show()
plt.scatter(x1, y1, c="blue", marker='o') plt.scatter(x2, y2, c="red", marker='o') plt.show() # 重组合x1,y1 (x1,y1) plot_list = [] for i, element in enumerate(x2): plot_list.append((element,y2[i])) print(plot_list)
a_points = np.array(plot_list) x = a_points[:, 0] y = a_points[:, 1]
ell = EllipseModel() ell.estimate(a_points)
xc, yc, a, b, theta = ell.params
print("center = ", (xc, yc)) print("angle of rotation = ", theta) print("axes = ", (a,b))
fig, axs = plt.subplots(2, 1, sharex=True, sharey=True) # axs[0].plot(x,y) axs[0].scatter(x, y, c="blue", marker='o') axs[1].scatter(x, y, c="blue", marker='o') # axs[1].plot(x, y) axs[1].scatter(xc, yc, color='red', s=100) axs[1].set_xlim(x.min(), x.max()) axs[1].set_ylim(y.min(), y.max())
ell_patch = Ellipse((xc, yc), 2*a, 2*b, theta*180/np.pi, edgecolor='red', facecolor='none')
axs[1].add_patch(ell_patch) plt.show()
|