STFT, MDCT and inverses. Onset and pitch detection

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


Updated 27 Aug 2012

View License

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.

Cite As

Antoine Liutkus (2023). STFT, MDCT and inverses. Onset and pitch detection (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

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

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

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

bugfix in the onset detection for multichannel signals

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.