File Exchange

image thumbnail


version 1.2 (1.94 KB) by

generates a mel filter bank for a given frequency vector



View License

% 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)
% See also
% melfilter melbankm mfcceps hz2mel

Comments and Ratings (5)

Pierce Brady

I updated the example code,
you should be plotting this


or in your case


MF is used to plot the Filterbank


pricky (view profile)

Hi Pierce Brady

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)

please help me . How can i resolve this error

Thank you


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.

Pierce Brady

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
% Read file
[X,Fs] = wavread(File);
% Compute power spectrum
[Pxx,F] = periodogram(x,[],512,Fs);
% Create Mel filter bank
[fbMel,MF] = melfilter(N,F);
mPxx = fbMel*Pxx;
figure; plot(MF,mPxxl);

MFCC = dct(log10(mPxx))

hope this helps

Gökhan Vural

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); ..



Changed the example code


1) A third optional input to allow different window shapes.
2) Mel frequency vector can be returned.
3) Example added to help section

MATLAB Release
MATLAB 7.5 (R2007b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today