高通滤波的python代码
时间: 2024-06-23 20:01:56 浏览: 7
在Python中,我们可以使用NumPy和SciPy库来实现高通滤波。高通滤波器是一种数字信号处理技术,它允许高频信号通过而抑制低频信号。以下是一个简单的高通滤波的实现,使用了IIR(无限 impulse response)滤波器设计:
```python
import numpy as np
from scipy.signal import butter, lfilter
def butter_highpass(cutoff, fs, order=5):
nyq = 0.5 * fs
normal_cutoff = cutoff / nyq
b, a = butter(order, normal_cutoff, btype='high', analog=False)
return b, a
def high_pass_filter(data, cutoff_freq, sample_rate, order=5):
b, a = butter_highpass(cutoff_freq, sample_rate, order=order)
filtered_data = lfilter(b, a, data)
return filtered_data
# 使用示例
data = np.random.rand(1000) # 假设这是你要滤波的数据
cutoff_freq = 0.1 * sample_rate # 高通截止频率,这里假设sample_rate是100Hz
filtered_data = high_pass_filter(data, cutoff_freq, sample_rate)