numpy.fft.fft 和 numpy.fft.rfft 有什么区别?
What is the difference between numpy.fft.fft and numpy.fft.rfft?
文档说 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
returns 一个二维形状数组 (number_of_frames, fft_length) 包含复数。
对于 np.fft.rfft
returns 一个包含复数的形状为 (number_of_frames, ((fft_length/2) + 1)) 的二维数组。我被引导相信这只包含 非冗余 FFT bins.
有人可以更深入地解释命令之间的区别以及返回数组的形状不同的原因。谢谢。
通过示例解释了基本差异 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 complex
conjugate of the second element, for real input. For rfft, this
symmetry is exploited to compute only the non-negative frequency
terms.
文档中解释了原因:
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))
文档说 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
returns 一个二维形状数组 (number_of_frames, fft_length) 包含复数。
对于 np.fft.rfft
returns 一个包含复数的形状为 (number_of_frames, ((fft_length/2) + 1)) 的二维数组。我被引导相信这只包含 非冗余 FFT bins.
有人可以更深入地解释命令之间的区别以及返回数组的形状不同的原因。谢谢。
通过示例解释了基本差异 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 complex conjugate of the second element, for real input. For rfft, this symmetry is exploited to compute only the non-negative frequency terms.
文档中解释了原因:
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))