Creating Mel triangular filters function
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, i know there are already plenty functions that create mel filter banks , but i need to create my own function. I found i decent guide http://practicalcryptography.com/miscellaneous/machine-learning/guide-mel-frequency-cepstral-coefficients-mfccs/ but i got stuck in the creation of triangular mel filters . So i need to make them form that equation
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148569/image.png)
where m is the mel scaled frequencies and k is the length of DFT. I tried the code below, but i get warnings that exceded indeces
f_low=300;
f_high=8000;
filt_num=12;
fs=16000;
%%computing band in mel-scale
mel_low=2595*log10(1+(f_low/100));
mel_high=2595*log10(1+(f_high/100));
%%creating the mel-scaled vector
Mel = linspace(mel_low,mel_high,filt_num);
%%computing frequencies of the Mel vector
%FREQ=700*((10.^(Mel/2595))-1);
Freq=mel2hz(Mel);
%%convert frequencies to nearest bins
for i=1:filt_num
f(i) = floor((nfft+1)*Freq(i)/fs);
end
for m =2:length(Mel)+2
for k=1:nfft+1
if (k<f(Mel(m)-1));H(Mel,k)=0;
elseif (k>=f(Mel(m)-1) && k<=(f(Mel(m))));H(Mel,k)=(k-f(Mel(m)-1))/(f(Mel(m))-f(Mel(m)-1));
elseif (k>=f(Mel(m)) && k<=f(Mel(m)+1));H(Mel,k)=(f(Mel(m)+1)-k)/(f(Mel(m)+1)-f(Mel(m)));
elseif (k>f(Mel(m)+1));H(Mel,k)=0;
end
end
end
Please help any advice appreciated, thank in advance.
2 comentarios
Suchithra K S
el 23 de Mzo. de 2019
Sir when i trying this code it showing the error like this
Subscript indices must either be real positive integers or logicals.
Respuestas (2)
Christiaan
el 2 de Abr. de 2015
Dear Manolis,
In your code you have computed an array 'f', where the frequencies are defined. These frequencies are calculated from this code: '' for i=1:filt_num f(i) = floor((nfft+1)*Freq(i)/fs);end '' However you have not specified nfft, you cannot calculate this. If you mean for nfft, the side of your FFT vector, please have a look at this website how NFFT in MATLAB is defined.
Then you wrote down the following in your code: ' f(Mel(m)) '
However when f has only 12 variables and Mel(1) is equal to a value higher then 12, MATLAB will give an error.
What may can help you is to define a formula to calculate your H value:
function H=formula(k,f,m)
if k<f(m-1)
H = 0;
elseif (k>=f(m-1)&&k<=f(m))
H = (k-f(m-1))/(f(m)-f(m-1));
elseif (k>=f(m+1)&&k<=f(m))
H = (f(m+1)-k)/(f(m+1)-f(m));
elseif k>f(m+1)
H = 0;
end
Then you can call the function in the mainfile to use in the loop.
Good luck! Christiaan
2 comentarios
Awais Asghar
el 4 de Abr. de 2018
Hello manolis and christian, what is k,m and f(m-1)..??? and what is the valu of k,f and m in fuction H-formula(k,f,m)...?????
Aula Rizkiyani
el 17 de Jul. de 2017
Hello manolis and christian, i've tried the function that you both gave but still wrong.
hz2mel = @ (hz) (1127*log(1+hz/700)); %Hertz to mel mel2hz = @ (mel) (700*exp(mel/1127)-700); %mel to Hertz f_low=300; f_high=8000; filt_num=12; fs=16000;
%% computing band in mel-scale mel_low=2595*log10(1+(f_low/100)); mel_high=2595*log10(1+(f_high/100));
%% creating the mel-scaled vector Mel = linspace(mel_low,mel_high,filt_num);
%% computing frequencies of the Mel vector Freq=700*((10.^(Mel/2595))-1); Freq=mel2hz(Mel);
Then i give the function that is explained by christian. like this : %% convert frequencies to nearest bins function H=formula(k,f,m) if k<f(m-1) H = 0; elseif (k>=f(m-1)&&k<=f(m)) H = (k-f(m-1))/(f(m)-f(m-1)); elseif (k>=f(m+1)&&k<=f(m)) H = (f(m+1)-k)/(f(m+1)-f(m)); elseif k>f(m+1) H = 0; end
After that I call the variable "Freq" to display on the plot. So the results I get like this.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/177471/image.png)
Can you help me. thank you...
0 comentarios
Ver también
Categorías
Más información sobre Feature Extraction en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!