2017-04-08 169 views
2

我正在讀取python中的csv文件並準備好一個數據幀。我有一個Microsoft Kinect,它正在錄製Arm Abduction練習並生成此CSV文件。如何在一維數組中找到峯值

我有ElbowLeft關節的Y座標this array。你可以看到這個here。現在,我想提出一個解決方案,可以統計這個數組中的峯值數量或局部最大值。

有人可以幫我解決這個問題嗎?

+0

嘗試'scipy.signal.find_peaks_cwt'。 – DyZ

回答

1

您可以嘗試使用平滑濾波器平滑數據,然後查找前後值小於當前值的所有值。這假定你想要序列中的所有峯。你需要平滑濾波器的原因是爲了避免局部最大值。所需的平滑程度取決於數據中存在的噪音。

一個簡單的平滑濾波器將當前值設置爲序列中當前值之前N個值的平均值和當前值的N個值以及要分析的當前值。

+0

我使用移動平均平滑來平滑它(與np.convolve)。並從scipy.signal使用argrelextrema。 –

0

可以使用find_peaks_cwt函數從scipy.signal模塊1-d陣列中找到峯:

from scipy import signal 
import numpy as np 

y_coordinates = np.array(y_coordinates) # convert your 1-D array to a numpy array if it's not, otherwise omit this line 
peak_widths = np.arange(1, max_peak_width) 
peak_indices = signal.find_peaks_cwt(y_coordinates, peak_widths) 
peak_count = len(peak_indices) # the number of peaks in the array 

點擊此處瞭解詳情:https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.find_peaks_cwt.html

0

這很容易,把數據存儲在1維數組中,並將每個值與相鄰數據進行比較,n-1和n + 1數據小於n。

讀取數據,羅伯特·瓦倫西亞表明

max_local=0 
for u in range (1,len(data)-1): 

if ((data[u]>data[u-1])&(data[u]>data[u+1])): 
          max_local=max_local+1