%% Get MFCC Data for Speech Segment
% Extract the mel frequency cepstral coefficients and the log energy values of segments in a speech file. Return delta, the difference between current and the previous cepstral coefficients, and deltaDelta, the difference between the current and the previous delta values. The log energy value the object computes can prepend the coefficients vector or replace the first element of the coefficients vector. This is done based on whether you set the LogEnergy property of the cepstralFeatureExtractor object to 'Replace' or 'Append'.
%
% Read an audio signal from 'Counting-16-44p1-mono-15secs.wav' file. Extract a 40 ms segment from the audio data. Create a cepstralFeatureExtractor object. The cepstral coefficients computed by the default object are the mel frequency coefficients. In addition, the object computes the log energy, delta, and delta-delta values of the audio segment.

[audioFile, fs] = audioread('Counting-16-44p1-mono-15secs.wav');
duration = round(0.04*fs); % 40 ms
audioSegment = audioFile(40000:40000+duration-1);
cepFeatures = cepstralFeatureExtractor('SampleRate',fs)

% The LogEnergy property is set to 'Append'. The first element in the coefficients vector is the log energy value and the remaining elements are the 13 cepstral coefficients computed by the object. The number of cepstral coefficients is determined by the value you specify in the NumCoeffs property.

[coeffs,delta,deltaDelta] = cepFeatures(audioSegment)

%
% The initial values for the delta and deltaDelta arrays are always zero. Consider another 40 ms audio segment in the file and extract the cepstral features from this segment.

audioSegmentTwo = audioFile(5820:5820+duration-1);
[coeffsTwo,deltaTwo,deltaDeltaTwo] = cepFeatures(audioSegmentTwo)

%
% Verify that the difference between coeffsTwo and coeffs vectors equals deltaTwo.

isequal(coeffsTwo-coeffs,deltaTwo)

%
% Verify that the difference between deltaTwo and delta vectors equals deltaDeltaTwo.

isequal(deltaTwo-delta,deltaDeltaTwo)

%
% Copyright 2012 The MathWorks, Inc.