Commit d97dd891 authored by Steve Tjoa's avatar Steve Tjoa

pca; hpss; pitch transcription

parent 082d13d0
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -271,6 +271,7 @@ div#notebook {
<li><a href="zcr.html">Zero Crossing Rate</a> (<a href="zcr.ipynb">ipynb</a>)</li>
<li><a href="spectral_features.html">Spectral Features</a> (<a href="spectral_features.ipynb">ipynb</a>)</li>
<li><a href="mfcc.html">Mel-Frequency Cepstral Coefficients</a> (<a href="mfcc.ipynb">ipynb</a>)</li>
<li><a href="pitch_transcription_exercise.html">Pitch Transcription Exercise</a> (<a href="pitch_transcription_exercise.ipynb">ipynb</a>)</li>
</ol>
</div>
......@@ -293,9 +294,11 @@ div#notebook {
<ol>
<li><a href="basic_supervised_classification.html">Basic Supervised Classification</a> (<a href="basic_supervised_classification.ipynb">ipynb</a>)</li>
<li><a href="knn.html">K-Nearest Neighbor Classification</a> (<a href="knn.ipynb">ipynb</a>)</li>
<li><a href="cross_validation.html">Cross Validation</a> (<a href="cross_validation.ipynb">ipynb</a>)</li>
<li><a href="knn_instrument_classification.html">Exercise: K-Nearest Neighbor Instrument Classification</a> (<a href="knn_instrument_classification.ipynb">ipynb</a>)</li>
<li><a href="kmeans.html">K-Means Clustering</a> (<a href="kmeans.ipynb">ipynb</a>)</li>
<li><a href="kmeans_instrument_classification.html">Exercise: Unsupervised Instrument Classification using K-Means</a> (<a href="kmeans_instrument_classification.ipynb">ipynb</a>)</li>
<li><a href="notebooks/evaluation.ipynb">Evaluation</a></li>
</ol>
</div>
......@@ -306,7 +309,7 @@ div#notebook {
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Chapter-4:-Matrix-Factorization-and-Evaluation">Chapter 4: Matrix Factorization and Evaluation<a class="anchor-link" href="#Chapter-4:-Matrix-Factorization-and-Evaluation">&#182;</a></h2>
<h2 id="Chapter-4:-Matrix-Factorization">Chapter 4: Matrix Factorization<a class="anchor-link" href="#Chapter-4:-Matrix-Factorization">&#182;</a></h2>
</div>
</div>
</div>
......@@ -316,11 +319,11 @@ div#notebook {
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<ol>
<li><a href="pca.html">Principal Component Analysis</a> (<a href="pca.ipynb">ipynb</a>)</li>
<li><a href="nmf.html">Nonnegative Matrix Factorization</a> (<a href="nmf.ipynb">ipynb</a>)</li>
<li><a href="hpss.html">Harmonic-Percussive Source Separation</a> (<a href="hpss.ipynb">ipynb</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>
</ol>
</div>
......
......@@ -66,7 +66,8 @@
"1. [Basic Feature Extraction](basic_feature_extraction.html) ([ipynb](basic_feature_extraction.ipynb))\n",
"1. [Zero Crossing Rate](zcr.html) ([ipynb](zcr.ipynb))\n",
"1. [Spectral Features](spectral_features.html) ([ipynb](spectral_features.ipynb))\n",
"1. [Mel-Frequency Cepstral Coefficients](mfcc.html) ([ipynb](mfcc.ipynb))"
"1. [Mel-Frequency Cepstral Coefficients](mfcc.html) ([ipynb](mfcc.ipynb))\n",
"1. [Pitch Transcription Exercise](pitch_transcription_exercise.html) ([ipynb](pitch_transcription_exercise.ipynb))"
]
},
{
......@@ -82,27 +83,29 @@
"source": [
"1. [Basic Supervised Classification](basic_supervised_classification.html) ([ipynb](basic_supervised_classification.ipynb))\n",
"1. [K-Nearest Neighbor Classification](knn.html) ([ipynb](knn.ipynb))\n",
"1. [Cross Validation](cross_validation.html) ([ipynb](cross_validation.ipynb))\n",
"1. [Exercise: K-Nearest Neighbor Instrument Classification](knn_instrument_classification.html) ([ipynb](knn_instrument_classification.ipynb))\n",
"1. [K-Means Clustering](kmeans.html) ([ipynb](kmeans.ipynb))\n",
"1. [Exercise: Unsupervised Instrument Classification using K-Means](kmeans_instrument_classification.html) ([ipynb](kmeans_instrument_classification.ipynb))"
"1. [Exercise: Unsupervised Instrument Classification using K-Means](kmeans_instrument_classification.html) ([ipynb](kmeans_instrument_classification.ipynb))\n",
"1. [Evaluation](notebooks/evaluation.ipynb)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Chapter 4: Matrix Factorization and Evaluation"
"## Chapter 4: Matrix Factorization"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"1. [Principal Component Analysis](pca.html) ([ipynb](pca.ipynb))\n",
"1. [Nonnegative Matrix Factorization](nmf.html) ([ipynb](nmf.ipynb))\n",
"1. [Harmonic-Percussive Source Separation](hpss.html) ([ipynb](hpss.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)"
"1. [Classification of Separated Signals](notebooks/classify_separated_signals.ipynb)\n"
]
},
{
......
This diff is collapsed.
{
"metadata": {
"name": "",
"signature": "sha256:3a3278f7c6fb206a34581be477af529e901600f877d2eeeb0456448031912235"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Pitch Transcription Exercise"
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Load an audio file."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import essentia.standard as ess\n",
"loader = ess.MonoLoader(filename='../test/test.wav', sampleRate=44100)\n",
"signal_in = loader()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from IPython.display import Audio\n",
"#Audio(data=signal_in, rate=44100)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Find each note and its pitch."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def get_onsets(signal_in):\n",
" onset_times, onset_rate = ess.OnsetRate()(signal_in)\n",
" return onset_times"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"yin = ess.PitchYinFFT()\n",
"spectrum = ess.Spectrum()\n",
"\n",
"def get_pitch(segment):\n",
" if len(segment) < 4096:\n",
" N = len(segment) if len(segment) % 2 == 0 else len(segment) - 1\n",
" else:\n",
" N = 4096\n",
" pitch, pitch_conf = yin(spectrum(segment[:N]))\n",
" return pitch"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def generate_sine(pitch, n_duration):\n",
" #print midi, f0\n",
" n = arange(n_duration)\n",
" return 0.2*sin(2*pi*pitch*n/44100.0)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def transcribe_pitch(signal_in):\n",
" \n",
" signal_out = zeros(len(signal_in))\n",
" \n",
" # get onsets\n",
" onsets = get_onsets(signal_in)\n",
" \n",
" # get pitches\n",
" for i in range(len(onsets)-1):\n",
" n0 = int(onsets[i]*44100)\n",
" n1 = int(onsets[i+1]*44100)\n",
" pitch = get_pitch(signal_in[n0:n1])\n",
" \n",
" signal_out[n0:n1] = generate_sine(pitch, n1-n0)\n",
" \n",
" return signal_out\n",
" "
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": true,
"input": [
"signal_out = transcribe_pitch(signal_in)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Play the synthesized transcription."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import essentia\n",
"#Audio(data=signal_out, rate=44100)\n",
"signal_out = sum([signal_out, signal_in], axis=0)\n",
"ess.MonoWriter(filename='../test/out.wav')(essentia.array(signal_out))"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 8
}
],
"metadata": {}
}
]
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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