Commit a12e71e7 authored by Steve Tjoa's avatar Steve Tjoa

nmf exercise

parent ac945eee
{
"metadata": {
"name": "",
"signature": "sha256:4dadf70135ac19f86b46054f55c35735380ff80be8d92673ea1a71fe1779641e"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Exercise: Source Separation using NMF"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Goals:\n",
"\n",
"1. Separate sources using NMF.\n",
"2. Analyze and classify separated sources."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Load an audio file:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import urllib\n",
"from urlparse import urljoin\n",
"filename = 'simpleLoop.wav'\n",
"#filename = 'CongaGroove-mono.wav'\n",
"#filename = '125BOUNC-mono.WAV'\n",
"url = urljoin('https://ccrma.stanford.edu/workshops/mir2014/audio/', filename)\n",
"print url\n",
"urllib.urlretrieve(url, filename=filename)\n",
"\n",
"from essentia.standard import MonoLoader\n",
"fs = 44100.0\n",
"MonoLoader?"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"https://ccrma.stanford.edu/workshops/mir2014/audio/simpleLoop.wav\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot the spectrogram:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import librosa\n",
"librosa.stft?\n",
"librosa.display.specshow?"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use NMF to decompose the spectrogram:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from sklearn.decomposition import NMF\n",
"NMF?"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot the decomposed matrices:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use the inverse STFT to synthesize the separated sources:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"librosa.istft?"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use the columns of the matrix, $W$, otherwise known as *spectral atoms*, 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?"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Bonus"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use different audio files."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Alter the rank of the decomposition, `n_components`. What happens when `n_components` is too large? too small?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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)...]`."
]
}
],
"metadata": {}
}
]
}
\ No newline at end of file
......@@ -314,7 +314,7 @@ div#notebook {
<div class="text_cell_render border-box-sizing rendered_html">
<ol>
<li><a href="nmf.html">Nonnegative Matrix Factorization</a> (<a href="nmf.ipynb">ipynb</a>)</li>
<li><a href="exercises/nmf_source_separation.ipynb">Exercise: Source Separation using NMF</a></li>
<li><a href="nmf_source_separation.html">Exercise: Source Separation using NMF</a> (<a href="nmf_source_separation.ipynb">ipynb</a>)</li>
<li><a href="notebooks/classify_separated_signals.ipynb">Classification of Separated Signals</a></li>
<li><a href="notebooks/cross_validation.ipynb">Cross Validation</a></li>
<li><a href="notebooks/evaluation.ipynb">Evaluation</a></li>
......
......@@ -96,7 +96,7 @@
"metadata": {},
"source": [
"1. [Nonnegative Matrix Factorization](nmf.html) ([ipynb](nmf.ipynb))\n",
"1. [Exercise: Source Separation using NMF](exercises/nmf_source_separation.ipynb)\n",
"1. [Exercise: Source Separation using NMF](nmf_source_separation.html) ([ipynb](nmf_source_separation.ipynb))\n",
"1. [Classification of Separated Signals](notebooks/classify_separated_signals.ipynb)\n",
"1. [Cross Validation](notebooks/cross_validation.ipynb)\n",
"1. [Evaluation](notebooks/evaluation.ipynb)"
......
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy, scipy, matplotlib.pyplot as plt, librosa, urllib, IPython.display"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[&larr; Back to Index](index.html)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exercise: Source Separation using NMF"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Goals:\n",
"\n",
"1. Separate sources using NMF.\n",
"2. Analyze and classify separated sources."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Download an audio file:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"urllib.urlretrieve?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Load an audio file:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"librosa.load?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot the spectrogram:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"librosa.stft?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"librosa.logamplitude?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"librosa.display.specshow?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use NMF to decompose the spectrogram:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"librosa.decompose.decompose?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot the spectral profiles and temporal activations of each component individually:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"plt.subplot?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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](nmf.html) for more details.)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"librosa.istft?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## For Further Exploration"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use different audio files."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Alter the rank of the decomposition, `n_components`. What happens when `n_components` is too large? too small?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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)...]`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[&larr; Back to Index](index.html)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment