2017-08-07 69 views
1

我目前正在製作一個設備,它使用MyoWare肌肉傳感器收集數據,將其發送到mysql數據庫,並使用matplotlib顯示圖形。由於這個設備是爲了運動目的(在我的情況下舉重),我想能夠確定用戶的重複次數。有誰知道或可以告訴我如何實現它?從matplotlib分析圖

Here is my graphs with 4 reps

我的Python代碼

conn = pymysql.connect(host="localhost", user="root", passwd="123456", db="XXX") 
 
cur = conn.cursor() 
 
query = """ 
 
SELECT CONVERT(data,SIGNED INTEGER),time FROM sensordata 
 
""" 
 
cur.execute(query) 
 
data = cur.fetchall() 
 
cur.close 
 

 
cur =conn.cursor() 
 
query1 = """ 
 
SELECT CONVERT(data1,SIGNED INTEGER),time1 FROM sensordata2 
 
""" 
 
cur.execute(query1) 
 
data1= cur.fetchall() 
 
cur.close 
 
conn.close() 
 

 
data,time= zip(*data) 
 
data1,time1= zip(*data1) 
 

 
data_moving_average = [] 
 
for initial_element_index in range(len(data)): 
 
    data_moving_average.append(sum(data[initial_element_index:initial_element_index+20])/5.) 
 
data_moving_average1 = [] 
 
for initial_element_index in range(len(data1)): 
 
    data_moving_average1.append(sum(data1[initial_element_index:initial_element_index+20])/5.) 
 

 
plt.plot(time,data_moving_average) 
 
plt.plot(time1,data_moving_average1)
什麼是我的數據庫裏面做的是計算,峯數
+-----+------+---------------------+----------------------------+ 
 
| id | data | time    | analyzetime    | 
 
+-----+------+---------------------+----------------------------+ 
 
| 1 | 1 | 2017-06-22 08:23:09 | 2017-06-22 08:23:09.846534 | 
 
| 2 | 0 | 2017-06-22 08:23:10 | 2017-06-22 08:23:10.048035 | 
 
| 3 | 0 | 2017-06-22 08:23:10 | 2017-06-22 08:23:10.333497 | 
 
| 4 | 0 | 2017-06-22 08:23:10 | 2017-06-22 08:23:10.656422 | 
 
| 5 | 0 | 2017-06-22 08:23:10 | 2017-06-22 08:23:10.865791 | 
 
| 6 | 0 | 2017-06-22 08:23:10 | 2017-06-22 08:23:10.954816 | 
 
| 7 | 0 | 2017-06-22 08:23:11 | 2017-06-22 08:23:11.147128 | 
 
| 8 | 0 | 2017-06-22 08:23:11 | 2017-06-22 08:23:11.402207 | 
 
| 9 | 0 | 2017-06-22 08:23:11 | 2017-06-22 08:23:11.613567 | 
 
| 10 | 0 | 2017-06-22 08:23:11 | 2017-06-22 08:23:11.867029 |

+0

究竟紅色和藍色曲線在圖形中是什麼意思? –

+0

@BatyrkhanSaduanov他們是我使用的兩個傳感器的個人圖形 –

+0

@BatyrkhanSaduanov但在我的情況下,現在我想專注於紅色確定重複次數(4)。你有什麼想法 ? –

回答

0

的一種方式。

您可以使用SciPy的,

from scipy import signal 

peakind = signal.find_peaks_cwt(data_moving_average, np.arange(1,100)) 
nbOfRepetitions = peakind.size 
print nbOfRepetitions 

UPDATE:

我找到了更好的功能,您的任務還使用SciPy的

from scipy.signal import argrelextrema 

peakind = argrelextrema(x, np.greater) 
nbOfRepetitions = peakind.size 
print nbOfRepetitions 
+0

有沒有辦法處理噪音(例如告訴'find_peaks_cwt'只在特定長度範圍內尋找峯值)? –

+0

好的,另一種方法是放置一個力量的門檻,就像40強被認爲是1次重複的力量。所以當你的力矩剛剛超過你的門檻時,你將不得不遍歷你的力量矩陣並計算出現次數。這樣對你好嗎? –