Creating Mel triangular filters function
조회 수: 13 (최근 30일)
이전 댓글 표시
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
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
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
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
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...
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Feature Extraction에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!