scipy.signal.
gammatone#
- scipy.signal.gammatone(freq, ftype, order=None, numtaps=None, fs=None)[source]#
Gammatone 濾波器設計。
此函數計算 FIR 或 IIR Gammatone 數位濾波器的係數 [1]。
- 參數:
- freqfloat
濾波器的中心頻率(單位與 fs 相同)。
- ftype{‘fir’, ‘iir’}
函數產生的濾波器類型。如果為 ‘fir’,函數將產生 N 階 FIR Gammatone 濾波器。如果為 ‘iir’,函數將產生 8 階數位 IIR 濾波器,建模為 4 階 Gammatone 濾波器。
- orderint, optional
濾波器的階數。僅當
ftype='fir'
時使用。預設值為 4,以模擬人類聽覺系統。必須介於 0 到 24 之間。- numtapsint, optional
濾波器的長度。僅當
ftype='fir'
時使用。如果 fs 大於 1000,則預設值為fs*0.015
;如果 fs 小於或等於 1000,則為 15。- fsfloat, optional
訊號的取樣頻率。freq 必須介於 0 到
fs/2
之間。預設值為 2。
- 返回值:
- b, andarray, ndarray
濾波器的分子 (
b
) 和分母 (a
) 多項式。
- 引發:
- ValueError
如果 freq 小於或等於 0 或大於或等於
fs/2
,如果 ftype 不是 ‘fir’ 或 ‘iir’,如果當ftype='fir'
時 order 小於或等於 0 或大於 24
參考文獻
[1]Slaney, Malcolm, “An Efficient Implementation of the Patterson-Holdsworth Auditory Filter Bank”, Apple Computer Technical Report 35, 1993, pp.3-8, 34-39.
範例
16 樣本點 4 階 FIR Gammatone 濾波器,中心頻率為 440 Hz
>>> from scipy import signal >>> signal.gammatone(440, 'fir', numtaps=16, fs=16000) (array([ 0.00000000e+00, 2.22196719e-07, 1.64942101e-06, 4.99298227e-06, 1.01993969e-05, 1.63125770e-05, 2.14648940e-05, 2.29947263e-05, 1.76776931e-05, 2.04980537e-06, -2.72062858e-05, -7.28455299e-05, -1.36651076e-04, -2.19066855e-04, -3.18905076e-04, -4.33156712e-04]), [1.0])
IIR Gammatone 濾波器,中心頻率為 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()