File Exchange

image thumbnail

Gammatone filterbank

version (150 KB) by Christopher Hummersone
Produce an array of responses from a fourth-order Gammatone filter via FFT


Updated 05 May 2018

From GitHub

View Version History

View license on GitHub

NOTE: this function is now available from the IoSR Matlab Toolbox as iosr.auditory.gammatoneFast.
bm = gammatoneFast(x,cfs,fs)
bm = gammatoneFast(...,align)
[bm,env] = gammatoneFast(...)
[bm,env,delay] = gammatoneFast(...)

This function takes an input vector and passes it through a bank of fourth-order gammatone filters, with centre frequencies specified by cfs. The function returns a matrix, with each row/column corresponding to a filter output with a centre frequency determined by the corresponding element in cfs. The orientation of the output is determined by the orientation of the input: if x is a row vector then the output will contain one row for each filter output, and vice versa.

Centre frequencies may be any value below the Nyquist rate (determined by the sampling frequency fs). Typically centre frequencies are equally spaced on the ERB-rate scale and may be calculated thus:

cfs = MakeErbCFs(low_cf,high_cf,numchans)

where low_cf is the lowest frequency in the bank, high_cf is the highest, and numchans is the numbers of filters in the bank.

bm = gammatoneFast(...,align) allows phase alignment to be applied. With align=false, no alignment is applied (default). With align=true, fine structure and envelope alignment is applied so that the impulse response peaks occurs at t=0.

[bm,env] = gammatoneFast(...) returns the instantaneous envelopes env for each filter.

[bm,env,delay] = gammatoneFast(...) returns the delay (in samples) removed by the phase alignment of each gammatone filter, i.e. delays(n)=0 if align=false. delay is a vector the same size as cfs.

Based on code written by ZZ Jin, adapted by DLW in Jan'07 and JF Woodruff in Nov'08

See also MakeErbCFs.

Cite As

Christopher Hummersone (2021). Gammatone filterbank (, GitHub. Retrieved .

Comments and Ratings (22)

Precious Chiejine

Hi Christopher, thanks for sharing.
I tried using the example code below which worked fine, but when I specify a path as you said (replacing 'imp' with 'x' and removing 'fs=48000'), I get a length mismatch error between X and Z. How can I rectify, please?


Z.H w

Thank U so much

Hi Patrick,

The function is not really designed for real-time processing. Real-time audio processing is normally performed on short blocks of audio samples (typically 512-1024 samples). At 44100Hz sampling rate, the impulse response would be 8192 samples, which is too long for any practical real-time system. Also, such block-based processing requires the filters to retain their ‘state’ between blocks. This function has no such mechanism.

You may be able to refactor some parts of the code into something useful. But I don’t think it’s useful in its current form.


Patrick Koch

Hey Christopher,

thanks for sharing. One question: I would like to use this algorithm on a live audio stream from a microphone. Do you think this is possible?

Thanks in advance.

Patrick Koch

Hi Hoi. You can pass any signal through the filter bank. This will give you the time-domain response of each filter. If you want cepstral coefficients then you’ll have to work out how to transform the time-domain data.

Hoi Liu

THX a lot,but is this use in speech? I am finding GFCC.

Hi Hoi, You can use code from the example below, except replace `imp` with `x` and set x as:
[x, fs] = audioread('path/to/my/file.wav');
and remove the line `fs = 48000;`. This assumes that x is a vector. If it's an array (because you have more than one audio channel) then you'll have to modify the code in order to pass one channel at a time through the filterbank.

Hoi Liu

HI Christopher Hummersone,waiting for your answer

Hoi Liu

I cant use ,after download the tool box ,could you sent me an example of audio signal to gammatone coef ,I cant plot the gammatone,thx

Hi Hoi. Your comment-less rating is of little value to me, or anyone else. Perhaps you could share the reasons for your rating? Better yet, suggest ways in which the code might be improved. Chris.

Hoi Liu

.... you can use the code in the comments below to draw the figure.

Ahmed Alghamdi

What is the effect of not doing phase alignment on the output of the gammatone filters?

Ahmed Alghamdi

Bohyun Kim

Thank you so much!! I totally appreciate for your help :)

fs = 48000; % sample rate
numchans = 8; % number of frequency channels
t = -0.005:1/fs:0.025; % time (s)

% impulse
imp = zeros(numel(t), 1);
imp(t==0) = 1;

% centre frequencies
cfs = iosr.auditory.makeErbCFs(500, 7500, numchans);

% calculate impulse response fine structure
x1 = iosr.auditory.gammatoneFast(imp, cfs, fs);
x2 = iosr.auditory.gammatoneFast(imp, cfs, fs, true);

% normalise each frequency for plotting
for c = 1:numchans
x1(:, c) = x1(:, c) ./ max(abs(x1(:, c)));
x2(:, c) = x2(:, c) ./ max(abs(x2(:, c)));

% draw
% non-phase aligned
subplot(1, 2, 1)
iosr.figures.multiwaveplot(t*1000, 1:numchans, x1')
h = gca;
% phase aligned
subplot(1, 2, 2)
iosr.figures.multiwaveplot(t*1000, 1:numchans, x2')
h(2) = gca;
% plot settings
set(h, 'yticklabel', num2str(round(cfs)'))
for n = 1:2
xlabel(h(n), 'Time [ms]');
ylabel(h(n), 'Frequency [Hz]');
title(h(1), 'Non-phase-aligned gammatone filterbank')
title(h(2), 'Phase-aligned gammatone filterbank')

Bohyun Kim

Could you tell me how can i plot the filtered signal like the screenshots above?

Shichao Hu


Kamil Wojcicki

Works great, thank you.

MATLAB Release Compatibility
Created with R2011a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!