numpy.fft.fft和numpy.fft.rfft有什么区别?

2024-05-28 23:20:12 发布

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

文件上说np.fft.fft这样做:

Compute the one-dimensional discrete Fourier Transform.

并且np.fft.rfft这样做:

Compute the one-dimensional discrete Fourier Transform for real input.

我还看到,对于我的数据(音频数据,实值),np.fft.fft返回包含复数的二维形状数组(帧数,fft长度)。

Fornp.fft.rfft返回包含复数的二维形状数组(帧数,((fft长度/2+1))。我相信这只包含非冗余FFT bin

是否有人能更深入地解释这些命令之间的区别以及返回数组的形状为何不同。谢谢您。


Tags: 文件the数据fftnptransform数组one
2条回答

文件中解释了原因:

When the DFT is computed for purely real input, the output is Hermitian-symmetric, i.e. the negative frequency terms are just the complex conjugates of the corresponding positive-frequency terms, and the negative-frequency terms are therefore redundant. This function does not compute the negative frequency terms, and the length of the transformed axis of the output is therefore n//2 + 1.

因此,算法得到了优化,rfft速度提高了一倍。此外,频谱更容易绘制:

In [124]: s=abs(sin(arange(0,2**13,3)))

In [125]: sp=rfft(s)

In [126]: plot(abs(sp))

enter image description here

通过示例解释了here的基本区别。正如上面所说:

import numpy as np

data = [0, 1, 2, 1, 0]

print("FFT output\n", np.fft.fft(data))
print("RFFT output\n", np.fft.rfft(data))

将导致:

FFT output
 [ 4.        +0.j         -2.11803399-1.53884177j  0.11803399+0.36327126j
  0.11803399-0.36327126j -2.11803399+1.53884177j]
RFFT output
 [ 4.        +0.j         -2.11803399-1.53884177j  0.11803399+0.36327126j]

Notice how the final element of the fft output is the complexconjugate of the second element, for real input. For rfft, thissymmetry is exploited to compute only the non-negative frequencyterms.

相关问题 更多 >

    热门问题