當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python SciPy signal.gammatone用法及代碼示例

本文簡要介紹 python 語言中 scipy.signal.gammatone 的用法。

用法:

scipy.signal.gammatone(freq, ftype, order=None, numtaps=None, fs=None)#

Gammatone 濾波器設計。

此函數計算 FIR 或 IIR 伽馬調數字濾波器 [1] 的係數。

參數

freq 浮點數

濾波器的中心頻率(以與 fs 相同的單位表示)。

ftype {‘fir’, ‘iir’}

函數生成的過濾器類型。如果‘fir’,該函數將生成一個 N 階 FIR gammatone 濾波器。如果‘iir’,該函數將生成一個 8 階數字 IIR 濾波器,建模為 4 階 gammatone 濾波器。

order 整數,可選

過濾器的順序。僅在 ftype='fir' 時使用。默認值為 4 以模擬人類聽覺係統。必須介於 0 和 24 之間。

numtaps 整數,可選

過濾器的長度。僅在使用時ftype='fir'.默認為fs*0.015如果fs大於 1000, 15 如果fs小於或等於 1000。

fs 浮點數,可選

信號的采樣頻率。頻率必須介於 0 和fs/2.默認值為 2。

返回

b, a 數組,數組

濾波器的分子 (b) 和分母 (a) 多項式。

拋出

ValueError

如果頻率小於或等於 0 或大於或等於fs/2, 如果類型不是 ‘fir’ 或 ‘iir’,如果次序小於或等於 0 或大於 24 時ftype='fir'

參考

[1]

Slaney, Malcolm,“Patterson-Holdsworth 聽覺濾波器組的有效實現”,Apple Computer Technical Report 35, 1993, pp.3-8, 34-39。

例子

以 440 Hz 為中心的 16 個樣本四階 FIR Gammatone 濾波器

>>> 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
>>> b, a = signal.gammatone(440, 'iir', fs=16000)
>>> w, h = signal.freqz(b, a)
>>> plt.plot(w / ((2 * np.pi) / 16000), 20 * np.log10(abs(h)))
>>> plt.xscale('log')
>>> plt.title('Gammatone filter frequency response')
>>> plt.xlabel('Frequency')
>>> plt.ylabel('Amplitude [dB]')
>>> plt.margins(0, 0.1)
>>> plt.grid(which='both', axis='both')
>>> plt.axvline(440, color='green') # cutoff frequency
>>> plt.show()
scipy-signal-gammatone-1.png

相關用法


注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.signal.gammatone。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。