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
Inconsistency in function PSD when the NFFT parameter is an odd number #4324
Milestone
Comments
Thank you for the detailed bug report and explanation of what we were doing wrong! Should be fixed by #4326 In [6]: P
Out[6]: array([ 14.28571429, 3.22739913, 1.38941047, 1.09747611]) |
tacaswell
added a commit
to tacaswell/matplotlib
that referenced
this issue
Apr 12, 2015
e-q
added a commit
to e-q/scipy
that referenced
this issue
Apr 12, 2015
See matplotlib/matplotlib#4324 for description of the problem. The previous welch algorithm suffered from the same bug, so the unit tests had to be updated/corrected as well.
e-q
added a commit
to e-q/scipy
that referenced
this issue
May 5, 2015
See matplotlib/matplotlib#4324 for description of the problem. The previous welch algorithm suffered from the same bug, so the unit tests had to be updated/corrected as well.
fariza
pushed a commit
to fariza/matplotlib
that referenced
this issue
May 15, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Function
mlab.psd
appears to have one inconsistency if the NFFT parameter is an odd number. In such case, as the highest frequency is not the Nyquist frequency, instead isint(.5*NFFT)/float(dt*NFFT)
, there are two distinct values showing both at the positive and negative frequencies in the FFT result. Consider the following example:The resulting arrays
Su
andP
are:To convert
Su
to one-sided output, it is common to sum the Fourier coefficients corresponding to negative and positive frequencies. Considering thatu.size
is odd, the frequencies which correspond to the coefficients inSu
are:thus, as the
Su[1:4]
are the positive side coefficients andSu[4:]
the negative side, all coefficients are summed except forSu[0]
(which in this case, asu
is real is the same asSu[1:4] * 2
):This results in
Su_1side = [ 14.29, 3.23, 1.39, 1.10 ]
, whose last coefficient differs from the result ofP
, i.e. themlab.psd
result.Note that the lack of scaling of the last coefficient is not a problem when the NFFT is an even number. In such case, as the as the frequency array is:
there is only one coefficient for the highest frequency (
fnyquist
), thus it is not summed up with another coefficient.The text was updated successfully, but these errors were encountered: