实时序列,numpy ifft v.i.的差异

2024-05-23 17:16:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我想生成一个随机的时间序列,具有指定的光谱形状。为此,我将从适当的频谱分布中提取随机复傅立叶系数,然后将频率转换为时域。在

为了产生一个实时的时间序列,傅里叶频谱必须有真实的直流和奈奎斯特系数,并且具有对称的负频率。在

当我这样做的时候,我得到的行为与numpy的ifft和它的irfft不同。在

作为一个例子,这里有一个32个样本的白色光谱:

import numpy as np

Nsamp = 2**5
Nfreq = (Nsamp-1)//2 # num pos freq bins not including DC or Nyquist

DC = 0.
f_pos = np.random.randn(Nfreq) + 1j*np.random.randn(Nfreq)
Nyquist = np.random.randn() # this is real
f_neg = f_pos[::-1] # mirror pos freqs

f_tot = np.hstack((DC, f_pos, Nyquist, f_neg))
f_rep = np.hstack((DC, f_pos, Nyquist))

t1 = np.fft.ifft(f_tot)
t2 = np.fft.irfft(f_rep)

print(t1)
print(t2)

我希望t1都是真实的,t1和{}都是一致的(在机器精度范围内)。两者都不是真的。在

{I>正确使用cd1}?看看np.fft.fftfreq(Nsamp)输出的频率,我认为我为输入正确地构建了f_tot。在

irfft是正确的结果,所以我将使用它。。。但我想知道未来如何使用ifft。在


^{} docs

A[0] contains the zero-frequency term (the sum of the signal), which is always purely real for real inputs. Then A[1:n/2] contains the positive-frequency terms, and A[n/2+1:] contains the negative-frequency terms, in order of decreasingly negative frequency. For an even number of input points, A[n/2] represents both positive and negative Nyquist frequency, and is also purely real for real input.


Tags: theposnprandomdcreal频率t1