gpt4 book ai didi

python - 如何获得信号最大幅度 10% 时的 (x, y) 坐标?

转载 作者:太空宇宙 更新时间:2023-11-03 11:58:17 25 4
gpt4 key购买 nike

当正弦波是其最大幅度的 10% 时,我如何提取正弦波的 (x, y) 坐标,如图(红点)所示?我的“x 值”是时间和数组的索引号。

Sinewave

我试过这样的东西,它不能正常工作:

sinewave_max = sinewave[0:argmax(sinewave)]
for i,val in enumerate(sinewave_max):
if i == int(0.1*(len(sinewave_max))):
y = sinewave_max[i]
x = index(y) (#Pseudo-Code line)

最佳答案

这是一种方法。这个想法是有一个密集 x 点网格,然后定义一个小的公差值。然后在 y 数组中查找接近最大高度 (=1) 的 0.1 倍的值 在此公差范围内

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 10, 1000)
y = np.sin(x)

plt.plot(x, y)
plt.axhline(0, color='k')
tol = 1e-2
ind = np.argwhere(abs(y-0.1*max(y))<=tol)

plt.scatter(x[ind], y[ind], c='r', s=100, zorder=3)
plt.xlabel('Time')
plt.ylabel('Amplitude = sin(time)')
plt.title('Sine wave')
plt.grid()
plt.show()

enter image description here

关于python - 如何获得信号最大幅度 10% 时的 (x, y) 坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56304639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com