scipy.signal.ellip 椭圆滤波器

scipy.signal.ellip(N, rp, rs, Wn, btype='low',analog=False, output='ba', fs=None)[source]

Elliptic (Cauer) digital and analog filterdesign.

Design an Nth-order digital or analog ellipticfilter and return the filter coefficients.

Parameters:

N :int

滤波器阶数

Rp:float

The maximum ripple allowed below unity gain inthe passband. Specified in decibels, as a positive number. 通带中单位增益以下允许的最大值

Rs:float

The minimum attenuation required in the stopband. Specified in decibels, as a positive number. 阻带内所需的最小衰减

Wn:array_like

A scalar or length-2 sequence giving thecritical frequencies. For elliptic filters, this is the point in the transitionband at which the gain first drops below -rp.

For digital filters, Wn are in the same unitsas fs. By default, fs is 2 half-cycles/sample, so these are normalized from 0to 1, where 1 is the Nyquist frequency. (Wn is thus in half-cycles / sample.)

For analog filters, Wn is an angular frequency(e.g., rad/s).

给出临界频率的标量或长度为2的序列。对于椭圆滤波器,这是过渡频带中增益首次降至-rp以下的点。 对于数字滤波器,Wn的单位与fs相同。默认情况下,fs为2个半周期/样本,因此它们归一化为0至1,其中1为奈奎斯特频率。(Wn因此,单位为半周期/样本。) 对于模拟滤波器,Wn是角频率(例如,弧度/秒)。

Btype:{‘lowpass’,‘highpass’, ‘bandpass’, ‘bandstop’}, optional

The type of filter. Default is ‘lowpass’.

滤波器类型

Analog:bool,optional

When True, return an analog filter, otherwise adigital filter is returned.

如果为True,则返回模拟滤波器,否则返回数字滤波器。

Output:{‘ba’,‘zpk’, ‘sos’}, optional

Type of output: numerator/denominator (‘ba’),pole-zero (‘zpk’), or second-order sections (‘sos’). Default is ‘ba’ forbackwards compatibility, but ‘sos’ should be used for general-purposefiltering.

输出类型:分子/分母(“ba”)、极点-零点(“zpk”)或二阶部分(“sos”)。默认值为“ba”以向后兼容,但“sos”应用于通用过滤。

Fs:float,optional

The sampling frequency of the digital system.

数字系统的采样频率。

Returns:

b, andarray, ndarray

Numerator (b) and denominator (a)polynomials of the IIR filter. Only returned if output='ba'.

IIR滤波器的分子(B)和分母(a)多项式

z, p, kndarray,ndarray, float

Zeros, poles, and system gain of the IIRfilter transfer function. Only returned if output='zpk'.

IIR滤波器传递函数的零点、极点和系统增益。

sosndarray

Second-order sections representation ofthe IIR filter. Only returned if output='sos'.

IIR滤波器的二阶部分表示。

scipy.signal.filtfilt滤波函数

scipy.signal.filtfilt(b, a, x, axis=-1,padtype='odd', padlen=None, method='pad', irlen=None)

输入参数:

b: 滤波器的分子系数向量

a: 滤波器的分母系数向量

x: 要过滤的数据数组。(array型)

axis: 指定要过滤的数据数组x的轴

padtype: 必须是“奇数”、“偶数”、“常数”或“无”。这决定了用于过滤器应用的填充信号的扩展类型。{‘odd’,‘even’, ‘constant’, None}

padlen:在应用滤波器之前在轴两端延伸X的元素数目。此值必须小于要滤波元素个数- 1。(int型或None)

method:确定处理信号边缘的方法。当method为“pad”时,填充信号;填充类型padtype和padlen决定,irlen被忽略。当method为“gust”时,使用古斯塔夫森方法,而忽略padtype和padlen。{“pad” ,“gust”}

irlen:当method为“gust”时,irlen指定滤波器的脉冲响应的长度。如果irlen是None,则脉冲响应的任何部分都被忽略。对于长信号,指定irlen可以显著改善滤波器的性能。(int型或None)

输出参数:

y:滤波后的数据数组

scipy.signal.butter 巴特沃斯滤波器

滤波器构造函数(仅介绍Butterworth滤波器)

scipy.signal.butter(N, Wn, btype='low', analog=False, output='ba')

输入参数:

N:滤波器的阶数

Wn:归一化截止频率。计算公式Wn=2*截止频率/采样频率。(注意:根据采样定理,采样频率要大于两倍的信号本身最大的频率,才能还原信号。截止频率一定小于信号本身最大的频率,所以Wn一定在0和1之间)。当构造带通滤波器或者带阻滤波器时,Wn为长度为2的列表。

btype : 滤波器类型{‘lowpass’,‘highpass’, ‘bandpass’, ‘bandstop’},

output : 输出类型{‘ba’,‘zpk’, ‘sos’},

输出参数:

b,a: IIR滤波器的分子(b)和分母(a)多项式系数向量。output='ba'

z,p,k: IIR滤波器传递函数的零点、极点和系统增益.output= 'zpk'

sos: IIR滤波器的二阶截面表示。output='sos'

函数的使用

信号滤波中最常用的无非低通滤波、高通滤波和带通滤波。下面简单介绍这三种滤波的使用过程:

(1).高通滤波

# 这里假设采样频率为1000hz,信号本身最大的频率为500hz,要滤除10hz以下频率成分,即截至频率为10hz,则wn=2*10/1000=0.02

# from scipy import signal

# b, a = signal.butter(8, 0.02, 'highpass')

# filtedData = signal.filtfilt(b, a, data)#data为要过滤的信号

(2).低通滤波

# 这里假设采样频率为1000hz,信号本身最大的频率为500hz,要滤除10hz以上频率成分,即截至频率为10hz,则wn=2*10/1000=0.02

# from scipy import signal

# b, a = signal.butter(8, 0.02, 'lowpass')

# filtedData = signal.filtfilt(b, a, data) #data为要过滤的信号

(3).带通滤波

# 这里假设采样频率为1000hz,信号本身最大的频率为500hz,要滤除10hz以下和400hz以上频率成分,即截至频率为10hz和400hz,则wn1=2*10/1000=0.02,wn2=2*400/1000=0.8。Wn=[0.02,0.8]

# from scipy import signal

# b, a = signal.butter(8, [0.02,0.8], 'bandpass')

# filtedData = signal.filtfilt(b, a, data) #data为要过滤的信号

具体可以看官方文档https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.ellip.html#scipy.signal.ellip