fixed off by one error for FFTmagnitude()#24
Conversation
The output off a Real-FFT is N/2+1 due to the dc offset. Hence the last frequency bin was discarded.
|
Hi @paradigmn, thank you for spotting this and creating a PR! It would be excellent if we could point to a reference to support that this is accurate. In reviewing The Fundamentals of FFT-Based Signal Analysis and Measurement (by NI) they say:
This implies the output length should be Do you have an authoritative reference we can point to to confirm the correct behavior? Absent this I might hop over to some of the other popular libraries (like numpy for matplotlib) and see what they tend to do... |
|
I was rewriting some Numpy Python code, when I notices this issue. They explicitly mention the buffer size in their documentation: https://numpy.org/doc/stable/reference/generated/numpy.fft.rfft.html. Would that be sufficient? |
Yeah, great reference! They say length should be
I'll add some tests to this PR and merge it in shortly. Thanks for your help here @paradigmn! |
|
no problem, you are welcome :) |
RFFT() returns an array of length N/2+1 and is now used to get the real component by FFTmagnitude() which previously returned an array of length N/2. This change will break systems that expected output to contain N/2 values...
swharden#24 verify values are identical to those produced by numpy

The output off a Real-FFT is N/2+1 due to the dc offset. Hence the last frequency bin was discarded.