添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I also see that for my data (audio data, real valued), np.fft.fft returns a 2 dimensional array of shape (number_of_frames, fft_length) containing complex numbers.

For np.fft.rfft returns a 2 dimensional array of shape (number_of_frames, ((fft_length/2) + 1)) containing complex numbers. I am led to believe that this only contains nonredundant FFT bins .

Can someone explain in more depth the difference between the commands and why the shape of the returned array is different. Thank you.

Possible duplicate of What is numpy.fft.rfft and numpy.fft.irfft and its equivalent code in MATLAB Mohammad Zain Abbas Sep 18, 2018 at 13:33 I don't want to know the difference between the fft and its inverse, and this is python not matlab MichaelAndroidNewbie Sep 18, 2018 at 14:12

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.

As a consequence, the algorithm is optimized and rfft is twice as fast. Furthermore, the spectrum is easier to plot :

In [124]: s=abs(sin(arange(0,2**13,3)))
In [125]: sp=rfft(s)
In [126]: plot(abs(sp))
                I like the plot addition to the answer and so upvoted you. If we were to plot the complex conjugates, would that just be symmetrical over the amplitude axis?
– MichaelAndroidNewbie
                Sep 18, 2018 at 14:19
                since  the frequency are proportional to  -n,-n+1,.....-1,0,1,... n-1,n. the +1 is for the central term which is is own symetric.
– B. M.
                Feb 26, 2021 at 7:53
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.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.