I cannot make sense of this behavior of scipy
. From the scipy.fftpack
docs i learn that the output of fft
is obviously complex and shaped like:
[y(0),y(1),..,y(n/2),y(1-n/2),...,y(-1)] if n is even
[y(0),y(1),..,y((n-1)/2),y(-(n-1)/2),...,y(-1)] if n is odd
so that if you plot something like np.abs(fft(signal))
you get the magnitude of the FFT.
If my signal is real-valued, then the negative frequencies give no information, and therefore one can use rfft
to speed things up a little. And here comes what I don't understand: why is the output of rfft
real valued, and shaped oddly like:
[y(0),Re(y(1)),Im(y(1)),...,Re(y(n/2))] if n is even
[y(0),Re(y(1)),Im(y(1)),...,Re(y(n/2)),Im(y(n/2))] if n is odd
Indeed with this definition, np.abs(rfft(signal))
gives you rubbish (you get alternately the absolute value of the real and imaginary parts of the FFT...), and you need some hacking to get the FFT magnitude. Why doesn't rfft
it simply output complex valued y(j)
s as:
[y(0),y(1),..,y(n/2)] if n is even
[y(0),y(1),..,y((n-1)/2)] if n is odd
so that things work nicely exactly as fft
(as one would expect)?
What am I missing?
EDIT: the issue is being discussed here