Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
Signal.spectrogram now returns values
Browse files Browse the repository at this point in the history
and Signal.plot_spectrogram plots it.
  • Loading branch information
FRidh committed Jun 22, 2016
1 parent 4e011ab commit b4dae46
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
22 changes: 22 additions & 0 deletions acoustics/_signal.pyx
Expand Up @@ -622,6 +622,27 @@ class Signal(numpy.ndarray):


def spectrogram(self, **kwargs):
"""Spectrogram of signal.
:returns: Spectrogram.
See :func:`scipy.signal.spectrogram`. Some of the default values have been changed.
The generated spectrogram consists by default of complex values.
"""
params = {
'nfft' : 4096,
'noverlap' : 128,
'mode' : 'complex',
}
params.update(kwargs)

t, s, P = spectrogram(self, fs=self.fs, **params)

return t, s, P


def plot_spectrogram(self, **kwargs):
"""
Plot spectrogram of the signal.
Expand All @@ -633,6 +654,7 @@ class Signal(numpy.ndarray):
.. note:: This method only works for a single channel.
"""
# To do, use :meth:`spectrogram`.
params = {
'xlim' : None,
'ylim' : None,
Expand Down
8 changes: 5 additions & 3 deletions tests/test__signal.py
Expand Up @@ -290,16 +290,18 @@ def test_plot_power_spectrum(self, signal):
def test_plot_phase_spectrum(self, signal):
signal.plot_phase_spectrum()

def test_spectrogram(self, signal):
def test_plot_spectrogram(self, signal):
if signal.channels > 1:
with pytest.raises(ValueError):
signal.spectrogram()
signal.plot_spectrogram()
else:
try:
signal.spectrogram()
signal.plot_spectrogram()
except NotImplementedError: # easy way to skip mpl 1.3.1 specgram mode issue
pass

def spectrogram(self, signal):
signal.spectrogram()

def test_pickling(self, signal):
import pickle
Expand Down

0 comments on commit b4dae46

Please sign in to comment.