{
 "metadata": {
  "name": "",
  "signature": "sha256:a92ad530ab974142e47c4d56f0ca34ea9aa24ae9ca7b73a6baa051e8a319a116"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Exercise: Source Separation using NMF"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "\n",
      "Lab 4\n",
      "=====\n",
      "\n",
      "Summary:\n",
      "\n",
      "1.  Separate sources.\n",
      "2.  Separate noisy sources.\n",
      "3.  Classify separated sources.\n",
      "\n",
      "Matlab Programming Tips\n",
      "*   Pressing the up and down arrows let you scroll through command history.\n",
      "*   A semicolon at the end of a line simply means ``suppress output''.\n",
      "*   Type `help <command>` for instant documentation. For example, `help wavread`, `help plot`, `help sound`. Use `help` liberally!\n",
      "\n",
      "\n",
      "Section 1: Source Separation\n",
      "----------------------------\n",
      "\n",
      "1.  In Matlab: Select File > Set Path. \n",
      "\n",
      "Select \"Add with Subfolders\". \n",
      "\n",
      "Select `/usr/ccrma/courses/mir2011/lab3skt`.\n",
      "\n",
      "2.  As in Lab 1, load the file, listen to it, and plot it.\n",
      "\n",
      "        [x, fs] = wavread('simpleLoop.wav');\n",
      "        sound(x, fs)\n",
      "        t = (0:length(x)-1)/fs;\n",
      "        plot(t, x)\n",
      "        xlabel('Time (seconds)')\n",
      "\n",
      "3.  Compute and plot a short-time Fourier transform, i.e., the Fourier transform over consecutive frames of the signal.\n",
      "\n",
      "        frame_size = 0.100;\n",
      "        hop = 0.050;\n",
      "        X = parsesig(x, fs, frame_size, hop);\n",
      "        imagesc(abs(X(200:-1:1,:)))\n",
      "\n",
      "    Type `help parsesig`, `help imagesc`, and `help abs` for more information.\n",
      "\n",
      "    This step gives you some visual intuition about how sounds (might) overlap.\n",
      "\n",
      "4.  Let's separate sources!\n",
      "\n",
      "        K = 2;\n",
      "        [y, W, H] = sourcesep(x, fs, K);\n",
      "\n",
      "    Type `help sourcesep` for more information.\n",
      "\n",
      "5.  Plot and listen to the separated signals.\n",
      "\n",
      "        plot(t, y)\n",
      "        xlabel('Time (seconds)')\n",
      "        legend('Signal 1', 'Signal 2')\n",
      "        sound(y(:,1), fs)\n",
      "        sound(y(:,2), fs)\n",
      "\n",
      "    Feel free to replace `Signal 1` and `Signal 2` with `Kick` and `Snare` (depending upon which is which).   \n",
      "\n",
      "6.  Plot the outputs from NMF.\n",
      "\n",
      "        figure\n",
      "        plot(W(1:200,:))\n",
      "        legend('Signal 1', 'Signal 2')\n",
      "        figure\n",
      "        plot(H')\n",
      "        legend('Signal 1', 'Signal 2')\n",
      "\n",
      "    What do you observe from `W` and `H`? \n",
      "\n",
      "    Does it agree with the sounds you heard?\n",
      "\n",
      "7.  Repeat the earlier steps for different audio files.\n",
      "\n",
      "        *  `125BOUNC-mono.WAV`\n",
      "        *  `58BPM.WAV` \n",
      "        *  `CongaGroove-mono.wav`\n",
      "        *  `Cstrum chord_mono.wav`\n",
      "\n",
      "    ... and more.\n",
      "\n",
      "8.  Experiment with different values for the number of sources, `K`. \n",
      "\n",
      "    Where does this separation method succeed? \n",
      "\n",
      "    Where does it fail?\n",
      "\n",
      "\n",
      "Section 2: Noise Robustness\n",
      "---------------------------\n",
      "\n",
      "1.  Begin with `simpleLoop.wav`. Then try others.\n",
      "\n",
      "    Add noise to the input signal, plot, and listen.\n",
      "\n",
      "        xn = x + 0.01*randn(length(x),1);\n",
      "        plot(t, xn)\n",
      "        sound(xn, fs)\n",
      "\n",
      "2.  Separate, plot, and listen.\n",
      "\n",
      "        [yn, Wn, Hn] = sourcesep(xn, fs, K);\n",
      "        plot(t, yn)\n",
      "        sound(yn(:,1), fs)\n",
      "        sound(yn(:,2), fs)\n",
      "        \n",
      "    How robust to noise is this separation method? \n",
      "\n",
      "    Compared to the noisy input signal, how much noise is left in the output signals? \n",
      "\n",
      "    Which output contains more noise? Why?\n"
     ]
    }
   ],
   "metadata": {}
  }
 ]
}