scipy.signal.

minimum_phase#

scipy.signal.minimum_phase(h, method='homomorphic', n_fft=None, *, half=True)[原始碼]#

將線性相位 FIR 濾波器轉換為最小相位

參數:
harray

線性相位 FIR 濾波器係數。

method{‘hilbert’, ‘homomorphic’}

可用的方法有

‘homomorphic’ (預設)

此方法 [4] [5] 最適用於具有奇數個 taps 的濾波器,且當 half=True (預設) 時,產生的最小相位濾波器將具有幅度響應,該響應近似於原始濾波器幅度響應的平方根,使用一半數量的 taps;當 half=False 時,則使用相同數量的 taps 近似於原始幅度頻譜。

‘hilbert’

此方法 [1] 旨在用於具有單位或零增益區域的等紋波濾波器 (例如,來自 remez)。

n_fftint

用於 FFT 的點數。應至少比訊號長度大幾倍 (請參閱 Notes)。

halfbool

如果 True,則建立一個長度為原始長度一半的濾波器,其幅度頻譜為原始頻譜的平方根。如果 False,則建立一個與原始長度相同的濾波器,其幅度頻譜旨在匹配原始頻譜 (僅在 method='homomorphic' 時支援)。

版本 1.14.0 新增。

返回:
h_minimumarray

濾波器的最小相位版本,當 half is True 時,長度為 (len(h) + 1) // 2,否則為 len(h)

另請參閱

firwin
firwin2
remez

註解

Hilbert [1] 或同態 [4] [5] 方法都需要選擇 FFT 長度來估計濾波器的複倒頻譜。

對於 Hilbert 方法,與理想頻譜的偏差 epsilon 與阻帶零點數量 n_stop 和 FFT 長度 n_fft 相關,如下所示

epsilon = 2. * n_stop / n_fft

例如,對於 100 個阻帶零點和 2048 的 FFT 長度,epsilon = 0.0976。如果我們保守地假設阻帶零點的數量比濾波器長度少 1,我們可以將 FFT 長度設為滿足 epsilon=0.01 的下一個 2 的冪,如下所示

n_fft = 2 ** int(np.ceil(np.log2(2 * (len(h) - 1) / 0.01)))

這為 Hilbert 和同態方法都提供了合理的結果,並給出了 n_fft=None 時使用的值。

存在用於建立最小相位濾波器的替代實作方式,包括零點反轉 [2] 和頻譜分解 [3] [4]。如需更多資訊,請參閱 此 DSPGuru 頁面

參考文獻

[1] (1,2)

N. Damera-Venkata 和 B. L. Evans,“Optimal design of real and complex minimum phase digital FIR filters,” Acoustics, Speech, and Signal Processing, 1999. Proceedings., 1999 IEEE International Conference on, Phoenix, AZ, 1999, pp. 1145-1148 vol.3. DOI:10.1109/ICASSP.1999.756179

[2]

X. Chen 和 T. W. Parks,“Design of optimal minimum phase FIR filters by direct factorization,” Signal Processing, vol. 10, no. 4, pp. 369-383, Jun. 1986.

[3]

T. Saramaki,“Finite Impulse Response Filter Design,” in Handbook for Digital Signal Processing, chapter 4, New York: Wiley-Interscience, 1993.

[4] (1,2,3)

J. S. Lim, Advanced Topics in Signal Processing. Englewood Cliffs, N.J.: Prentice Hall, 1988.

[5] (1,2)

A. V. Oppenheim, R. W. Schafer, 和 J. R. Buck,“Discrete-Time Signal Processing,” 3rd edition. Upper Saddle River, N.J.: Pearson, 2009.

範例

建立一個最佳線性相位低通濾波器 h,其過渡帶為 [0.2, 0.3] (假設 Nyquist 頻率為 1)

>>> import numpy as np
>>> from scipy.signal import remez, minimum_phase, freqz, group_delay
>>> import matplotlib.pyplot as plt
>>> freq = [0, 0.2, 0.3, 1.0]
>>> desired = [1, 0]
>>> h_linear = remez(151, freq, desired, fs=2)

將其轉換為最小相位

>>> h_hil = minimum_phase(h_linear, method='hilbert')
>>> h_hom = minimum_phase(h_linear, method='homomorphic')
>>> h_hom_full = minimum_phase(h_linear, method='homomorphic', half=False)

比較四個濾波器的脈衝響應和頻率響應

>>> fig0, ax0 = plt.subplots(figsize=(6, 3), tight_layout=True)
>>> fig1, axs = plt.subplots(3, sharex='all', figsize=(6, 6), tight_layout=True)
>>> ax0.set_title("Impulse response")
>>> ax0.set(xlabel='Samples', ylabel='Amplitude', xlim=(0, len(h_linear) - 1))
>>> axs[0].set_title("Frequency Response")
>>> axs[0].set(xlim=(0, .65), ylabel="Magnitude / dB")
>>> axs[1].set(ylabel="Phase / rad")
>>> axs[2].set(ylabel="Group Delay / samples", ylim=(-31, 81),
...             xlabel='Normalized Frequency (Nyqist frequency: 1)')
>>> for h, lb in ((h_linear,   f'Linear ({len(h_linear)})'),
...               (h_hil,      f'Min-Hilbert ({len(h_hil)})'),
...               (h_hom,      f'Min-Homomorphic ({len(h_hom)})'),
...               (h_hom_full, f'Min-Homom. Full ({len(h_hom_full)})')):
...     w_H, H = freqz(h, fs=2)
...     w_gd, gd = group_delay((h, 1), fs=2)
...
...     alpha = 1.0 if lb == 'linear' else 0.5  # full opacity for 'linear' line
...     ax0.plot(h, '.-', alpha=alpha, label=lb)
...     axs[0].plot(w_H, 20 * np.log10(np.abs(H)), alpha=alpha)
...     axs[1].plot(w_H, np.unwrap(np.angle(H)), alpha=alpha, label=lb)
...     axs[2].plot(w_gd, gd, alpha=alpha)
>>> ax0.grid(True)
>>> ax0.legend(title='Filter Phase (Order)')
>>> axs[1].legend(title='Filter Phase (Order)', loc='lower right')
>>> for ax_ in axs:  # shade transition band:
...     ax_.axvspan(freq[1], freq[2], color='y', alpha=.25)
...     ax_.grid(True)
>>> plt.show()
../../_images/scipy-signal-minimum_phase-1_00_00.png
../../_images/scipy-signal-minimum_phase-1_00_01.png

脈衝響應和群組延遲圖描繪了線性相位濾波器 h 的 75 個樣本延遲。相位在阻帶中也應為線性 – 由於幅度小,數值雜訊在那裡佔主導地位。此外,這些圖顯示最小相位濾波器清楚地顯示在通帶和過渡帶中減少 (負) 的相位斜率。這些圖也說明了參數為 method='homomorphic', half=False 的濾波器具有與線性濾波器 h 相同的階數和幅度響應,而其他最小相位濾波器只有一半的階數和幅度響應的平方根。