Core Utils (libnmfd.utils.core_utils)

libnmfd.utils.core_utils.colored_components(comp_A, col_vec=None)[source]

Maps a list containing parallel component spectrograms into a color-coded spectrogram image, similar to Fig. 10 in [1]. Works best for three components corresponding to RGB.

References

[1] Christian Dittmar and Meinard Müller “Reverse Engineering the Amen Break - Score-informed Separation and Restoration applied to Drum Recordings” IEEE/ACM Transactions on Audio, Speech, and Language Processing, 24(9): 1531-1543, 2016.

Parameters:
  • comp_A (list) – List with the component spectrograms, all should have the same dimensions

  • col_vec (TODO)

Returns:

rgbA (np.ndarray) – Color-coded spectrogram

libnmfd.utils.core_utils.diagonality_soft_constraints_nmf(H: ndarray, kern_ord: int) ndarray[source]

Implements a simplified version of the soft constraints in [1]

References

[1] Jonathan Driedger, Thomas Prätzlich, and Meinard Müller Let It Bee – Towards NMF-Inspired Audio Mosaicing In Proceedings of the International Conference on Music Information Retrieval (ISMIR): 350-356, 2015.

Parameters:
  • H (np.ndarray) – NMF activations given as matrix

  • kern_ord (int) – Order of smoothing operation

Returns:

H (np.ndarray) – Processed NMF activations

libnmfd.utils.core_utils.drum_specific_soft_constraints_nmf(W: ndarray, H: ndarray, decay: ndarray | float, kern: int) Tuple[ndarray, ndarray][source]

Implements the drum specific soft constraints that can be applied during NMF or NMFD iterations. These constraints affect the activation vectors only and are described in sec.23 of [1].

TODO

References

[1] Christian Dittmar, Patricio López-Serrano, and Meinard Müller Unifying Local and Global Methods for Harmonic-Percussive Source Separation In Proceedings of the IEEE International Conference on Acoustics, Speech, and Signal Processing (ICASSP), 2018.

Parameters:
  • W (np.ndarray) – NMF templates given in matrix/tensor form

  • H (np.ndarray) – NMF activations given as matrix

  • decay (list of np.ndarray) – Optional list of decay values per component.

  • kern (int TODO?) – Concrete smoothing kernel

Returns:
  • W (np.ndarray) – Processed NMF templates

  • H_out (np.ndarray) – Processed NMF activations

libnmfd.utils.core_utils.percussiveness_estimation(W: ndarray) ndarray[source]

This function takes a matrix or tensor of NMF templates and estimates the percussiveness by assuming that the lower part explains percussive and the upper part explains harmonic components. This is explained in sec. 2.4, especially eq. (4) in [1].

References

[1] Christian Dittmar, Patricio López-Serrano, and Meinard Müller Unifying Local and Global Methods for Harmonic-Percussive Source Separation In Proceedings of the IEEE International Conference on Acoustics, Speech, and Signal Processing (ICASSP), 2018.

Parameters:

W (np.ndarray) – K x R matrix (or K x R x T tensor) of NMF (NMFD) templates

Returns:

perc_weight (np.ndarray) – The resulting percussiveness estimate per component

libnmfd.utils.core_utils.visualize_components_kam(comp_A: List, time_res: float, freq_res: float, start_sec: float | None = None, end_sec: float | None = None, font_size: float = 11) Figure[source]

Given a non-negative matrix V, and its non non-negative NMF or NMFD components, this function provides a visualization.

Parameters:
  • comp_A (list) – List with R individual component magnitude spectrograms.

  • time_res (float) – Temporal resolution

  • freq_res (float) – Spectral resolution

  • start_sec (float) – Where to zoom in on the time axis

  • end_sec (float) – Where to zoom in on the time axis

  • font_size (float) – Font size of the figure.

Returns:

fh (matplotlib.figure.Figure) – The figure handle

libnmfd.utils.core_utils.visualize_components_nmf(V: ndarray, W: ndarray, H: ndarray, comp_V: ndarray, log_comp: float = 1.0, time_res: float | None = None, freq_res: ndarray | None = None, start_sec: float | None = None, end_sec: float | None = None, font_size: float = 11) Tuple[Figure, ndarray][source]

Given a non-negative matrix V, and its non non-negative NMF or NMFD components, this function provides a visualization.

Parameters:
  • V (np.ndarray) – K x M non-negative target matrix, in our case, this is usually sa magnitude spectrogram

  • W (np.ndarray) – K X R matrix of learned template matrices

  • H (np.ndarray) – R X M matrix of learned activations

  • comp_V (np.ndarray) – Matrix with R individual component magnitude spectrograms

  • log_comp (float) – Factor to control the logarithmic magnitude compression

  • time_res (float) – Temporal resolution

  • freq_res (float) – Spectral resolution

  • start_sec (float) – Where to zoom in on the time axis

  • end_sec (float) – Where to zoom in on the time axis

  • font_size (float) – Font size of the figure

Returns:
  • fh (matplotlib.figure.Figure) – The figure handle

  • log_freq_axis (np.ndarray) – Log frequency axis