Creating Mel triangular filters function

21 ビュー (過去 30 日間)
Manolis Michailidis
Manolis Michailidis 2015 年 4 月 1 日
コメント済み: Suchithra K S 2019 年 3 月 23 日
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
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 件のコメント
Angel David
Angel David 2017 年 2 月 15 日
Replace log10 for a log function.
Suchithra K S
Suchithra K S 2019 年 3 月 23 日
Sir when i trying this code it showing the error like this
Subscript indices must either be real positive integers or logicals.

サインインしてコメントする。

回答 (2 件)

Christiaan
Christiaan 2015 年 4 月 2 日
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 件のコメント
Manolis Michailidis
Manolis Michailidis 2015 年 4 月 2 日
Hello Cristian and thanks for you reply, yes indeed i forgot to mention that i use fft with 128 points.Anyway the idea is to create overlapped triangular filters (a matrix H[number_of_filters,nfft_points]) that will have different widths something like this
Anyway thanks again.
Awais Asghar
Awais Asghar 2018 年 4 月 4 日
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
Aula Rizkiyani 2017 年 7 月 17 日
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.
Can you help me. thank you...

カテゴリ

Help Center および File ExchangeFeature Extraction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by