为什么这个白噪声频谱在 freq=0 时有一个峰值?

问题描述

从理论上我们知道白噪声的频谱是恒定的。 S(w)=S0

我已经编写了代码,在其中定义了一个白噪声,尽管是随机的。然后我对其应用快速傅立叶变换。我期待某种常数函数,但我得到了 w=0 的峰值。当我将 fft 应用于随机输入时,为什么我会得到 freq=0 的峰值?

这是我的代码

import matplotlib.pyplot as plt
import numpy as np
import scipy
from scipy.fft import fft,fftfreq,ifft
from scipy import  signal
#Define the time limits to create the array
tin=0
tfin=1
#the code works better with power of 2 (64;128;256;512;etc.)
Nt=127
#time span
T=tfin-tin
#time interval
dt=T/Nt
#array of time
t=np.arange(tin,tfin,dt)
#noise
noise=0.3*np.random.rand(Nt)
#array of the function to be transformed
x=noise
#creating the spectrum ordinate array
y=fft(x)
#Obtaining the frequency array correlated to the spectrum
freq=fftfreq(Nt,d=dt)
#Creating the time history from the spectrum
xinv=ifft(y)
#Plotting the spectrum X(w)
#I only want the positive freq values:
freq=freq[:Nt//2]
y=y[0:Nt//2]
#I want freq in rad/s
freq=freq*2*np.pi
#I want the absolute value of the spectrum
y=abs(y)
plt.plot(freq,y,label='Spectrum')
plt.legend(loc='upper left')
plt.xlabel('w[rad/s]')
plt.ylabel('X(w)')
plt.title('')
plt.grid()
plt.show()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...