如何在一维数组中找到峰

How to find peaks in 1d array

我正在读取 python 中的一个 csv 文件并从中准备一个数据框。我有一个 Microsoft Kinect,它正在记录 Arm Abduction 练习并生成此 CSV 文件。

我有this array of Y-Coordinates of ElbowLeft joint. You can visualize this here。现在,我想想出一个解决方案,可以计算这个数组中的峰数或局部最大值。

有人可以帮我解决这个问题吗?

您可以尝试使用平滑滤波器对数据进行平滑处理,然后找出前后值都小于当前值的所有值。这假设您想要序列中的所有峰。您需要平滑滤波器的原因是为了避免局部最大值。所需的平滑级别将取决于数据中存在的噪声。

一个简单的平滑过滤器将当前值设置为序列中当前值之前的 N 个值和之后的 N 个值的平均值以及正在分析的当前值。

您可以使用 scipy.signal 模块中的 find_peaks_cwt 函数来查找一维内的峰数组:

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

很简单,将数据放在一维数组中,然后将每个值与邻居进行比较,n-1和n+1数据都小于n。

按照 Robert Valencia 的建议阅读数据

   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