New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
One extra array element from Magnitude and Power methods? #68
Comments
Hi @MV10, This extra point is only present when the I think the lowest number represents the DC component, and the highest number is the magnitude of the signal at the Nyquist frequency (sample rate / 2). When the full array is returned the data is mirrored around these points, and the length is equal to the input length. Lines 157 to 174 in 6f341bb
However, if convention in other software packages does something different, I'd be happy to modify the functionality of FftSharp to return data more consistent with what others do FYI I'm looking over https://www.sjsu.edu/people/burford.furman/docs/me120/FFT_tutorial_NI.pdf page 2 "Converting from a Two-Sided Power Spectrum to a Single-Sided Power Spectrum" to see if I can get some insights here |
This comment was marked as outdated.
This comment was marked as outdated.
Okay, I think I figured this out my original reasoning. My understanding was that the DC component (gray square) and Nyquist frequency (yellow square) are shared by both the positive (blue) and negative (orange) magnitudes. ... however, is this the best behavior? I'm still deciding 😅 |
I confirmed the length N/2+1 behavior is shared by Python (SciPy), so I'm satisfied with that! I think thinks are good as they are 😎 Thanks for raising the original question @MV10! This topic isn't very intuitive, and I'm glad to have some written justification now about why things are the way they are. import numpy as np
import scipy.fft
xs = np.arange(1024) / 10
data = np.sin(xs)
print(f"data length: {len(data)}")
fft = scipy.fft.fft(data)
print(f"fft length: {len(fft)}")
rfft = scipy.fft.rfft(data)
print(f"rfft length: {len(rfft)}")
|
Gotcha. Interesting. Thank you, this library is incredibly handy! |
I am passing 2048 PCM samples to either
FFT.Magnitude
orFFT.Power
, and I'm getting back 1025 elements instead of 1024.This isn't a big deal since, of course, most of the "far end" (for music) is zero or near-zero, but I wasn't expecting that. Is this known/expected for some reason? Or am I doing something wrong? Nothing fancy in the code, reading 16-bit
short
samples via OpenAL:The text was updated successfully, but these errors were encountered: