在 python 中使用 FindPeaks 后如何从信号中提取最大值和最小值

发布于 2025-01-10 01:31:04 字数 370 浏览 2 评论 0原文

使用下面的示例,如何将标记为“顶部”和“底部”的最大值和最小值拉入单独的数组中?

# Load library
import numpy as np
from findpeaks import findpeaks

# Data
i = 10000
xs = np.linspace(0,3.7*np.pi,i)
X = (0.3*np.sin(xs) + np.sin(1.3 * xs) + 0.9 * np.sin(4.2 * xs) + 0.06 * np.random.randn(i))

# Initialize
fp = findpeaks(method='peakdetect')
results = fp.fit(X)
# Plot
fp.plot1d()

Using the example below, how can I pull the max and min values marked as 'Top' and 'Bottom' into a separate array?

# Load library
import numpy as np
from findpeaks import findpeaks

# Data
i = 10000
xs = np.linspace(0,3.7*np.pi,i)
X = (0.3*np.sin(xs) + np.sin(1.3 * xs) + 0.9 * np.sin(4.2 * xs) + 0.06 * np.random.randn(i))

# Initialize
fp = findpeaks(method='peakdetect')
results = fp.fit(X)
# Plot
fp.plot1d()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

却一份温柔 2025-01-17 01:31:04

我假设您使用的是 findpeaks 库 2.4.0results 变量已包含 minmax 值。您可以通过以下方式获取:

df_interp = results["df"]
min_peaks = df_interp["x"].loc[df_interp["valley"]].values
max_peaks = df_interp["x"].loc[df_interp["peak"]].values
print("min", min_peaks)
print("max", max_peaks)

I assume you're using the findpeaks library 2.4.0. The results variable already contains the min and max value. You can get it as follows:

df_interp = results["df"]
min_peaks = df_interp["x"].loc[df_interp["valley"]].values
max_peaks = df_interp["x"].loc[df_interp["peak"]].values
print("min", min_peaks)
print("max", max_peaks)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文