File Exchange

image thumbnail

STFT, MDCT and inverses. Onset and pitch detection

version 1.8 (8.83 KB) by

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

40 Downloads

Updated

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
s.STFT;

%display log-spectrogram
figure(1)
clf
subplot 311
imagesc(10*log10(abs(s.S(1:s.nfftUtil,:,1)).^2));
xlabel('frame')
ylabel('frequency bin')
axis xy
title('spectrogram')

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

%display it
subplot 312
plot(pitchs)
xlabel('frame')
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
plot(onsets)
xlabel('frame')
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.

Comments and Ratings (18)

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

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

Antoine Liutkus

Antoine Liutkus (view profile)

pitch detection function is back, along with MDCT and inverse

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

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

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?

fu

fu (view profile)

bounldes

Thanks for your kind answer!

Antoine Liutkus

Antoine Liutkus (view profile)

Hi, yes the onset detection algorithm is described in :
@INPROCEEDINGS{onsetdetection,
  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

bounldes

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

bounldes

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

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

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.

Updates

1.8

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

1.7

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

1.5

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

1.4

bugfix in the onset detection for multichannel signals

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.

MATLAB Release
MATLAB 7.10 (R2010a)

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

» Watch video