Gammatone Filterbank
raw JSON → 1.0.3 verified Fri May 01 auth: no python
A Python implementation of gammatone filters for auditory modeling, including filterbank generation and cochleagram computation. Current version: 1.0.3 (patch release, adds f_max parameter to gtgram). Requires Python >=3.8.
pip install gammatone Common errors
error ImportError: cannot import name 'Gammatone' from 'gammatone' ↓
cause Trying to import Gammatone from the top-level package instead of the implementation module.
fix
Use 'from gammatone.gammatone_impl import Gammatone'
error ValueError: The number of channels is too high for the given f_max ↓
cause Requesting more channels than possible given the frequency range when using gtgram.
fix
Reduce channels or increase f_max. Ensure f_max / f_min >= 2^(channels/ERB scale).
error TypeError: gtgram() got an unexpected keyword argument 'f_max' ↓
cause Using an older version of gammatone (<1.0.3) that does not support the f_max parameter.
fix
Upgrade: pip install --upgrade gammatone
Warnings
gotcha The default f_max in gtgram is 4000 Hz. If you need higher frequencies (e.g., for 22050 Hz audio), pass f_max explicitly. Added in v1.0.3. ↓
fix Call gtgram(... , f_max=8000) to extend coverage.
gotcha Input signal must be 1-D array. If you pass a 2-D array (e.g., stereo audio), it will fail silently or produce incorrect shape. ↓
fix Mono mix: signal = np.mean(signal, axis=1) for stereo.
deprecated Direct import from gammatone.gammatone (without _impl suffix) may be deprecated in future releases. Use gammatone.gammatone_impl for core filter classes. ↓
fix Use from gammatone.gammatone_impl import Gammatone
Imports
- Gammatone
from gammatone.gammatone_impl import Gammatone - gtgram
from gammatone.gtgram import gtgram - gammatone_freq
from gammatone.filters import make_erb_filters, centre_freqs
Quickstart
import numpy as np
from gammatone.gtgram import gtgram
# Generate a cochleagram from a sample audio signal
fs = 16000
duration = 0.1
t = np.linspace(0, duration, int(fs*duration), endpoint=False)
signal = np.sin(2*np.pi*1000*t) # 1 kHz tone
# Compute gammatone spectrogram (cochleagram)
coch = gtgram(signal, fs, window_time=0.02, hop_time=0.01, channels=64, f_min=50, f_max=8000)
print(coch.shape)