In [ ]:
import numpy, scipy, matplotlib.pyplot as plt, librosa, urllib, IPython.display

Exercise: Source Separation using NMF

Goals:

  1. Separate sources using NMF.
  2. Analyze and classify separated sources.

Download an audio file:


In [ ]:
urllib.urlretrieve?

Load an audio file:


In [ ]:
librosa.load?

Plot the spectrogram:


In [ ]:
librosa.stft?

In [ ]:
librosa.logamplitude?

In [ ]:
librosa.display.specshow?

Use NMF to decompose the spectrogram:


In [ ]:
librosa.decompose.decompose?

Plot the spectral profiles and temporal activations of each component individually:


In [ ]:
plt.subplot?

Use the inverse STFT to synthesize the separated sources. (librosa.istft expects a full, complex-valued spectrogram. Therefore, you will need to include the phase of the original spectrogram in your reconstruction. See the notebook on NMF for more details.)


In [ ]:
librosa.istft?

Use the reconstructed outputs as inputs into the kick/snare classifier that you created in an earlier exercise. Observe the results; are you able to automatically classify the separated sources?

For Further Exploration

Use different audio files.

Alter the rank of the decomposition, n_components. What happens when n_components is too large? too small?

NMF is a useful preprocessor for MIR tasks such as music transcription. Using the steps above, build your own simple transcription system that returns a sequence of note events, [(onset time, class label, volume/gain)...].