maad.sound.median_equalizer
- maad.sound.median_equalizer(Sxx, display=False, savefig=None, **kwargs)[source]
Remove background noise in spectrogram using median equalizer.
- Parameters:
- Sxx2D numpy array
Original spectrogram (or image), !!! not in dB
- 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
- figsizetuple of integers, optional, default: (4,10)
width, height in inches.
- 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:
- Sxx_out2d ndarray of scalar
Spectrogram after denoising
References
[1]This function has been proposed first by Carol BEDOYA <carol.bedoya@pg.canterbury.ac.nz> Adapted by S. Haupert Oct 9, 2018 for Python
Examples
Load audio recording and convert it into spectrogram
>>> s, fs = maad.sound.load('../data/rock_savanna.wav') >>> Sxx,tn,fn,ext = maad.sound.spectrogram (s, fs)
Convert linear spectrogram into dB
>>> Sxx_dB = maad.util.power2dB(Sxx) +96
Remove stationnary noise from the spectrogram
>>> Sxx_noNoise = maad.sound.median_equalizer(Sxx) >>> Sxx_dB_noNoise = maad.util.power2dB(Sxx_noNoise)
Plot both spectrograms
>>> import matplotlib.pyplot as plt >>> import numpy as np >>> fig, (ax1, ax2) = plt.subplots(2, 1) >>> maad.util.plot2d(Sxx_dB, ax=ax1, extent=ext, title='original', vmin=np.median(Sxx_dB), vmax=np.median(Sxx_dB)+40) >>> maad.util.plot2d(Sxx_dB_noNoise, ax=ax2, extent=ext, title='Without stationary noise',vmin=np.median(Sxx_dB_noNoise), vmax=np.median(Sxx_dB_noNoise)+40) >>> fig.set_size_inches(15,8) >>> fig.tight_layout()