Answer a question

The documentation says that np.fft.fft does this:

Compute the one-dimensional discrete Fourier Transform.

and np.fft.rfft does this:

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

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.

Answers

Basic difference is explained here via example. As it says:

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))

will result in:

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.

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐