简体   繁体   English

计算白噪声的功率谱密度时出现无法解释的对称性

[英]Unexplained symmetry when computing Power Spectral Density of white noise

I'm trying to learn more about noise, power spectral denisty (PSD) and statistical variances. 我正在尝试了解有关噪声,功率谱密度(PSD)和统计差异的更多信息。 With regards this I'm trying to compute the Power Spectral density of white noise, however, when I do I get a very odd symmetry. 关于这一点,我试图计算白噪声的功率谱密度,但是,当我这样做时,我得到一个非常奇怪的对称性。 my spectrum seems to be symmetric around the central frequency value, which is obviously incorrect. 我的频谱似乎围绕中心频率值对称,这显然是错误的。 I'm new to using autocorrelations and Power spectral densities so I'd appreciate if someone could help nudge me in the direction of the error. 我对使用自相关和功率谱密度是陌生的,因此,如果有人可以帮助我朝错误的方向发展,我将不胜感激。

Code to calculate PSD: 计算PSD的代码:

import numpy as np 
from math import sin, pi, log10
from allan_noise import white,pink,brown, violet
import acor
import numpy as np


#METHOD ONE: AUTOCORRELATION FUNCTION METHOD
def psd1(time_dats):
    #auto_corr = acor.function(time_dats)
    auto_corr = np.correlate(time_dats,time_dats,mode="same")

    #To check autocorrelation
    for i in range(len(auto_corr)):
        print i*.0000001 ,auto_corr[i]

    return fft(auto_corr) 

#DEFINE VARIABLES
t = .0001       #simulation time
N = 100000  #number of data points 
dt = t/N    #time interval between data points

#CREATE SIGNAL
sig = white(N)
df = 1.0/(t)
freq_axis = np.arange(0,N/t,df)

spec = psd1(sig)

#OPEN UP OUTPUT FILE
f = open('data/psdtest_f','w')
g = open('data/psdtest_t','w')

#PRINT OUT DATA
for i in range(N):
    f.write('%g %g\n' %(freq_axis[i],log10(abs(spec[i]))))
    g.write('%g %g\n' %(i*dt, sig[i]))

Using this code I produce the following graphs, which can be accessed here https://drive.google.com/#folders/0B8BdiIhqTYw7Vk1EaDFMQW84RHM : 使用此代码,我产生了以下图形,可以在这里https://drive.google.com/#folders/0B8BdiIhqTYw7Vk1EaDFMQW84RHM进行访问:

  1. Temporal Profile of the noise before calculations 计算之前噪声的时间分布

  2. Autocorrelation function calculated from the temporal profile (I'm aware the x axis scale is wrong but that doesn't contribute to the code any where else 根据时间轮廓计算的自相关函数(我知道x轴比例尺是错误的,但是在其他任何地方都不会对代码有贡献

  3. Power Spectral Denisty, beautifully symmetric though not supposed to be 功率谱密度,对称对称,虽然不应该这样

Any help anyone could provide as to whats causing this symmetry would be most helpful. 任何人都可以提供有关造成这种对称性的原因的任何帮助将是最有帮助的。 i've tested the code with a simple sin wave signal and I get expected results (with no symmetry) 我已经用简单的正弦波信号测试了代码,并且得到了预期的结果(没有对称性)

First,your function is written incorrect, you take fft from autocorr which is not your initial signal array. 首先,您的函数编写不正确,您从autocorr那里获取了fft,这不是您的初始信号数组。 Funny thing, because of the nature of rounding error you will get whit noise like psd from it as well. 有趣的是,由于舍入误差的性质,您也会从其中得到类似psd的白噪声。 Second, you calculating frequencies axis wrong, as they should be extended to N/(t*2) (which is Nyquist fr.). 其次,计算频率轴错误,因为它们应该扩展到N /(t * 2)(即奈奎斯特fr。)。 Instead, since your freq_axis array length is N, you retrieve N elements from you sig array, and because of that you just read negative frequencies with the same psd, which causes you the symmetry (taking log convert you variable to real and all the Fourier coefficients for negative freqs are just conjugates for positive ones). 相反,由于freq_axis数组的长度为N,因此您从sig数组中检索了N个元素,因此,您仅以相同的psd读取负频率,这导致了对称性(对数将变量转换为实数,所有傅里叶负频率的系数只是正频率的共轭)。 replacing your code with the following one give a perfectly good result: 用下面的代码替换您的代码可获得非常好的结果:

sig = white(N,1,N/t)
(siglog,freq_axis)=ml.psd(sig,N,(N/t), detrend=ml.detrend_none,
   window=ml.window_hanning, noverlap=0, pad_to=None,
    sides='default', scale_by_freq=None)
plt.plot(freq_axis,np.log10(siglog))
plt.show()

matplotlib.mlab.psd result matplotlib.mlab.psd结果

don't forget to import 别忘了导入

import matplotlib.mlab as ml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM