Skip to main content

Gammatone Filterbank Toolkit

Utilities for analysing sound using perceptual models of human hearing.

This is a fork of the gammatone package library by Jason Heeris, 2013. All modifications are by Dan Meliza, Jonah Weissmann, and Tyler Robbins.

Summary

This is a port of Malcolm Slaney's and Dan Ellis' gammatone filterbank MATLAB code, detailed below, to Python 2 and 3 using Numpy and Scipy. It analyses signals by running them through banks of gammatone filters, similar to Fourier-based spectrogram analysis.

Gammatone-based spectrogram of Für Elise

Installation

You can install directly from this git repository using:

pip install git+https://github.com/melizalab/gammatone.git

...or you can clone the git repository however you prefer, and do:

pip install .

...or:

python setup.py install

...from the cloned tree.

Dependencies

  • numpy
  • scipy

for generating plots (optional)

  • matplotlib

for running tests (optional)

  • nose
  • mock

Using the Code

If you want to use the CLI, make sure to enable the plot extra during installation (e.g. pip install .[plot).

See the API documentation. For a demonstration, find a .wav file (for example, Für Elise) and run:

python -m gammatone FurElise.wav -d 10

...to see a gammatone-gram of the first ten seconds of the track. If you've installed via pip or setup.py install, you should also be able to just run:

gammatone FurElise.wav -d 10

Basis

This project is based on research into how humans perceive audio, originally published by Malcolm Slaney:

Malcolm Slaney (1998) "Auditory Toolbox Version 2", Technical Report #1998-010, Interval Research Corporation, 1998.

Slaney's report describes a way of modelling how the human ear perceives, emphasises and separates different frequencies of sound. A series of gammatone filters are constructed whose width increases with increasing centre frequency, and this bank of filters is applied to a time-domain signal. The result of this is a spectrum that should represent the human experience of sound better than, say, a Fourier-domain spectrum would.

A gammatone filter has an impulse response that is a sine wave multiplied by a gamma distribution function. It is a common approach to modelling the auditory system.

The gammatone filterbank approach can be considered analogous (but not equivalent) to a discrete Fourier transform where the frequency axis is logarithmic. For example, a series of notes spaced an octave apart would appear to be roughly linearly spaced; or a sound that was distributed across the same linear frequency range would appear to have more spread at lower frequencies.

The real goal of this toolkit is to allow easy computation of the gammatone equivalent of a spectrogram — a time-varying spectrum of energy over audible frequencies based on a gammatone filterbank.

Slaney demonstrated his research with an initial implementation in MATLAB. This implementation was later extended by Dan Ellis, who found a way to approximate a "gammatone-gram" by using the fast Fourier transform. Ellis' code calculates a matrix of weights that can be applied to the output of a FFT so that a Fourier-based spectrogram can easily be transformed into such an approximation.

Ellis' code and documentation is here: Gammatone-like spectrograms

Interest

I became interested in this because of my background in science communication and my general interest in the teaching of signal processing. I find that the spectrogram approach to visualising signals is adequate for illustrating abstract systems or the mathematical properties of transforms, but bears little correspondence to a person's own experience of sound. If someone wants to see what their favourite piece of music "looks like," a normal Fourier transform based spectrogram is actually quite a poor way to visualise it. Features of the audio seem to be oddly spaced or unnaturally emphasised or de-emphasised depending on where they are in the frequency domain.

The gammatone filterbank approach seems to be closer to what someone might intuitively expect a visualisation of sound to look like, and can help develop an intuition about alternative representations of signals.

Verifying the port

Since this is a port of existing MATLAB code, I've written tests to verify the Python implementation against the original code. These tests aren't unit tests, but they do generally test single functions. Running the tests has the same workflow:

  1. Run the scripts in the test_generation directory. This will create a .mat file containing test data in tests/data.

  2. Run nosetest3 in the top level directory. This will find and run all the tests in the tests directory.

Although I'm usually loathe to check in generated files to version control, I'm willing to make an exception for the .mat files containing the test data. My reasoning is that they represent the decoupling of my code from the MATLAB code, and if the two projects were separated, they would be considered a part of the Python code, not the original MATLAB code.

Metadata

Release files for melizalab-gammatone 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for melizalab-gammatone 0.1.1
File Size Uploaded Provenance Actions
melizalab-gammatone-0.1.1.tar.gz 14.7 kB Without provenance Details for melizalab-gammatone-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for melizalab-gammatone 0.1.1
File Interpreter ABI Platform Actions
melizalab_gammatone-0.1.1-py3-none-any.whl Python 3 none any Details for melizalab_gammatone-0.1.1-py3-none-any.whl

Total release size: 28.8 kB

Release files / melizalab-gammatone-0.1.1.tar.gz

Download URL melizalab-gammatone-0.1.1.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3b1d4c0e7e2329af01834a73088f7079442c228ab24ab99f5c5db6e43c37d3b4
BLAKE2b-256 checksum
How to use checksums
04a7ffce5d8984ab2cf88ac1c97171d27e8729db82a2c354e247e3cf2af94d66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.7

Release files / melizalab_gammatone-0.1.1-py3-none-any.whl

Download URL melizalab_gammatone-0.1.1-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2970bee5c0e94e5f3cfbe93b2356e41f8fa73ba3bb3dcaff7e9eb481cd77d82
BLAKE2b-256 checksum
How to use checksums
ee2a14eb70be69f13adbe1a4593bda6818f39e17a13030c948411aee4362ce04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.7

Security for melizalab-gammatone 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page