bundles / scipy latest / scipy / signal / _filter_design / gammatone
function
scipy.signal._filter_design:gammatone
Signature
def gammatone ( freq , ftype , order = None , numtaps = None , fs = None , * , xp = None , device = None ) Summary
Gammatone filter design.
Extended Summary
This function computes the coefficients of an FIR or IIR gammatone digital filter [1].
Parameters
freq: floatCenter frequency of the filter (expressed in the same units as
fs).ftype: {'fir', 'iir'}The type of filter the function generates. If 'fir', the function will generate an Nth order FIR gammatone filter. If 'iir', the function will generate an 8th order digital IIR filter, modeled as as 4th order gammatone filter.
order: int, optionalThe order of the filter. Only used when
ftype='fir'. Default is 4 to model the human auditory system. Must be between 0 and 24.numtaps: int, optionalLength of the filter. Only used when
ftype='fir'. Default isfs*0.015iffsis greater than 1000, 15 iffsis less than or equal to 1000.fs: float, optionalThe sampling frequency of the signal.
freqmust be between 0 andfs/2. Default is 2.xp: array_namespace, optionalOptional array namespace. Should be compatible with the array API standard, or supported by array-api-compat. Default:
numpydevice: anyoptional device specification for output. Should match one of the supported device specification in
xp.
Returns
b, a: ndarray, ndarrayNumerator (
b) and denominator (a) polynomials of the filter.
Raises
: ValueErrorIf
freqis less than or equal to 0 or greater than or equal tofs/2, ifftypeis not 'fir' or 'iir', iforderis less than or equal to 0 or greater than 24 whenftype='fir'
Notes
Array API Standard Support
gammatone has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ✅ PyTorch ✅ ✅ JAX ✅ ✅ Dask ✅ n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
16-sample 4th order FIR Gammatone filter centered at 440 Hzfrom scipy import signal
✓signal.gammatone(440, 'fir', numtaps=16, fs=16000)
✗import matplotlib.pyplot as plt import numpy as np✓
fc, fs = 440, 16000 b, a = signal.gammatone(fc, 'iir', fs=fs) w, h = signal.freqz(b, a)✓
plt.plot(w * fs / (2 * np.pi), 20 * np.log10(abs(h)))
✗plt.xscale('log')
✓plt.title('Gammatone filter frequency response') plt.xlabel('Frequency [Hz]') plt.ylabel('Amplitude [dB]')✗
plt.margins(0, 0.1) plt.grid(which='both', axis='both')✓
plt.axvline(fc, color='green') # cutoff frequency
✗plt.show()
✓
See also
Aliases
-
scipy.signal.gammatone