Why do I get "The number of requested coefficients must be equal to or less than 0" ?
3 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I'm trying to compute the MELF coefficients of an audio file and with MATLAB's defect configuration I get this error:
Error using mfcc>iValidateBandEdges (line 360)
The number of requested coefficients must be equal to or less than 0.
Error in mfcc (line 129)
iValidateBandEdges(fs,options.BandEdges,options.NumCoeffs);
Error in pruebasAudio (line 63)
coeffs = mfcc(audioIn,fs);
This is the code I'm using:
dir = "Audios\00000798.aif";
[audioIn,fs] = audioread(dir);
coeffs = mfcc(audioIn,fs);
And the variables I obtain with the audioread function are:
audioIn => 75792x1 double
fs => 250
How can I solve this issue?
Thanks in advance.
1 个评论
采纳的回答
MathWorks Audio Toolbox Team
2024-12-4
编辑:MathWorks Audio Toolbox Team
2024-12-4
Your sample rate is so low that not even the first of the default bandpass filters fall within range. Could you say what kind of audio this is? It will help us cover your use case in the future.
You have a number of options.
- Modify the BandEdges option of mfcc. The default first band edge starts at ~133 Hz to follow the popular Slaney implementation. When modifying, you're using the o-shaughnessy mel formula and just fitting the requested number of mel bands.
- Use audioFeatureExtractor. By default, audioFeatureExtractor uses the o-shaughnessy mel formula, so it will automatically "just work". You will need to modify the Window, overlap length, and fftlength to fit the lower sample rate though. Other modified parameters in the example below are just to show equivalency between the two methods.
- Use the low-level building blocks: designAuditoryFitlerBank, stft, and cepstralCoefficients. Or melSpectrogram + cepstralCoeffiencts.
Here's an example of the first two options:
%% Option 1, use the BandEdges option of mfcc
fs = 250;
audioIn = rand(75792,1);
b = hz2mel([0,124]);
numBands = 16;
melVect = linspace(b(1),b(2),numBands+2);
hzVect = mel2hz(melVect);
melc1 = mfcc(audioIn,fs,BandEdges=hzVect,LogEnergy="ignore");% ignoring log-energy to show equivalency with next option
%% Option 2, use audioFeatureExtractor
afe = audioFeatureExtractor(SampleRate=fs,mfcc=true, ...
Window=hamming(round(0.03*fs),'periodic'), ... % These are defaults of mfcc--probably don't make sense for your signal
OverlapLength=round(0.02*fs), ... % These are defaults of mfcc--probably don't make sense for your signal
FFTLength=round(0.03*fs)); % These are defaults of mfcc--probably don't make sense for your signal
setExtractorParameters(afe,"melSpectrum", ...
SpectrumType="magnitude", ...
WindowNormalization=false, ...
FilterBankDesignDomain="linear", ...
FilterBankNormalization="bandwidth", ...
NumBands=numBands, ...
FrequencyRange=[0,124])
melc2 = extract(afe,audioIn);
Given the very small sample rate you're using, I'm not sure that mfcc would be the best option for feature extraction for you. Certainly the default Window, OverlapLength, and FFTLength will need to be modified to suite your application.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio Processing Algorithm Design 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!