View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
STFT, MDCT and inverses. Onset and pitch detection

5.0 | 6 ratings Rate this file 31 Downloads (last 30 days) File Size: 8.83 KB File ID: #33451 Version: 1.8
image thumbnail

STFT, MDCT and inverses. Onset and pitch detection


Antoine Liutkus (view profile)


26 Oct 2011 (Updated )

Short Time Fourier Transform, MDCT and their inverse. CQT. Onset and Pitch detection.

| Watch this File

File Information

  Class name : Signal
handles basic Signal operations and transforms.
* wave loading
* STFT with any window and overlap ratio from 0 to 1
* MDCT and its inverse
* constant Q transform
* splitting into frames
* onset detection
* pitch detection
Main properties that are read/write
* s : signal
* windowLength (ms)
* nfft (samples)
* overlapRatio (>=0 and <1)
* S : stft data
Main properties that are read only :
* sLength : signal length
* nChans : number of channels
* nfftUtil : number of bins in the positive frequency domain
* framesPositions, nFrames : positions and number of frames
* sWin, sWeights : windowed data
example that produced the description figure :

% Create a Signal object from a wav file
s = Signal('linktomyfile.wav');

%set window length to 50ms
s.windowLength = 50;

%set window overlap to 75%
s.overlapRatio = 0.75;

%compute STFT

%display log-spectrogram
subplot 311
ylabel('frequency bin')
axis xy

%compute f0 between 200 and 500Hz
pitchs = s.mainPitch(200,500);

%display it
subplot 312
ylabel('f0 (Hz)')
grid on
title('f0 detection')

%Compute onsets that both appear and low and high frequencies
onsets = s.getOnsets(0,500).*s.getOnsets(6000,15000);

%display them
subplot 313
ylabel('onset presence')
grid on
title('onset detection')

Note that :
* all properties are automatically set relevantly in case of modifications. for example, when nfft is set, windowLength is changed accordingly
* the pitch detection algorithm is designed to work with a considerable amount of background superimposed to the lead signal. It should hence give reasonable results for popular music. Note that the lead signal ought to be more or less harmonic.

Required Products MATLAB
MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (18)
23 Feb 2017 Antoine Liutkus

Antoine Liutkus (view profile)

Hi Stavros, thanks for your comment. I don't know about updating, are there some things on this class not working with the new version ? cheers

Comment only


28 Dec 2016 Stavros Skouras

Hi Antoine,
Thank you for your valuable contribution.
Are you planning on updating for more recent Matlab versions (e.g. 2015-2016)?

Comment only
09 Oct 2015 Rebecca Burrell

09 Feb 2015 Supachan Traitruengsakul

22 Nov 2012 alexis benichoux

01 Sep 2012 Antoine Liutkus

Antoine Liutkus (view profile)

pitch detection function is back, along with MDCT and inverse

Comment only
19 Jul 2012 Antoine Liutkus

Antoine Liutkus (view profile)

The version currently uploaded does not have the pitch detection function due to a mistake I made. I'll update it shortly

Comment only
08 Mar 2012 Antoine Liutkus

Antoine Liutkus (view profile)

Hi, thanks for the comment/rating.

There are several possible reasons for your problem:
* the pitch detection system tries to find the most predominant and stable pitch within a background. It is mostly targeted for voice or harmonic signals. I have not really tested it for fundamental frequencies higher than 500-600Hz.
* If you have a knowledge that your fundamental frequency is likely to lie in some given bound, specify it the most tightly as you can. For example, looking for pitch from 100 to 500 may lead to catch the bass, whereas looking within [250-500] may catch the voice. This is due to the assumption that the pitch you are looking for has the higher energy.

If you provide me with your wavfile, I could give you some more hints

I hope this helps

cheers and good luck

Comment only
07 Mar 2012 fu

fu (view profile)

Hi, your sharing attracts me very much, but the value of F0 between 200 and 500 eludes me, why? and I find that if I use 1000 or larger number to replace 500, F0 will be constant, can you help me?

Comment only
07 Mar 2012 fu

fu (view profile)

02 Mar 2012 bounldes

Thanks for your kind answer!

Comment only
21 Feb 2012 Antoine Liutkus

Antoine Liutkus (view profile)

Hi, yes the onset detection algorithm is described in :
author = {C. Duxbury and J.P. Bello and M. Davies and M. Sandler},
title = {Complex Domain Onset Detection for Musical Signals},
booktitle = {In Proc. Digital Audio Effects Workshop (DAFx},
year = {2003},
address = {London, UK},
month = sep

Concerning the pitch detection, I developped it it, but unfortunately I still didn't took time to publish it somewhere..

cheers, thanks for your interest

Comment only
21 Feb 2012 bounldes

Are there some papers about it?If you have it,please give me a website.Thank you very much!

Comment only
22 Nov 2011 bounldes

Thank you.My matlab version is 7.1.I will run it again with 2008a.

Comment only
21 Nov 2011 Antoine Liutkus

Antoine Liutkus (view profile)

Hello, it seems to me that it must be a problem of Matlab version. What version do you use ? I think that object capabilities from this code come with 2008a

Comment only
20 Nov 2011 bounldes

There's a error when I use "s = Signal('myfile.wav')".
Error is as followed´╝Ü
??? Error: File: Signal.m Line: 62 Column: 9
Function definitions are not permitted at the prompt or in scripts.

Comment only
27 Oct 2011 1.1

fast detection of pitch / main melody added. Designed to be robust to the (strong) presence of a background, and should hence work relatively well for pop music. Note that the lead instrument ought to be harmonic.

27 Oct 2011 1.4

bugfix in the onset detection for multichannel signals

28 Oct 2011 1.5

Added an example that computes STFT, onset and main melody in the description

26 Jun 2012 1.7

This new version includes
* MDCT and its inverse
* Conqtant-Q transforms (implemented by Jacques Prado)

27 Aug 2012 1.8

This update brings back the pitch detection function that I removed by mistake when incorporating the MDCT/inverse MDCT

Contact us