I am totally new in Matlab. Can anyone please explain in details how I can extract pitch contour of a speech? I would like to observe how the speaker's pitch varies during his speech to know whether he is speaking in a flat tone.


I recommend computing the spectrogram of the audio recording using the MATLAB function spectrogram().

The fourth return value (ps in the documentation page linked above) of the spectrogram() function is a matrix of the power spectral density estimates. This can be used to investigate how much energy there is at each frequency at each time instant. A tone of constant frequency results in a straight horizontal line, a short impulse in a vertical one. Most signals have much more complex spectrograms.

Looking at the matrix as a two-dimensional image reveals a lot about the signal at hand. As the range of coefficient values in the spectrogram of an audio signal is usually quite large, it is a good idea to compress this range by computing the logarithm before plotting. The following code snippet will hopefully yield the image you had in mind - with x your (single channel) audio signal and fs the sampling rate:

L_block = 4096;
L_overlap = floor(L_block/2);
L_DFT = L_block;
[~,f,t,ps] = spectrogram(x, ...
    hann(L_block, 'periodic'), ...
    L_overlap, ...
    L_DFT, ...
    fs, ...
imagesc(t, f, 10*log10(ps));
axis xy;
ylim([20 600]); % zoom to the fundamental frequency range
xlabel('Time in s');
ylabel('Frequency in Hz');

To find out how much the pitch of the speaker varies, analyze the horizontal lines that you see. Experiment with the block length (L_block), overlap length (L_overlap) and the window (here: hann()) to obtain optimum results.

By the way: Here is another example on how to compute and display the spectrogram in MATLAB.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.