The tools package contains various modules with different uses.


distance/divergence functions

2013 Jean-Louis Durrieu, Y)[source]

value = ISDistortion(X, Y)

Returns the value of the Itakura-Saito (IS) divergence between matrix X and matrix Y. X and Y should be two NumPy arrays with same dimension.


Simple Nonnegative Matrix Factorization (NMF) routines to be used to estimate initial parameters in FASST.

Relevant references:

[Durrieu2010]J.-L. Durrieu, G. Richard, B. David and C. Fevotte, Source/Filter Model for Main Melody Extraction From Polyphonic Audio Signals, IEEE Transactions on Audio, Speech and Language Processing, special issue on Signal Models and Representations of Musical and Environmental Sounds, March 2010, Vol. 18 (3), pp. 564 – 575.
[Fevotte2009](1, 2) C. Fevotte and N. Bertin and J.-L. Durrieu, Nonnegative matrix factorization with the Itakura-Saito divergence. With application to music analysis, Neural Computation, vol. 21 (3), pp. 793-830, March 2009. [pdf], nbComps=10, niter=10, verbose=0, Winit=None, Hinit=None, updateW=True, updateH=True)[source]

NMF multiplicative gradient, for Itakura Saito divergence measure between SX and,H)

\[\mathbf{S}_X \approx \mathbf{W} \mathbf{H}\]\[s_{X, fn} \approx \sum_{k=1}^K w_{fk} h_{kn}\]

See for instance [Fevotte2009].

  • SX (numpy.ndarray) – Matrix to be factorized
  • nbComps (integer) – Number of components / factors into which to decompose SX
  • niter (integer) – Number of iterations for the NMF algorithm
  • verbose (integer) – 0 for null verbosity, 1 for normal and more for debug
  • Winit (numpy.ndarray) – Initial array for matrix W
  • Hinit (numpy.ndarray) – Initial array for matrix H
  • updateW (boolean) – whether to update W or not
  • updateH (boolean) – whether to update H or not

W and H (numpy.ndarray) - the “spectral” component dictionary matrix and the “activation” coefficient matrix.

Notes : For (probably marginal) efficiency, the amplitude matrix H is “transposed”, such that its use in the operations uses a C-ordered contiguous array. The output is however in the “correct” form., nbComps=10, niter=10, verbose=0)[source]

NMF multiplicative gradient, for Itakura Saito divergence measure between SX and,H)

See for instance [Fevotte2009]., nbComps=10, nbFiltComps=10, niter=10, verbose=0, Winit=None, Hinit=None, WFiltInit=None, HFiltInit=None, updateW=True, updateH=True, updateWFilt=True, updateHFilt=True, nbResComps=2)[source]

Implements a simple source/filter NMF algorithm, similar to that introduced in [Durrieu2010]


Plotting tools to be used with PyFASST and audioModel classes


>>> import as pt
>>> # display the estimated spectral components
>>> # (one per row of subplot)
>>> pt.subplotsAudioModelSpecComps(model)
>>> # display a graph showing where the sources have been "spatially"
>>> # estimated: in an anechoic case, ideally, the graph for the 
>>> # corresponding source is null everywhere, except at the delay 
>>> # between the two channels:
>>> pt.plotTimeCorrelationMixingParams(model), **kwargs)[source]

Computes the inverse Fourier transform of the ratio of each of the ‘steering vectors’, for each spatial component. This correlation provides some insight in the spatial mixing process, since for an anechoic pair of steering vectors, the ratio is almost a complex exponential, with spatial frequency equal to the delay of arrival between the 2 channels.


  • model – a source model, instance of pyfasst.audioModel.FASST
  • kwargs – the other keyword arguments are passed to a plt.plot() Please refer to that function to see what keywords are accepted.


Returns:1. delays - an array containing the delays in samples, the axis corresponding to the other returned arrays

2. delayDetectionFunction - an array of which each column corresponds to a spatial component in model, nimp='FB')[source]

Display any of the field for the first factor of each spectral component of model, nimp should therefore either be ‘FB’, ‘FW’, ‘TW’ or ‘TB’.

model should be instance of (at least) FASST, fig=None, diffdispdb=60)[source]

Computes the spectral powers for each of the spatial components of model, and displays them on a single figure.

model should be instance of a sub-class of FASST[source]

Displays the time weights for each of the spectral component of model.

model should be instance of (at least) FASST


gathers signal processing tools, freqs=None, axis=None, samplingrate=44100, fouriersize=2048, f0min=80, f0max=3000, stepnote=16, numberHarmonics=20, threshold=0.5, detectFunc=<function sum at 0x1020a1e60>, weightFreqs=None, debug=False)[source]

Computes the Harmonic Sum

detectFunc should be a function taking an array as argument, and

threshold is homogenous to a tone on the western musical scale, **kwargs)[source]

Computes the harmonic sum, **kwargs)[source]

Computes the harmonic sum, a_01, a_11)[source]

This inverts a set of 2x2 Hermitian matrices

better check inv_herm_mat_2d() instead, and replace all reference to this by the former., sigma_x_off, verbose=False)[source]

Computes the inverse of 2D hermitian matrices.



ndarray, with (dim of axis=0) = 2

The diagonal elements of the matrices to invert. sigma_x_diag[0] are the (0,0) elements and sigma_x_diag[1] are the (1,1) ones.


ndarray, with the same dimensions as sigma_x_diag[0]

The off-diagonal elements of the matrices, more precisely the (0,1) element (since the matrices are assumed Hermitian, the (1,0) element is the complex conjugate)



ndarray, 2 x shape(sigma_x_off)

Diagonal elements of the inverse matrices. [0] <-> (0,0) [1] <-> (1,1)


ndarray, shape(sigma_x_off)

Off-diagonal (0,1) elements of the inverse matrices


ndarray, shape(sigma_x_off)

For each inversion, the determinant of the matrix.


The inversion is done explicitly, by computing the determinant (explicit formula for 2D matrices), then the elements of the inverse with the corresponding formulas.

To deal with ill-conditioned matrices, a minimum (absolute) value of the determinant is guaranteed., length=10)[source]

median filter, X1, neighborNb=10, verbose=0)[source]

Computes the eigen values and eigen vectors for a matrix X of shape 2 x F x N, computing the 2 x 2 covariance matrices for the F x N over the temporal neighborhood of size neighborNb., numberHarmonicsHS=50, numberHarmonicsHP=1, **kwargs)[source]

Sort the spectra in spectrum with respect to their F0 values, as estimated by HS * HP function.

20130521 DJL sort of works, but periodicity detection should be reworked according to YIN and the like, in order to obtain better estimates.


Useful functions for (audio) signal processing

2013 Jean-Louis Durrieu


db() db(positiveValue)

Returns the decibel value of the input positiveValue[source]

window = hann(args)

Computes a Hann window, with NumPy’s function hanning(args).[source]

ident() : identity function, return the inputs unchanged[source]

Find \(2^n\) that is equal to or greater than.

code taken from the website:[source]

window = sinebell(lengthWindow)

Computes a “sinebell” window function of length L=lengthWindow

The formula is:

\[window(t) = sin(\pi \frac{t}{L}), t=0..L-1\][source]

A root-squared Blackman-Harris window function.

For use in scholkhuber and klapuri’s framework.

Table Of Contents

Previous topic

Time-Frequency Transforms

This Page