如何计算大数据的fft,避免内存耗尽?

How to calculate fft of large size data ,avoid memory exhausted?

用16GB内存计算fft,导致内存耗尽

print(data_size)
freqs, times, spec_arr = signal.spectrogram(data, fs=samp_rate,nfft=1024,return_onesided=False,axis=0,scaling='spectrum',mode='magnitude')

输出如下:

537089518
Killed

如何使用现有的 python 包计算大数据的 fft?

一个更通用的解决方案是自己做。由于 well-known Cooley–Tukey FFT algorithm and multidimentional decomposition. For more information about this strategy, please read The Design and Implementation of FFTW3. You can do the operation in virtually mapped memory 的存在,一维 FFT 可以拆分成更小的 FFT,这样可以更轻松地做到这一点。 FFTW 等一些 library/package 使您能够 relatively-easily 执行快速 in-place FFT。您可能需要编写自己的 Python 程序包或使用 Cython,以免分配未映射内存的额外内存。

另一种解决方案是将您的数据保存在 HDF5 中(例如使用 h5py, and then use out_of_core_fft 然后再次读取文件。但是,请注意这个包有点旧并且似乎不再维护。