Commit ecf31cac authored by Steve Tjoa's avatar Steve Tjoa

added exercise: knn instrument classification; spectral features

parent fcc19395
{
"metadata": {
"name": "",
"signature": "sha256:bb2e49be0f0cc1f2f28b5e822902210b4d295112f04bd4c301dc435f7be7ebf4"
"signature": "sha256:acdbb21211e509f92197f1505242fdab716b14fe5434b6af6ac4f453c4e7606c"
},
"nbformat": 3,
"nbformat_minor": 0,
......@@ -20,30 +20,415 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Read a drum loop.\n",
"This is an *exercise* notebook. It's a playground for your Python code. Feel free to write and execute your code without fear.\n",
"\n",
"Detect onsets. Save the onset times.\n",
"When you see a cell that looks like this:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"plot?"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"that is a cue to use a particular command, in this case, `plot`. Run the cell to see documentation for that command. (To quickly close the Help window, press `q`.) \n",
"\n",
"At each onset, extract one 100-ms segment from the audio signal.\n",
"For more documentation, visit the links in the Help menu above. Also see the other notebooks; all the exercises here are covered somewhere else in separate notebooks."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This exercise is loosely based upon \"Lab 1\" from previous MIR workshops ([2010](https://ccrma.stanford.edu/workshops/mir2010/Lab1_2010.pdf))."
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Goals"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"1. Extract spectral features from an audio signal.\n",
"2. Train a K-Nearest Neighbor classifier.\n",
"3. Use the classifier to classify beats in a drum loop."
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Step 1: Retrieve Audio, Detect Onsets, and Segment"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Follow the same steps here.](feature_sonification.ipynb#Step-1:-Retrieve-Audio)\n",
"\n",
"For each segment, compute the MFCCs.\n",
"1. Download the file `simpleLoop.wav` onto your local machine.\n",
"1. Save the audio signal into an array.\n",
"1. Find the times, in seconds, when onsets occur in the audio signal.\n",
"1. Save into an array, `segments`, 100-ms segments beginning at each onset."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import urllib\n",
"url = 'https://ccrma.stanford.edu/workshops/mir2014/audio/simpleLoop.wav'\n",
"urllib.urlretrieve?"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 16
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from essentia.standard import MonoLoader\n",
"MonoLoader?"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 17
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"fs = 44100\n",
"frame_sz = int(0.1*fs)\n",
"import essentia\n",
"segments = essentia.array([rand(frame_sz), rand(frame_sz)]) # placeholder"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 18
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Step 2: Extract MFCCs"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For each segment, compute the MFCCs."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from essentia.standard import MFCC, Spectrum, Windowing\n",
"hamming_window = Windowing(type='hamming')\n",
"spectrum = Spectrum() # we just want the magnitude spectrum\n",
"mfcc = MFCC()\n",
"\n",
"Read a training set of drum samples. For each test signal, extract MFCCs, and use `mean` to obtain one MFCC vector per signal.\n",
"mfccs = array([mfcc(spectrum(hamming_window(frame)))[1]\n",
" for frame in segments])\n",
"\n",
"Train a K-NN classifier using test signals. When training, discard the 0th MFCC coefficient, because it only represents the energy in the frame and does not add any discriminative power. \n",
"imshow(mfccs[:,1:].T, origin='lower', aspect='auto', interpolation='nearest') # Ignore the 0th MFCC\n",
"yticks(range(12), range(1,13)) # Ignore the 0th MFCC\n",
"ylabel('MFCC Coefficient Index')\n",
"xlabel('Segment Index')"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 15,
"text": [
"<matplotlib.text.Text at 0x3968210>"
]
},
{
"metadata": {},
"output_type": "display_data",
"png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEICAYAAABWJCMKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XtYVHUeP/D3ARGTm3ckwaUkVGCCAYI0L5SCoeGjJrp4\nw9R0c1erbfupuz3PkuVP2iyVXDfTBDXTVTeVxPypraBJeEVttdRISrwgRshN4+L39wcxOsI4zOHM\nmYPzfj3PPM/MmTPfz8fjPPPhnO/5fr+SEEKAiIjsjoOtEyAiIttgASAislMsAEREdooFgIjITrEA\nEBHZqVa2TqCeJEm2ToGIqEWSezOnZgoAACSK5bZO4YFxIikDIUnDbJ3GA4HHUlk8nspaI82U/Vle\nAiIislMsAEREdooF4AHVNeoxW6fwwOCxVBaPp3awADygukb52zqFBwaPpbJ4PLVD8QIwZcoUeHp6\nQqfTGba9/vrr6N27N4KDgzFq1CjcuHFD6bBERGQhxQvACy+8gF27dhlti4mJwenTp3Hy5En4+/tj\n4cKFSoclIiILKV4A+vfvj/bt2xtti46OhoNDXajIyEgUFBQoHZaIiCyk+jiA1atXIyEhodH3TiRl\nGJ53jXqM1wqJiO5xNfMcrmaeV6QtVQvAggUL0Lp1a4wbN67R9zk4hIjo/rpG+Rv9cXzyzYz77H1/\nqhWAtLQ07Ny5E19++aVaIYmI6D5UKQC7du3Cu+++i6ysLLRp00aNkEREZIbincAJCQno27cvzp49\nCx8fH6xevRqzZs1CeXk5oqOjodfrMXOm/LkriIhIGZJW1gSWJImTwRERWWiNNFP2bKAcCUxEZKdY\nAIiI7BQLABGRnWIBICKyU5rqBBabbJ0FkWm3hto6A6KGHnKVvyQkzwCIiOwUCwARkZ1iASAislMs\nAEREdooFgIjITqmyJOTmzZsRGBgIR0dHHD9+XOmQREQkgypLQup0OmzduhUDBgxQOhwREcmk+HTQ\n/fv3R35+vtG2Xr16KR2GiIiaSfUlIe8nafOd51EBQFSg7X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YtWwzbT506dd/Purm5GSYptJQkSYiMjERWVhaKi4tR\nXV2NzZs3G96PiYlBSkqK4fWJEycA1E3wtWvXLhw/fhyLFi1Cfn6+rPhEd2MBIE0pLy/H5MmTERgY\niODgYHz33XdISkqCk5MTtmzZgjlz5iAkJAR6vR5ff/01AODjjz/Giy++CL1ej8rKSnh4eABouM7E\nvc/rX69fvx4ff/wxQkJCEBQUhPT0dJOfAYDg4GA4OjoiJCSk0U7g+v1MrXPRtWtXJCUloU+fPujX\nrx8CAwMN76WkpODo0aMIDg5GYGAgPvroI1RVVWH69OlITU2Fl5cX3nvvPUyZMsXyg0t0D04GRy1e\nRUUFXFzeQiFxAAAAW0lEQVRcAADJyckoLCzE4sWLbZwVkfaxD4BavIyMDCxcuBA1NTXw9fVFWlqa\nrVMiahF4BkBEZKfYB0BEZKdYAIiI7BQLABGRnWIBICKyUywARER2igWAiMhO/X+rhe0nJCc9jQAA\nAABJRU5ErkJggg==\n",
"text": [
"<matplotlib.figure.Figure at 0x395f350>"
]
}
],
"prompt_number": 15
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Step 3: Train K-NN Classifier"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from urlparse import urljoin\n",
"\n",
"kick_files = ['Bass_Drum_%02d_V01.WAV' % n\n",
" for n in range(1,11)]\n",
"\n",
"\n",
"snare_files = ['Bass_Drum_%02d_V01.WAV' % n\n",
" for n in range(1,11)]\n",
"\n",
"For each segment in the test audio signal, feed it into the trained K-NN classifier, and save the label.\n",
"\n",
"Play a \"beep\" for each detected kick drum.\n",
"for kick_file in kick_files:\n",
" url = urljoin('https://ccrma.stanford.edu/workshops/mir2014/audio/drum%%20samples/kicks/', kick_file)\n",
" urllib.urlretrieve(url, filename=kick_file)\n",
"#kicks = [MonoLoader(filename=filename) for filename in kick_files]\n",
"#snares = [MonoLoader(filename=filename) for filename in kick_files]\n",
"\n",
"Play a \"beep\" for each detected snare drum.\n",
"%ls"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"https://ccrma.stanford.edu/workshops/mir2014/audio/drum%%20samples/kicks/Bass_Drum_01_V01.WAV\n",
"https://ccrma.stanford.edu/workshops/mir2014/audio/drum%%20samples/kicks/Bass_Drum_02_V01.WAV"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"https://ccrma.stanford.edu/workshops/mir2014/audio/drum%%20samples/kicks/Bass_Drum_03_V01.WAV"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"https://ccrma.stanford.edu/workshops/mir2014/audio/drum%%20samples/kicks/Bass_Drum_04_V01.WAV"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"https://ccrma.stanford.edu/workshops/mir2014/audio/drum%%20samples/kicks/Bass_Drum_05_V01.WAV"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"https://ccrma.stanford.edu/workshops/mir2014/audio/drum%%20samples/kicks/Bass_Drum_06_V01.WAV"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"https://ccrma.stanford.edu/workshops/mir2014/audio/drum%%20samples/kicks/Bass_Drum_07_V01.WAV"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"https://ccrma.stanford.edu/workshops/mir2014/audio/drum%%20samples/kicks/Bass_Drum_08_V01.WAV"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"https://ccrma.stanford.edu/workshops/mir2014/audio/drum%%20samples/kicks/Bass_Drum_09_V01.WAV"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"https://ccrma.stanford.edu/workshops/mir2014/audio/drum%%20samples/kicks/Bass_Drum_10_V01.WAV"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"Bass_Drum_01_V01.WAV Bass_Drum_04_V01.WAV Bass_Drum_07_V01.WAV Bass_Drum_10_V01.WAV nmf_source_separation.ipynb\r\n",
"Bass_Drum_02_V01.WAV Bass_Drum_05_V01.WAV Bass_Drum_08_V01.WAV feature_sonification.ipynb\r\n",
"Bass_Drum_03_V01.WAV Bass_Drum_06_V01.WAV Bass_Drum_09_V01.WAV knn_instrument_classification.ipynb\r\n"
]
}
],
"prompt_number": 32
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Step 4: Run the Classifier"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Step 5: Sonify the Classifier Output"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Play a \"beep\" for each detected kick drum."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from essentia.standard import AudioOnsetsMarker\n",
"AudioOnsetsMarker?"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Play a \"beep\" for each detected snare drum."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from essentia.standard import AudioOnsetsMarker\n",
"AudioOnsetsMarker?"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Read a training set of drum samples. For each test signal, extract MFCCs, and use `mean` to obtain one MFCC vector per signal.\n",
"\n",
"Train a K-NN classifier using test signals. When training, discard the 0th MFCC coefficient, because it only represents the energy in the frame and does not add any discriminative power. \n",
"\n",
"In addition to the MFCCs, extract the delta-MFCCs. Re-train the classifier, and re-run the classifier over the test audio signal. Do the results change?\n",
"\n",
"Repeat for other audio files."
"\n",
"For each segment in the test audio signal, feed it into the trained K-NN classifier, and save the label."
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Bonus"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In addition to the MFCCs, extract the following features:\n",
"\n",
"- spectral centroid\n",
"- spectral spread\n",
"- spectral skewness\n",
"- spectral kurtosis. "
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from essentia.standard import CentralMoments, DistributionShape\n",
"DistributionShape?"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Re-train the classifier, and re-run the classifier over the test audio signal. Do the results change?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Repeat the steps above for the following audio files:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"url = 'https://ccrma.stanford.edu/workshops/mir2014/audio/CongaGroove-mono.wav'\n",
"url = 'https://ccrma.stanford.edu/workshops/mir2014/audio/125BOUNC-mono.WAV'"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
}
],
"metadata": {}
......
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