Getting NaN and Inf values after extracting features from Audio files

17 views (last 30 days)
Ibrahim A
Ibrahim A on 23 Jun 2020
Commented: Greg Heath on 17 Aug 2020
Hello,
I am trying to extract audio features from audio files that range from 1 - 30 seconds. When I extract the features using the code below, I get some NaN and Inf valuses which causing errors when I try to classify my files. Can someone help me to find out why this is happending? what causes this issue? or how to slove it? or any other thoughts.
I checked the files and there is nothing wrong with them."played the audio and was working fine"
Thank you everyone
trainingFeatures = cell(1,numel(adsTrain.Files));
windowLength = 512;
overlapLength = 0;
aFE = audioFeatureExtractor('SampleRate',16e3, ...
'Window',hamming(windowLength,'periodic'),...
'OverlapLength',overlapLength,...
'spectralCentroid',true, ...
'spectralCrest',true, ...
'spectralDecrease',true, ...
'spectralEntropy',true,...
'spectralFlatness',true,...
'spectralFlux',false,...
'spectralKurtosis',true,...
'spectralRolloffPoint',true,...
'spectralSkewness',true,...
'spectralSlope',true,...
'spectralSpread',true);
reset(adsTrain);
index = 1;
while hasdata(adsTrain)
data = read(adsTrain);
trainingFeatures{index} = extract(aFE,data); % After extracting the features, some of the valuse are NaN and Inf
index = index + 1;
end
  2 Comments

Sign in to comment.

Accepted Answer

Brian Hemmat
Brian Hemmat on 17 Aug 2020
The features you are extracting (basically statistics about a spectrum) are either not defined or poorly defined for an all-zero input, which is mostly likely what you have at the beginning of your audio signal. Audio signals are sometimes padded with zeros to make they a consistent length. As you mention, you can replace the first couple feature vectors with some placeholder that won't error downstream for your system. Or, you can just disregard the feature vectors that correspond to all-zero input, since there is no relevant information there anyway.
Here is an illustration of what you are encountering:
>> windowLength = 512;
overlapLength = 0;
aFE = audioFeatureExtractor('SampleRate',16e3, ...
'Window',hamming(windowLength,'periodic'),...
'OverlapLength',overlapLength,...
'spectralCentroid',true, ...
'spectralCrest',true, ...
'spectralDecrease',true, ...
'spectralEntropy',true,...
'spectralFlatness',true,...
'spectralFlux',false,...
'spectralKurtosis',true,...
'spectralRolloffPoint',true,...
'spectralSkewness',true,...
'spectralSlope',true,...
'spectralSpread',true);
input = zeros(512,1);
features = extract(aFE,input)
features =
NaN NaN NaN 0 Inf NaN 0 NaN 0 NaN
The equations for the spectral descriptors can be found on the individual reference pages in the Audio Toolbox documentation, or summarized here:
If you look at the algorithms, you will see that many will result in a divide by zero (Inf) or a 0/0 (NaN).

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!