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

melfilter

by

 

04 Mar 2009 (Updated )

generates a mel filter bank for a given frequency vector

| Watch this File

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

Required Products Signal Processing Toolbox
MATLAB release MATLAB 7.5 (R2007b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
21 Feb 2014 Pierce Brady

I updated the example code,
you should be plotting this

plot(1:N,FPxx)

or in your case

plot(1:N,mPxxl)

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

20 Feb 2014 pricky

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)
plot(MF,mPxxl);

please help me . How can i resolve this error

Thank you

17 Mar 2012 Pawel

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.

15 Mar 2010 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);
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

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

Updates
15 Mar 2010

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

21 Feb 2014

Changed the example code

Contact us