Python:来自3d数据库的功率谱

时间:2017-02-10 03:00:01

标签: python fft average

我正在尝试计算常规分布式3D密度数据库的功率谱(1D)。但我一直将功率谱的峰值设为0.我很感谢你的帮助!

这是我的代码:

import numpy as np
import matplotlib.pyplot as plt

bins = 1.
tbins = 400.

density = np.random.rand(400,400,400)

x, y, z = np.mgrid[0:400, 0:400, 0:400]
x = x - 199.5
y = y - 199.5
z = z - 199.5

dist = np.sqrt(x**2+y**2+z**2)

FT = np.fft.fftn(density)
power = FT.real*FT.real + FT.imag*FT.imag

P = power.reshape(np.size(power))
dist = dist.reshape(np.size(dist))

intervals = np.array([nn*bins for nn in range(0,int(tbins)+1)])

p = np.histogram(dist, bins=intervals, weights=P)[0]
pd = np.histogram(dist, bins=intervals)[0]
pd.astype('float')
p = p/pd

plt.figure()
plt.plot(2.*np.pi/intervals[1:], p)
plt.show()

0 个答案:

没有答案