File Exchange

## melfilter

version 1.2 (1.94 KB) by

generates a mel filter bank for a given frequency vector

Updated

% melfilter Create a mel frequency filterbank
%
% [Filter,MelFrequencyVector] = melfilter(N,FrequencyVector,hWindow)
%
% Generates a filter bank matrix with N lineary spaced filter banks,
% in the Mel frequency domain, that are overlapped by 50%.
%
% `N` the number of filter banks to construct.
%
% `FrequencyVector` a vector indicating the frequencies at which to
% evaluate the filter bank coeffiecents.
%
% `hWindow` a handle to the windowing function that determines the shape
% of the filterbank. The default is hWindow = @triang
%
% `Filter` is sparse matrix of size [N numel(FrequencyVector)].
%
% `MelFrequencyVector` is a vector containing the Mel frequency values
%
% Example
% N = 50;
% Fs = 10000;
% x = sin(2*pi*110*(0:(1/Fs):5));
% [Pxx,F] = periodogram(x,[],512,Fs);
%
% Filter = melfilter(N,F);
% Filter = melfilter(N,F,@rectwin);
% [Filter,MF] = melfilter(N,F,@blackmanharris);
% FPxx = Filter*Pxx;
% plot(1:N,FPxx)
%
% melfilter melbankm mfcceps hz2mel
%

I updated the example code,
you should be plotting this

plot(1:N,FPxx)

plot(1:N,mPxxl)

MF is used to plot the Filterbank
i.e.
plot(MF,Filter)

pricky

### pricky (view profile)

Why did you choose f= 512 in
[Pxx,F] = periodogram(x,[],512,Fs);

i am getting

Error using plot
Vectors must be the same lengths.

Error in speechtrial (line 116)
plot(MF,mPxxl);

Thank you

Pawel

### Pawel (view profile)

Sorry Pierce, but I can't plot the signal in the way you exampled it. The dimensions of matrices aren't equal. After filtering my signal with mel bank I get a new signal with length set by the number of filters in the bank, however frequencies vector is much bigger. Do I make something wrong or shall the filtration be done differently? Thanks a lot. Pawel.

Hi gokan,
I have just uploaded a new version with an example. it should be availble in a day or two.

Example of how to use code

File = 'yourfile.wav'
N = 50; % 50 mel filter banks
% Compute power spectrum
[Pxx,F] = periodogram(x,[],512,Fs);
figure;
plot(F,Pxx)
% Create Mel filter bank
[fbMel,MF] = melfilter(N,F);
mPxx = fbMel*Pxx;
figure; plot(MF,mPxxl);

MFCC = dct(log10(mPxx))
figure;
plot(1:N,MFCC)

hope this helps

Gökhan Vural

### Gökhan Vural (view profile)

Hi Pierce.
I wanna use this filter for a wav file.. Could you write an example to show how to use your code ?
ie. melfilter (X , Y); ..