TOOLS

The tools package contains various modules with different uses.

DISTANCES

distances.py

distance/divergence functions

2013 Jean-Louis Durrieu

pyfasst.tools.distances.ISDistortion(X, 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.

NONNEGATIVE MATRIX FACTORIZATION

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]
pyfasst.tools.nmf.NMF_decomp_init(SX, 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 np.dot(W,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].

Parameters:
  • 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
Returns:

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 np.dot operations uses a C-ordered contiguous array. The output is however in the “correct” form.

pyfasst.tools.nmf.NMF_decomposition(SX, nbComps=10, niter=10, verbose=0)[source]

NMF multiplicative gradient, for Itakura Saito divergence measure between SX and np.dot(W,H)

See for instance [Fevotte2009].

pyfasst.tools.nmf.SFNMF_decomp_init(SX, 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]

PLOT TOOLS

Plotting tools to be used with PyFASST and audioModel classes

Examples:

>>> import pyfasst.tools.plotTools 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)
pyfasst.tools.plotTools.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.

Inputs:

Parameters:
  • 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.

Outputs:

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

pyfasst.tools.plotTools.subplotsAudioModelSpecCompNimp(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

pyfasst.tools.plotTools.subplotsAudioModelSpecComps(model, 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

pyfasst.tools.plotTools.subplotsAudioModelSpecTW(model)[source]

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

model should be instance of (at least) FASST

SIGNALTOOLS

signalTools.py

gathers signal processing tools

pyfasst.tools.signalTools.f0detectionFunction(TFmatrix, 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

pyfasst.tools.signalTools.harmonicProd(TFmatrix, **kwargs)[source]

Computes the harmonic sum

pyfasst.tools.signalTools.harmonicSum(TFmatrix, **kwargs)[source]

Computes the harmonic sum

pyfasst.tools.signalTools.invHermMat2D(a_00, 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.

pyfasst.tools.signalTools.inv_herm_mat_2d(sigma_x_diag, sigma_x_off, verbose=False)[source]

Computes the inverse of 2D hermitian matrices.

Inputs

sigma_x_diag

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.

sigma_x_off

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)

Outputs

inv_sigma_x_diag

ndarray, 2 x shape(sigma_x_off)

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

inv_sigma_x_off

ndarray, shape(sigma_x_off)

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

det_sigma_x

ndarray, shape(sigma_x_off)

For each inversion, the determinant of the matrix.

Remarks

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.

pyfasst.tools.signalTools.medianFilter(inputArray, length=10)[source]

median filter

pyfasst.tools.signalTools.prinComp2D(X0, 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.

pyfasst.tools.signalTools.sortSpectrum(spectrum, 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.

UTILS

utils.py

Useful functions for (audio) signal processing

2013 Jean-Louis Durrieu

http://www.durrieu.ch

Content

pyfasst.tools.utils.db(val)[source]

db() db(positiveValue)

Returns the decibel value of the input positiveValue

pyfasst.tools.utils.hann(args)[source]

window = hann(args)

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

pyfasst.tools.utils.ident(energy)[source]

ident() : identity function, return the inputs unchanged

pyfasst.tools.utils.nextpow2(i)[source]

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

code taken from the website:

pyfasst.tools.utils.sinebell(lengthWindow)[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\]
pyfasst.tools.utils.sqrt_blackmanharris(M)[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