本文簡要介紹 python 語言中 scipy.signal.zpk2sos
的用法。
用法:
scipy.signal.zpk2sos(z, p, k, pairing=None, *, analog=False)#
從係統的零點、極點和增益返回二階部分
- z: array_like
傳遞函數的零點。
- p: array_like
傳遞函數的極點。
- k: 浮點數
係統增益。
- pairing: {無,‘nearest’, ‘keep_odd’,‘minimal’},可選
用於將極點和零點對組合成部分的方法。如果模擬為假且配對為無,則配對設置為‘nearest’;如果模擬為真,則配對必須為‘minimal’,如果為無,則設置為該值。
- analog: 布爾型,可選
如果為真,係統是模擬的,否則是離散的。
- sos: ndarray
二階濾波器係數數組,形狀為
(n_sections, 6)
。有關 SOS 過濾器格式規範,請參閱sosfilt
。
參數 ::
返回 ::
注意:
用於將 ZPK 轉換為 SOS 格式的算法旨在最大限度地減少由於數值精度問題導致的錯誤。配對算法試圖最小化每個雙二次部分的峰值增益。這是通過將極點與最近的零配對來完成的,對於discrete-time 係統,從最接近單位圓的極點開始,對於continuous-time 係統,從最接近虛軸的極點開始。
pairing='minimal'
輸出可能不適合sosfilt
,並且analog=True
輸出將永遠不適合sosfilt
。算法
pairing='nearest'
、pairing='keep_odd'
和pairing='minimal'
算法中的步驟大多是共享的。'nearest'
算法試圖最小化峰值增益,而'keep_odd'
在 odd-order 係統應保留一個部分作為一階的約束下最小化峰值增益。'minimal'
類似於'keep_odd'
,但沒有引入額外的極點或零點算法步驟如下:
作為
pairing='nearest'
、pairing='keep_odd'
的預處理步驟,根據需要將極點或零點添加到原點以獲得相同數量的極點和零點以進行配對。如果pairing == 'nearest'
並且有奇數個極點,則在原點添加一個附加極點和一個零。然後迭代以下步驟,直到不再有極點或零點:
取最接近單位圓(或虛軸,對於
analog=True
)的(下一個剩餘的)極點(複數或實數)開始新的濾波器部分。如果極點是實數並且沒有其他剩餘的實數極點 [1],則將最接近的實數零添加到該部分並將其保留為一階部分。請注意,在這一步之後,我們保證為後續配對迭代留下偶數個實極點、複數極點、實零點和複數零點。
別的:
If the pole is complex and the zero is the only remaining real zero*, then pair the pole with the next closest zero (guaranteed to be complex). This is necessary to ensure that there will be a real zero remaining to eventually create a first-order section (thus keeping the odd order).
Else pair the pole with the closest remaining zero (complex or real).
Proceed to complete the second-order section by adding another pole and zero to the current pole and zero in the section:
If the current pole and zero are both complex, add their conjugates.
Else if the pole is complex and the zero is real, add the conjugate pole and the next closest real zero.
Else if the pole is real and the zero is complex, add the conjugate zero and the real pole closest to those zeros.
Else (we must have a real pole and real zero) add the next real pole closest to the unit circle, and then add the real zero closest to that pole.
例子:
為采樣率為 8000 Hz、pass-band 轉角頻率為 1000 Hz 的係統設計 6 階 low-pass 橢圓數字濾波器。 pass-band 中的紋波不應超過 0.087 dB,stop-band 中的衰減應至少為 90 dB。
在下麵對
ellip
的調用中,我們可以使用output='sos'
,但在本示例中,我們將使用output='zpk'
,然後使用zpk2sos
轉換為 SOS 格式:>>> from scipy import signal >>> import numpy as np >>> z, p, k = signal.ellip(6, 0.087, 90, 1000/(0.5*8000), output='zpk')
現在轉換為 SOS 格式。
>>> sos = signal.zpk2sos(z, p, k)
各部分分子的係數:
>>> sos[:, :3] array([[0.0014152 , 0.00248677, 0.0014152 ], [1. , 0.72976874, 1. ], [1. , 0.17607852, 1. ]])
因為所有的零點都在單位圓上,所以會出現係數的對稱性。
各部分分母的係數:
>>> sos[:, 3:] array([[ 1. , -1.32544025, 0.46989976], [ 1. , -1.26118294, 0.62625924], [ 1. , -1.2570723 , 0.8619958 ]])
下一個示例顯示了配對選項的效果。我們有一個具有三個極點和三個零點的係統,因此 SOS 陣列將具有形狀 (2, 6)。實際上,這意味著在 SOS 表示的原點處有一個額外的極點和一個額外的零。
>>> z1 = np.array([-1, -0.5-0.5j, -0.5+0.5j]) >>> p1 = np.array([0.75, 0.8+0.1j, 0.8-0.1j])
使用
pairing='nearest'
(默認),我們得到>>> signal.zpk2sos(z1, p1, 1) array([[ 1. , 1. , 0.5 , 1. , -0.75, 0. ], [ 1. , 1. , 0. , 1. , -1.6 , 0.65]])
第一段有零點 {-0.5-0.05j, -0.5+0.5j} 和極點 {0, 0.75},第二段有零點 {-1, 0} 和極點 {0.8+0.1j, 0.8 -0.1j}。請注意,原點處的額外極點和零點已分配給不同的部分。
使用
pairing='keep_odd'
,我們獲得:>>> signal.zpk2sos(z1, p1, 1, pairing='keep_odd') array([[ 1. , 1. , 0. , 1. , -0.75, 0. ], [ 1. , 1. , 0.5 , 1. , -1.6 , 0.65]])
原點處的額外極點和零在同一部分。第一部分實際上是first-order 部分。
使用
pairing='minimal'
,first-order 部分在原點沒有額外的極點和零點:>>> signal.zpk2sos(z1, p1, 1, pairing='minimal') array([[ 0. , 1. , 1. , 0. , 1. , -0.75], [ 1. , 1. , 0.5 , 1. , -1.6 , 0.65]])
相關用法
- Python SciPy signal.zpk2tf用法及代碼示例
- Python SciPy signal.zoom_fft用法及代碼示例
- Python SciPy signal.czt_points用法及代碼示例
- Python SciPy signal.chirp用法及代碼示例
- Python SciPy signal.residue用法及代碼示例
- Python SciPy signal.iirdesign用法及代碼示例
- Python SciPy signal.max_len_seq用法及代碼示例
- Python SciPy signal.kaiser_atten用法及代碼示例
- Python SciPy signal.oaconvolve用法及代碼示例
- Python SciPy signal.hilbert用法及代碼示例
- Python SciPy signal.ricker用法及代碼示例
- Python SciPy signal.group_delay用法及代碼示例
- Python SciPy signal.cheb2ord用法及代碼示例
- Python SciPy signal.get_window用法及代碼示例
- Python SciPy signal.lfilter用法及代碼示例
- Python SciPy signal.morlet用法及代碼示例
- Python SciPy signal.coherence用法及代碼示例
- Python SciPy signal.dfreqresp用法及代碼示例
- Python SciPy signal.TransferFunction用法及代碼示例
- Python SciPy signal.dbode用法及代碼示例
- Python SciPy signal.residuez用法及代碼示例
- Python SciPy signal.bilinear_zpk用法及代碼示例
- Python SciPy signal.firls用法及代碼示例
- Python SciPy signal.impulse用法及代碼示例
- Python SciPy signal.buttord用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.signal.zpk2sos。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。