-
Notifications
You must be signed in to change notification settings - Fork 44
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
Bug with spectra when using real fft #105
Comments
These are all really great fixes! Thanks for putting in the time. |
I think this is not an xrft nor scipy periodogram bug. In scipy.signal.periodogram(), there is a default parameter "return_onesided" which is set to "True" as default. xrft power_spectrum() returns a two_sided spectrum. |
Actually, adding a "real" parameter in xrft makes xrft.power_spectrum() to return a one_sided spectrum whose amplitude is NOT doubled. real parameter in xrft is thus NOT an equivalent to return_onesided=True in scipy.periodogram() even if the two methods will return a one_sided spectrum. |
Thanks for the explanations @lanougue! I think it's super important we get all of this documented in the documentation. |
Thanks for your input, @lanougue. I agree that it was probably not fair for me to call this a "bug". But, I think most users would expect that the output of a function for computing power spectrum should integrate to (approximately) the signal energy. This is the behaviour of Regardless of what is decided here, I agree with @rabernat that clear documentation is what is really important. |
Hi @dougiesquire, |
I think there is a bug with the power spectrum estimates when a
real
dimension is provided.For real fft, Hermitian symmetry is exploited to compute only the non-negative frequency terms. But we can't ignore the energy in the negative frequency terms when computing spectra. To account for this, we need to multiply by 2 the energy of all but the first (DC) mode (and last mode if the signal length even - see https://numpy.org/doc/stable/reference/generated/numpy.fft.rfft.html).
I can demonstrate the issue and the fix through comparison to
scipy.signal.periodogram
:The text was updated successfully, but these errors were encountered: