%% Modify Spectral Rolloff Threshold and Mel Spectrum Parameters
% Read in an audio signal.

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

%
% Create an audioFeatureExtractor object to extract the melSpectrum and spectralRolloffPoint. Specify ten bands for the mel spectrum and set the threshold for the rolloff point to 50% of the total energy.

aFE = audioFeatureExtractor("SampleRate",fs,"melSpectrum",true,"spectralRolloffPoint",true);
setExtractorParams(aFE,"melSpectrum","NumBands",10)
setExtractorParams(aFE,"spectralRolloffPoint","Threshold",0.5)

%
% Call extract and plot the results.

features = extract(aFE,audioIn);
idx = info(aFE);

surf(10*log10(features(:,idx.melSpectrum)))
title('Mel Spectrum')
plot(features(:,idx.spectralRolloffPoint))
title('Spectral Rolloff Point')

%
% To return individual audio feature extractors to their default values, call setExtractorParams without specifying any parameters to set.

setExtractorParams(aFE,"melSpectrum")
setExtractorParams(aFE,"spectralRolloffPoint")

%
% Call extract and plot the results.

features = extract(aFE,audioIn);
idx = info(aFE);

surf(10*log10(features(:,idx.melSpectrum)))
title('Mel Spectrum')
plot(features(:,idx.spectralRolloffPoint))
title('Spectral Rolloff Point')

% Copyright 2019 The MathWorks, Inc.