np.fft.fftfreq 实际上是做什么的?

What does np.fft.fftfreq actually do?

我有一个每月的时间序列,我正在对其进行离散傅立叶变换。 但是我对numpy如何将时域转换为频域感到困惑?

我正在使用 np.fft.fftfreq,我的时间数组有 708 个索引,每个月都会计算数据的每个测量值。

这是使用 numpy fftfreq 的输出频率:

frequency = np.fft.fftfreq(len(time_months),d=1)

print(frequency)

output:
[0.         0.00141243 0.00282486 0.00423729 0.00564972 0.00706215
 0.00847458 0.00988701 0.01129944 0.01271186 0.01412429 0.01553672
 0.01694915 0.01836158 0.01977401 0.02118644 0.02259887 0.0240113
 0.02542373 0.02683616 0.02824859 0.02966102 0.03107345 0.03248588
 0.03389831 0.03531073 0.03672316 0.03813559 0.03954802 0.04096045
 0.04237288 0.04378531 0.04519774 0.04661017 0.0480226  0.04943503
 0.05084746 0.05225989 0.05367232 0.05508475 0.05649718 0.0579096
 0.05932203 0.06073446 0.06214689 0.06355932 0.06497175 0.06638418
 0.06779661 0.06920904 0.07062147 0.0720339  0.07344633 0.07485876
 0.07627119 0.07768362 0.07909605 0.08050847 0.0819209  0.08333333
 0.08474576 0.08615819 0.08757062 0.08898305 0.09039548 0.09180791
 0.09322034 0.09463277 0.0960452  0.09745763 0.09887006 0.10028249
 0.10169492 0.10310734 0.10451977 0.1059322  0.10734463 0.10875706... 
0.49152542 0.49293785 0.49435028 0.49576271 0.49717514 0.49858757
 0.5

但是当我尝试查看采样率和奈奎斯特频率时,我无法重新创建 numpys 频率输出。 np.fft.fftfreq 将时域转换为频域的真正作用是什么?

我试过这个:

sample_time = np.diff(time_months) #taking difference between each time stamp

sample_time_mean = np.mean(sample_time)

print('sample time (months)', sample_time_mean, 'months')

sample_time_mean_days = sample_time_mean*30.4 #days

print('sample time (days)', sample_time_mean_days, 'days')

sample_rate_days = 1/sample_time_mean_days

print('Sampling rate (per day, 1/sample time) =', sample_rate_days, 'sample/day')

nyq = sample_rate_days/2

print('nyquist frequency (per day)', nyq)

sample time (months) 0.08333333333325754 months
sample time (days) 2.5333333333310293 days
Sampling rate (per day, 1/sample time) = 0.39473684210562215 sample/day
nyquist frequency (per day) 0.19736842105281108

可以找到 fftfreq 正在做什么 here

有关输入信号与傅里叶变换之间关系的更多信息,请参见here

奈奎斯特频率只是获得信号完整信息所需的最小采样频率,不一定会限制 FFT 结果。