python的一些滤波器函数

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

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,针对这个问题,我可以为您提供一些思路和代码。 首先,我们需要导入一些必要的库,比如 numpy、scipy、opencv-python 等。 ```python import cv2 import numpy as np from scipy.signal import convolve2d ``` 然后,我们可以定义一个高斯滤波器函数,用于对图像进行平滑处理,以便于更好地去除噪声。 ```python def gaussian_filter(size, sigma=1): x, y = np.meshgrid(np.linspace(-1,1,size), np.linspace(-1,1,size)) d = np.sqrt(x*x+y*y) g = np.exp(-(d**2 / (2.0*sigma**2))) return g / g.sum() ``` 接着,我们可以定义一个泊松噪声生成函数,用于对图像添加噪声。 ```python def add_poisson_noise(image): noisy_image = np.zeros(image.shape, np.uint8) noisy_image = cv2.randn(noisy_image, 0, np.sqrt(image)) noisy_image = cv2.add(image, noisy_image) return noisy_image ``` 最后,我们可以将上述函数整合起来,设计一个去噪函数,对泊松噪声图像进行去噪。 ```python def denoise_poisson(image, size=3, sigma=1): noisy_image = add_poisson_noise(image) kernel = gaussian_filter(size, sigma) denoised_image = np.zeros(image.shape, np.uint8) for i in range(3): denoised_image[:,:,i] = convolve2d(noisy_image[:,:,i], kernel, mode='same', boundary='symm') return denoised_image ``` 以上就是一个简单的对泊松噪声图像进行去噪的函数。当然,这只是一个基础的实现,实际应用中可能会有更加复杂的情况和需求,需要根据具体情况进行调整和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值