8000 BUG : fix scaling issue with mlab.psd and odd NFFT · matplotlib/matplotlib@17bc283 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 17bc283

Browse files
committed
BUG : fix scaling issue with mlab.psd and odd NFFT
closes #4324
1 parent 016f568 commit 17bc283

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/matplotlib/mlab.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,15 @@ def _spectral_helper(x, y=None, NFFT=None, Fs=None, detrend_func=None,
782782
# Also include scaling factors for one-sided densities and dividing by
783783
# the sampling frequency, if desired. Scale everything, except the DC
784784
# component and the NFFT/2 component:
785-
result[1:-1] *= scaling_factor
785+
786+
# if we have a even number of frequencies, don't scale NFFT/2
787+
if not NFFT % 2:
788+
slc = slice(1, -1, None)
789+
# if we have an odd number, just don't scale DC
790+
else:
791+
slc = slice(1, None, None)
792+
793+
result[slc] *= scaling_factor
786794

787795
# MATLAB divides by the sampling frequency so that density function
788796
# has units of dB/Hz and can be integrated by the plotted frequency

0 commit comments

Comments
 (0)
0