0
以下我的問題:我有一個PSD的理論模型,基於此我計算了一個時間序列。這個時間序列經過一些修改後,應該被轉換回我的PSD。不幸的是,我沒有得到我的原PSD回來,但略有不同的一個,我不知道爲什麼......從時間序列的PSD估計
這裏是我的一些說明性代碼:
import numpy as np
from scipy import fftpack
import matplotlib.pyplot as plt
bins = [1,2,3,4,5,6] #spots in the frequency domain
PSD = [7,8,7,10,6,3]
plt.loglog(bins, PSD)
t = np.linspace(0,1,2**9, endpoint = 'false')
signal = np.zeros_like(t)
for i in range(6):
signal += np.sqrt(PSD[i]) * np.cos(2*np.pi* t * bins[i] + random.uniform(0,2*np.pi))
n = signal.size
timestep = t[1]-t[0]
freq = np.fft.fftfreq(n, d=timestep)
freq = freq[:freq.size/2]
PSD_from_timeserie = abs(scipy.fftpack.fft(signal)/ n * 2)**2
PSD_from_timeserie = PSD_from_timeserie[:PSD_from_timeserie.size/2]
plt.loglog(freq, PSD_from_timeserie, 'x')
plt.show()
這幾乎提供了正確的PSD,因爲你可以輕鬆退房......任何關於錯誤的地方的建議?