Code covered by the BSD License

### Highlights from melfilter

Be the first to rate this file! 12 Downloads (last 30 days) File Size: 1.94 KB File ID: #23179 Version: 1.2

# melfilter

04 Mar 2009 (Updated )

generates a mel filter bank for a given frequency vector

File Information
Description

% 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
%

Required Products Signal Processing Toolbox
MATLAB release MATLAB 7.5 (R2007b)

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)

Comment only
20 Feb 2014 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

Comment only
17 Mar 2012 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.

Comment only

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

Comment only
27 Feb 2010 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); ..

Comment only
15 Mar 2010 1.1