-
Notifications
You must be signed in to change notification settings - Fork 2
/
melfilter.m
36 lines (34 loc) · 1.33 KB
/
melfilter.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function fb1=melfilter(fs1,fsize1,noc1)
fmax = fs1/2; % maximum frequency
Nmax = fsize1/2; % maximum fft index
melmax = freq2mel(fmax); % maximum mel frequency
df = fs1/fsize1; %frequency increment on linear scale ie. frequency resolution
dmel = melmax / (noc1 + 1); % frequency increment on mel scale
%center frequencies on mel scale
melcenters = (1:noc1) .* dmel;
%center frequencies in linear scale [Hz]
fcenters = mel2freq(melcenters);
%on linear scale gives corresponding indices of coefficient of power
%spectrum ie. fft indices
indexcenter = round(fcenters ./df); %center of nc(k)
%compute start indices of windows
indexstart = [1 , indexcenter(1:noc1-1)]; %start of nc(k)= center of nc(k-1)
%compute stop indices of windows
indexstop = [indexcenter(2:noc1),Nmax]; %stop of nc(k)=center of nc(k+1)
%compute triangle-shaped filter coefficients
fb1(1:noc1,1:Nmax) =0;
for c = 1:noc1
%left ramp
increment = 1.0/(indexcenter(c) - indexstart(c)); %maximum amplitude is 1
for i = indexstart(c)+1:indexcenter(c)
fb1(c,i) = (i - indexstart(c))*increment;
end
%right ramp
decrement = 1.0/(indexstop(c) - indexcenter(c));
for i = indexcenter(c):indexstop(c)
fb1(c,i) = 1.0 - ((i - indexcenter(c))*decrement);
end
end
fb1=nanclr(fb1);
%figure;
%plot(fb1');