This repository contains a MATLAB example for Onset Detection using a Convolutional Neural Network (CNN). The repository contains a matconvnet distribution for training/evaluation.
For use, please download the training and testing databases and install them in a folder in your local PC.
For evaluating, several learned models are included in the learned_models folder. To have a look, run onset_test.m
The spectrograms of the audio files are first extracted at different time resolutions.
![]() |
|---|
| Input spectrograms. From top to bottom: with 23ms, 46ms and 93ms time resolution. |
The spectrograms are then filtered using a mel-spaced frequency filter bank of 80 filters, so to reduce redundancy at the time of learning.
![]() |
|---|
| Mel-filtered Spectrum. |
This gives an input for the CNN which is comprised of three channels, each of which describes a different temporal resolution, but describing the same frequency components. A possible depiction would contain the same number of frequency bands, but smeared in the time domain. This effect is represented in the next picture, which shows an RGB representation of such an input.
![]() |
|---|
| An RGB representation of the input for the network. |
However, the CNN will look for the relationships and differences in the input space, finding relationships in both time and frequency.
The model that is used in the example is a 10-layer convolutional network with different filter sizes and a rectifying units attached at the end of each convolutional layer. The label which was applied for training is an onset detection function.
The output of the CNN is then post-processed to deliver a generated onset detection function, which is shown below.
![]() |
|---|
| Generated onset detection function and its ground truth. |
The peaks of the output signal, shown in the picture as a line plot, show a correct identification of the onsets which play along with the audio file. Notice that the second onset is correctly generalized. This represents and improvement with respect to the algorithm used to generate the ground truth labels. Notice, also, some issues with time alignment in the output signal.
A training script is included in onset_train.m. Optionally, there is the option to use the mel-filtered spectral flux, which exploits the relationships between subsequent time bins in the spectrogram.
This implementation is loosely based on: [1]. Jan Schlüter and Sebastian Böck. "Improved Musical Onset Detection with Convolutional Neural Networks." 2014 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP). IEEE, 2014.
If you use this code or data in your research, please cite:
- C. de Obaldía, Udo Zölzer: "Convolutional Neural Networks for Spectrogram Segmentation of Whale Calls", 10th International Conference on Ecological Informatics, 24–28 September 2018, Jena, Germany.
@inproceedings{deobaldia2018whale,
author = {de Obaldía, C. and Zölzer, Udo},
title = {Convolutional Neural Networks for Spectrogram Segmentation of Whale Calls},
booktitle = {10th International Conference on Ecological Informatics},
year = {2018},
month = {September},
address = {Jena, Germany}
}For more information on matconvnet visit its official repository



