簡體   English   中英

設計帶阻濾波器(在SciPy firwin)

[英]Designing band-stop filter (at SciPy firwin)

我正在嘗試使用帶有firwin的kaiserord窗口為我的數據設計一堆過濾器。 我已經根據互聯網上提供的信息設法創建了一個低通濾波器和一個帶通濾波器。 但是,我既不能創建帶阻濾波器,也不能創建高通濾波器。 我正在使用firwin的pass_zero輸入來選擇濾波器是帶通/低通濾波器還是帶阻/高通濾波器( 如firwin文檔中所示

我將以下代碼用於高通濾波器:

from scipy.signal import kaiserord, firwin, freqz
from pylab import figure, clf, plot, xlabel, ylabel, xlim, ylim, title, grid, axes, show

# The Nyquist rate of the signal.
nyq_rate = sample_rate / 2.0

# The desired width of the transition from pass to stop,
# relative to the Nyquist rate.
width = 5/nyq_rate

# The desired attenuation in the stop band, in dB.
ripple_db = 60.0

# Compute the order and Kaiser parameter for the FIR filter.
N, beta = kaiserord(ripple_db, width)
print('Filter order: ', N)

# Use firwin with a Kaiser window to create the high-pass FIR filter.
taps = firwin(N, 15/nyq_rate, window=('kaiser', beta), pass_zero=False)

figure(1)
clf()
w, h = freqz(taps, worN=8000)
plot((w/pi)*nyq_rate, absolute(h), linewidth=2)
xlabel('Frequency (Hz)')
ylabel('Gain')
title('Frequency Response')
ylim(-0.05, 1.05)
grid(True)

這將引發以下錯誤:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\DT\Miniconda3\envs\cmoenv\lib\site-packages\scipy\signal\fir_filter_design.py", line 409, in firwin
    raise ValueError("A filter with an even number of coefficients must "
ValueError: A filter with an even number of coefficients must have zero response at the Nyquist frequency.

有人可以幫我使用kaiserord設計高通和帶阻濾波器嗎?

非常感謝! DT

在調用firwin之前,添加以下語句

N |= 1

這將確保N為奇數。 該語句等效於N = N | 1和| 是按位或運算符。 該語句將N的最低位設置為1。

引用函數的文檔字符串,

此函數計算有限脈沖響應濾波器的系數。 濾波器將具有線性相位; 如果numtaps是奇數, numtaps I型;如果numtaps是偶數, numtaps II型。

II型濾波器在Nyquist頻率下始終具有零響應,因此,如果使用numtaps偶數調用numtaps並且通帶的右端為Nyquist頻率,則會引發ValueError異常。

firwinfirwin返回的系數陣列始終具有偶數對稱性,並且從數學firwin ,具有偶數對稱性和偶數抽頭的濾波器在奈奎斯特頻率下將自動具有零響應,因此設計沒有任何意義。帶firwin帶有firwin的高通或帶阻濾波器。

請查看此問答,以獲取有關FIR濾波器類型的更多背景信息: https : //dsp.stackexchange.com/questions/9408/fir-filter-with-linear-phase-4-types

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM