%% Estimate Pitch of Musical Signal Using Nondefault Parameters
% Load an audio file of the introduction to Für Elise and the sample rate of the audio. Call the pitch function using the pitch estimate filter (PEF), a search range from 50 Hz to 800 Hz, a window length of 80 ms, and an overlap of 50 ms. Plot the results and listen to the song to verify the fundamental frequency estimates returned by the pitch function.

load FurElise.mat song fs

[f0,loc] = pitch(song,fs, ...
    'Method','PEF', ...
    'Range',[50 800], ...
    'WindowLength',round(fs*0.08), ...
    'OverlapLength',round(fs*0.05));

t = loc/fs;
plot(t,f0)
ylabel('Pitch (Hz)')
xlabel('Time (s)')
sound(song,fs)

% Copyright 2012 The MathWorks, Inc.