我正在尝试计算仅知道功率谱的信号的自相关函数。
为了测试我的方法,我想在自相关已知(缓慢下降)的$ 1 / f ^ 2 $噪声频谱上进行尝试。这是我的测试代码
import scipy as sp
import colorednoise as cn
def plot_acf(length, avg):
fig, ax1 = plt.subplots(1,1)
# get 1/f^2 noise.
data = cn.powerlaw_psd_gaussian(2, length)
# getting the power-spectrum. scipy.welch returns the power-spectrum, with
# positive frequencies first and then negative frequencies.
f, pxx = sp.welch(data, nperseg = avg, window = "hanning", return_onesided = False)
# remove the spurious imaginary part of the inverse fourier transform.
acf = np.real_if_close(np.fft.ifft(pxx))
ax1.plot(acf[:int(avg/2)])
但是它会生成如下所示的图:
这显然是错误的:相关强度太弱了,对于$ 1 / f ^ 2 $噪声信号,它的下降太快了。
您知道问题可能来自哪里吗?