Skip to content

Commit

Permalink
Merge pull request matplotlib#7845 from vollbier/specgram_overlap_err
Browse files Browse the repository at this point in the history
Fixed bug with default parameters NFFT and noverlap in specgram()
  • Loading branch information
efiring authored Jan 17, 2017
2 parents cf83cd5 + 37481ad commit fa95b58
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion 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
7 changes: 6 additions & 1 deletion lib/matplotlib/mlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,12 @@ def specgram(x, NFFT=None, Fs=None, detrend=None, window=None,
"""
if noverlap is None:
noverlap = 128
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)))

spec, freqs, t = _spectral_helper(x=x, y=None, NFFT=NFFT, Fs=Fs,
detrend_func=detrend, window=window,
Expand Down

0 comments on commit fa95b58

Please sign in to comment.