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

Fixed bug with default parameters NFFT and noverlap in specgram() #7845

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

Merged
merged 3 commits into from
Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Set defaults for NFFT and noverlap function wide in _axes.specgram() …
…and mlab.specgram().
  • Loading branch information
DietBru committed Jan 16, 2017
commit 37481ad842cf46317e18ef0d0deae834fd4af890
11 changes: 5 additions & 6 deletions 11 lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7200,8 +7200,12 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
if not self._hold:
self.cla()

if NFFT is None:
NFFT = 256 # same default as in mlab.specgram()
if Fc is None:
Fc = 0
Fc = 0 # same default as in mlab._spectral_helper()
if noverlap is None:
noverlap = 128 # same default as in mlab.specgram()

if mode == 'complex':
raise ValueError('Cannot plot a complex specgram')
Expand Down Expand Up @@ -7234,11 +7238,6 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
Z = np.flipud(Z)

if xextent is None:
# define default values:
if noverlap is None:
noverlap = 128 # defined in mlab.specgram
if NFFT is None:
NFFT = 256 # defined in mlab._spectral_helper
# padding is needed for first and last segment:
pad_xextent = (NFFT-noverlap) / Fs / 2
xextent = np.min(t) - pad_xextent, np.max(t) + pad_xextent
Expand Down
6 changes: 4 additions & 2 deletions 6 lib/matplotlib/mlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,8 +1273,10 @@ def specgram(x, NFFT=None, Fs=None, detrend=None, window=None,

"""
if noverlap is None:
noverlap = 128
if len(x) <= (256 if NFFT is None else NFFT): # see _spectral_helper()
noverlap = 128 # default in _spectral_helper() is noverlap = 0
if NFFT is None:
NFFT = 256 # same default as in _spectral_helper()
if len(x) <= NFFT:
warnings.warn("Only one segment is calculated since parameter NFFT " +
"(=%d) >= signal length (=%d)." % (NFFT, len(x)))

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.