Python 发现高于阈值的峰值

Python 发现高于阈值的峰值,python,scipy,Python,Scipy,我正在使用scipy.signal import查找峰值的。 是否可能找到大于指定阈值的所有峰值。 我不能完全肯定你是否能做到这一点。 例如:indexs=find_peaks(s_volts,threshold=0.5*maxPeak)我正在尝试查找大于最大峰值50%的所有峰值。不要认为有一种内置方法可以做到这一点。以下是您如何在没有scipy的情况下进行此操作: from scipy.signal import find_peaks import numpy as np x = np.arr

我正在使用scipy.signal import查找峰值的
。
是否可能找到大于指定阈值的所有峰值。
我不能完全肯定你是否能做到这一点。

例如:
indexs=find_peaks(s_volts,threshold=0.5*maxPeak)
我正在尝试查找大于最大峰值50%的所有峰值。

不要认为有一种内置方法可以做到这一点。以下是您如何在没有scipy的情况下进行此操作:

from scipy.signal import find_peaks
import numpy as np
x = np.array([1,2,3,2,1,2,3,2,1,2,3,4,3,2,1,2,3,4,7,4,3,2,1])
peaks_indices = find_peaks(x)[0]
peaks = np.array(list(zip(peaks_indices, x[peaks_indices])))
threshold = 0.5 * max(x[peaks_indices])
filtered_peaks = [(index, value) for index, value in peaks if value > threshold]

# If you just want the indices:
filtered_peaks_indices = [index for index, value in peaks if value > threshold]

# Or just want the values
filtered_peaks_values = [value for index, value in peaks if value > threshold]

# Visualize
from matplotlib import pyplot as plt
plt.plot(range(len(x)), x)
for index in peaks_indices:
     plt.axvline(index)

plt.axhline(threshold)
plt.scatter(filtered_peaks_indices, filtered_peaks_values, s=200)
plt.show()


不要认为有一种内在的方式可以做到这一点。以下是您如何在没有scipy的情况下进行此操作:

from scipy.signal import find_peaks
import numpy as np
x = np.array([1,2,3,2,1,2,3,2,1,2,3,4,3,2,1,2,3,4,7,4,3,2,1])
peaks_indices = find_peaks(x)[0]
peaks = np.array(list(zip(peaks_indices, x[peaks_indices])))
threshold = 0.5 * max(x[peaks_indices])
filtered_peaks = [(index, value) for index, value in peaks if value > threshold]

# If you just want the indices:
filtered_peaks_indices = [index for index, value in peaks if value > threshold]

# Or just want the values
filtered_peaks_values = [value for index, value in peaks if value > threshold]

# Visualize
from matplotlib import pyplot as plt
plt.plot(range(len(x)), x)
for index in peaks_indices:
     plt.axvline(index)

plt.axhline(threshold)
plt.scatter(filtered_peaks_indices, filtered_peaks_values, s=200)
plt.show()


如果可以事先定义阈值,则可以使用
height
参数。借用@omer tuchfeld示例:

from scipy.signal import find_peaks
import numpy as np
from matplotlib import pyplot as plt

x = np.array([1,2,3,2,1,2,3,2,1,2,3,4,3,2,1,2,3,4,7,4,3,2,1])

threshold = 0.5 * max(x)
peaks_indices = find_peaks(x, height=threshold)[0]
peaks_values = x[peaks_indices]

fig = plt.figure()
plt.plot(range(len(x)), x)
for index in peaks_indices:
    plt.axvline(index)

plt.axhline(threshold)
plt.scatter(peaks_indices, peaks_values, s=200)
plt.show()

如果可以事先定义阈值,则可以使用
height
参数。借用@omer tuchfeld示例:

from scipy.signal import find_peaks
import numpy as np
from matplotlib import pyplot as plt

x = np.array([1,2,3,2,1,2,3,2,1,2,3,4,3,2,1,2,3,4,7,4,3,2,1])

threshold = 0.5 * max(x)
peaks_indices = find_peaks(x, height=threshold)[0]
peaks_values = x[peaks_indices]

fig = plt.figure()
plt.plot(range(len(x)), x)
for index in peaks_indices:
    plt.axvline(index)

plt.axhline(threshold)
plt.scatter(peaks_indices, peaks_values, s=200)
plt.show()