我想用Python3计算功率谱.从另一个关于这个主题的主题我得到了基本的成分.我认为应该是这样的:
ps = np.abs(np.fft.fft(x))**2
timeres = t[1]-t[0]
freqs = np.fft.fftfreq(x.size, timeres)
idx = np.argsort(freqs)
plt.plot(freqs[idx], ps[idx])
plt.show()
Run Code Online (Sandbox Code Playgroud)
这t是时间,x是光子计数.我也尝试过:
W = fftfreq(x.size, timeres=t[1]-t[0])
f_x = rfft(x)
plt.plot(W,f_x)
plt.show()
Run Code Online (Sandbox Code Playgroud)
但两者大多只是给我一个零左右的峰值(尽管它们不一样).我试图从这个计算功率谱:
哪个应该给我一个大约580Hz的信号.我在这做错了什么?
我试图在一个环中生成随机的x和y坐标,它的外半径为3.5,内半径为2.因此x和y必须满足以下条件:
x**2 + y**2 < 12.25 and x**2 + y**2 > 4
Run Code Online (Sandbox Code Playgroud)
我写了以下函数:
def meteorites():
circle = False
while circle == False:
r = np.array([uniform(-6., 6.), uniform(-6., 6.)])
# we will regenerate random numbers untill the coordinates
# are within the ring x^2+y^2 < 3,5^2 and x^2+y^2 > 2^2
if (r[0]**2+r[1]**2 < 12.25) and (r[0]**2+r[1]**2 > 4.):
circle = True
else :
circle = False
return r[0], r[1]
x = np.zeros(1000)
y = np.zeros(1000)
for i in range(1000):
x[i] = …Run Code Online (Sandbox Code Playgroud)