%% Specify Nondefault Parameters
% Read in an audio file.

[audioIn,fs] = audioread('Counting-16-44p1-mono-15secs.wav');

%
% Calculate the centroid of the power spectrum over time. Calculate the centroid for 50 ms Hamming windows of data with 25 ms overlap. Use the range from 62.5 Hz to fs/2 for the centroid calculation. Plot the results.

centroid = spectralCentroid(audioIn,fs, ...
                            'Window',hamming(round(0.05*fs)), ...
                            'OverlapLength',round(0.025*fs), ...
                            'Range',[62.5,fs/2]);
                        
t = linspace(0,size(audioIn,1)/fs,size(centroid,1));
plot(t,centroid)
xlabel('Time (s)')
ylabel('Centroid (Hz)')

%
% Copyright 2018 The MathWorks, Inc.