maad.sound.smooth

maad.sound.smooth(Sxx, std=1, verbose=False, display=False, savefig=None, **kwargs)[source]

Smooth a spectrogram with a gaussian filter.

Parameters:
Sxx2d ndarray of scalars

Spectrogram (or image)

stdscalar, optional, default is 1

Standard deviation of the gaussian kernel used to smooth the spectrogram. The larger is the number, the smoother will be the image and the longer it takes. Standard values should fall between 0.5 and 3.

verboseboolean, optional, default is False

Print messages

displayboolean, optional, default is False

Display the signal if True

savefigstring, optional, default is None

Root filename (with full path) is required to save the figures. Postfix is added to the root filename.

kwargs, optional. This parameter is used by plt.plot and savefig functions
  • savefilenamestr, optional, default :’_spectro_after_noise_subtraction.png’

    Postfix of the figure filename

  • extentlist of scalars [left, right, bottom, top], optional, default: None

    The location, in data-coordinates, of the lower-left and upper-right corners. If None, the image is positioned such that the pixel centers fall on zero-based (row, column) indices.

  • titlestring, optional, default‘Spectrogram’

    title of the figure

  • xlabelstring, optional, default‘Time [s]’

    label of the horizontal axis

  • ylabelstring, optional, default‘Amplitude [AU]’

    label of the vertical axis

  • cmapstring or Colormap object, optional, default is ‘gray’

    See https://matplotlib.org/examples/color/colormaps_reference.html in order to get all the existing colormaps examples: ‘hsv’, ‘hot’, ‘bone’, ‘tab20c’, ‘jet’, ‘seismic’, ‘viridis’…

  • vmin, vmaxscalar, optional, default: None

    vmin and vmax are used in conjunction with norm to normalize luminance data. Note if you pass a norm instance, your settings for vmin and vmax will be ignored.

  • extentscalars (left, right, bottom, top), optional, default: None

    The location, in data-coordinates, of the lower-left and upper-right corners. If None, the image is positioned such that the pixel centers fall on zero-based (row, column) indices.

  • dpiinteger, optional, default is 96

    Dot per inch. For printed version, choose high dpi (i.e. dpi=300) => slow For screen version, choose low dpi (i.e. dpi=96) => fast

  • formatstring, optional, default is ‘png’

    Format to save the figure

… and more, see matplotlib

Returns:
im_out: smothed or blurred image

Examples

>>> import maad

Load audio recording and convert it into spectrogram

>>> s, fs = maad.sound.load('../data/cold_forest_daylight.wav')
>>> Sxx,tn,fn,ext = maad.sound.spectrogram (s, fs, tcrop=(5,10), fcrop=(0,10000))   

Convert linear spectrogram into dB

>>> Sxx_dB = maad.util.power2dB(Sxx) +96

Smooth the spectrogram

>>> Sxx_dB_std05 = maad.sound.smooth(Sxx_dB, std=0.5)
>>> Sxx_dB_std10 = maad.sound.smooth(Sxx_dB, std=1)
>>> Sxx_dB_std15 = maad.sound.smooth(Sxx_dB, std=1.5)

Plot spectrograms

>>> import matplotlib.pyplot as plt 
>>> fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1)
>>> ax1, fig = maad.util.plot2d(Sxx_dB, ax=ax1, extent=ext, title='original', vmin=10, vmax=70)
>>> ax2, fig = maad.util.plot2d(Sxx_dB_std05, ax=ax2, extent=ext, title='smooth (std=0.5)', vmin=10, vmax=70)
>>> ax3, fig = maad.util.plot2d(Sxx_dB_std10, ax=ax3, extent=ext, title='smooth (std=1)', vmin=10, vmax=70)
>>> ax4, fig = maad.util.plot2d(Sxx_dB_std15, ax=ax4, extent=ext, title='smooth (std=1.5)', vmin=10, vmax=70)
>>> fig.set_size_inches(7,9)
>>> fig.tight_layout()