{ } Raw JSON

bundles / scipy 1.17.1 / scipy / signal / _filter_design / gammatone

function

scipy.signal._filter_design:gammatone

source: /scipy/signal/_filter_design.py :5845

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 : float

Center 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, optional

The 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, optional

Length of the filter. Only used when ftype='fir'. Default is fs*0.015 if fs is greater than 1000, 15 if fs is less than or equal to 1000.

fs : float, optional

The sampling frequency of the signal. freq must be between 0 and fs/2. Default is 2.

xp : array_namespace, optional

Optional array namespace. Should be compatible with the array API standard, or supported by array-api-compat. Default: numpy

device: any

optional device specification for output. Should match one of the supported device specification in xp.

Returns

b, a : ndarray, ndarray

Numerator (b) and denominator (a) polynomials of the filter.

Raises

: ValueError

If freq is less than or equal to 0 or greater than or equal to fs/2, if ftype is not 'fir' or 'iir', if order is less than or equal to 0 or greater than 24 when ftype='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-arrayapi for more information.

Examples

16-sample 4th order FIR Gammatone filter centered at 440 Hz
from scipy import signal
signal.gammatone(440, 'fir', numtaps=16, fs=16000)
IIR Gammatone filter centered at 440 Hz
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()
fig-d766c55f3a5e8c74.png

See also

firwin
iirfilter

Aliases

  • scipy.signal.gammatone

Referenced by