Not sure what causes it but by applying fillmissing function, it should solve the problem by replacing the NaN values with valid values.
Getting NaN and Inf values after extracting features from Audio files
3 views (last 30 days)
Show older comments
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/321019/image.jpeg)
2 Comments
Accepted Answer
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).
0 Comments
More Answers (0)
See Also
Categories
Find more on AI for Audio in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!