2017-04-08 33 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 
相关问题