Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
musicinformationretrieval-com
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
A.S.
musicinformationretrieval-com
Commits
d831c98d
Commit
d831c98d
authored
Jun 21, 2014
by
Leigh Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Now uses Centroid calculation, retained the old calculation
parent
22d94ff4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
14 deletions
+64
-14
spectral_features.ipynb
notebooks/spectral_features.ipynb
+64
-14
No files found.
notebooks/spectral_features.ipynb
View file @
d831c98d
{
"metadata": {
"name": "",
"signature": "sha256:
620336a15b319b335fbc26f830d5f6b5507392500835305cf3d7fd579934ff6e
"
"signature": "sha256:
b4779de8997f272445c84c210f3048f03d085c9dd003e7005e82662dc0906c79
"
},
"nbformat": 3,
"nbformat_minor": 0,
...
...
@@ -211,11 +211,12 @@
"cell_type": "code",
"collapsed": false,
"input": [
"from essentia.standard import ZeroCrossingRate, CentralMoments, Spectrum, Windowing\n",
"from essentia.standard import ZeroCrossingRate, CentralMoments, Spectrum, Windowing
, Centroid
\n",
"zcr = ZeroCrossingRate()\n",
"hamming_window = Windowing(type = 'hamming') # we need to window the frame to avoid FFT artifacts.\n",
"spectrum = Spectrum()\n",
"central_moments = CentralMoments()\n",
"spectral_centroid = Centroid()\n",
"\n",
"frame_size = 0.100 * sample_rate # 100ms\n",
"file_index = 0 # to process a single file, this will be your file loop iteration\n",
...
...
@@ -223,15 +224,65 @@
"current_frame = audio[0 : frame_size]\n",
"features_snare[file_index, 0] = zcr(current_frame)\n",
"spectral_magnitude = spectrum(hamming_window(current_frame))\n",
"centroid = spectral_centroid(spectral_magnitude)\n",
"\n",
"# Spectral centroid in normalised bandwidth (i.e fraction of Nyquist frequency).\n",
"centroid"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 41,
"text": [
"0.22001729905605316"
]
}
],
"prompt_number": 41
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Centroid in spectral coefficient indices.\n",
"centroid * spectral_magnitude.shape[0]"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 42,
"text": [
"485.3581617176533"
]
}
],
"prompt_number": 42
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Essentia can make things seem a little magical, here is how the centroid would be calculated:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Normalize the spectral magnitude\n",
"norm_spectral_mag = spectral_magnitude / np.sum(spectral_magnitude)
;
\n",
"norm_spectral_mag = spectral_magnitude / np.sum(spectral_magnitude)\n",
"# Make index vector\n",
"indices = np.arange(
spectral_magnitude
.shape[0])\n",
"indices = np.arange(
norm_spectral_mag
.shape[0])\n",
"\n",
"# Centroid, in spectral coefficient indices.\n",
"centroid = np.sum(norm_spectral_mag * indices)\n",
"centroid"
"
my_
centroid = np.sum(norm_spectral_mag * indices)\n",
"
my_
centroid"
],
"language": "python",
"metadata": {},
...
...
@@ -239,13 +290,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number":
23
,
"prompt_number":
50
,
"text": [
"485.13728477961195"
]
}
],
"prompt_number":
23
"prompt_number":
50
},
{
"cell_type": "code",
...
...
@@ -266,13 +317,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number":
32
,
"prompt_number":
51
,
"text": [
"array([ 1. , 0. , 0.04079479, 0.00723291, 0.00497805], dtype=float32)"
]
}
],
"prompt_number":
32
"prompt_number":
51
},
{
"cell_type": "code",
...
...
@@ -289,14 +340,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number":
34
,
"prompt_number":
52
,
"text": [
"array([ 1.29251704e-01, 4.85137285e+02, 4.07947935e-02,\n",
" 7.23291235e-03, 4.97804629e-03])"
"array([ 0.1292517 , 0.2200173 , 0.04079479, 0.00723291, 0.00497805])"
]
}
],
"prompt_number":
34
"prompt_number":
52
},
{
"cell_type": "markdown",
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment