maad.sound.pcen

maad.sound.pcen(Sxx, gain=0.98, bias=2, power=0.5, b=0.025, eps=1e-06, display=False, savefig=False, **kwargs)[source]

Per-Channel Energy Normalization (PCEN)

This function normalizes a time-frequency representation Sxx by performing automatic gain control, followed by nonlinear compression [1] This function was adapted from librosa PCEN function [2] to match linear spectrogram representation

Parameters:
Sxx2D numpy array

Original spectrogram (or image)

gainscalar (>=0), optional, default is 0.98

Gain factor. Typical values should be less than 1.

biasscalar (>=0), optional, default is 2

Bias point of the nonlinear compression

powerscalar (>=0), optional, default is 0.5

Compression exponent. Typical values should be between 0 and 0.5. Smaller values of power result in stronger compression. At the limit power=0, polynomial compression becomes logarithmic.

bscalar between [0, 1], optional, default is 0.025

The filter coefficient for the low-pass filter.

epsscalar (>0), optional, default is 1e-6

A small constant used to ensure numerical stability of the filter.

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 PCEN

enhance_profile1d ndarray of scalar

Enhance profile

PCENxx2d ndarray of scalar

enhanced map

References

[1]

Lostanlen, V., Salamon, J., McFee, B., Cartwright, M., Farnsworth, A., Kelling, S., and Bello, J. P. Per-Channel Energy Normalization: Why and How. IEEE Signal Processing Letters, 26(1), 39-43. DOI: 10.1109/LSP.2018.2878620

[2]

McFee, Brian, Colin Raffel, Dawen Liang, Daniel PW Ellis,Matt McVicar, Eric Battenberg, and Oriol Nieto. “librosa: Audio and music signal analysis in python.” In Proceedings of the 14th python in science conference, pp. 18-25. 2015. https://librosa.org/doc/main/generated/librosa.pcen.html