Chr*_*isG 7 python signal-processing
我使用以下代码在python中实现了高通滤波器:
from scipy.signal import butter, filtfilt
import numpy as np
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 butter_highpass_filter(data, cutoff, fs, order=5):
b, a = butter_highpass(cutoff, fs, order=order)
y = filtfilt(b, a, data)
return y
rawdata = np.loadtxt('sampleSignal.txt', skiprows=0)
signal = rawdata
fs = 100000.0
cutoff = 100
order = 6
conditioned_signal = butter_highpass_filter(signal, cutoff, fs, order)
Run Code Online (Sandbox Code Playgroud)
我在100 kHz电压信号上应用此滤波器,它对于> = 60 Hz的截止频率工作正常.但它在下面不起作用.我想切断低于10赫兹的所有频率.我的错误是什么提示?我观察到的是滤波器的阶数越低,截止频率就越低.
Kon*_*tov 14
我希望这可以帮助你:
import numpy as np
import pandas as pd
from scipy import signal
import matplotlib.pyplot as plt
def sine_generator(fs, sinefreq, duration):
T = duration
nsamples = fs * T
w = 2. * np.pi * sinefreq
t_sine = np.linspace(0, T, nsamples, endpoint=False)
y_sine = np.sin(w * t_sine)
result = pd.DataFrame({
'data' : y_sine} ,index=t_sine)
return result
def butter_highpass(cutoff, fs, order=5):
nyq = 0.5 * fs
normal_cutoff = cutoff / nyq
b, a = signal.butter(order, normal_cutoff, btype='high', analog=False)
return b, a
def butter_highpass_filter(data, cutoff, fs, order=5):
b, a = butter_highpass(cutoff, fs, order=order)
y = signal.filtfilt(b, a, data)
return y
fps = 30
sine_fq = 10 #Hz
duration = 10 #seconds
sine_5Hz = sine_generator(fps,sine_fq,duration)
sine_fq = 1 #Hz
duration = 10 #seconds
sine_1Hz = sine_generator(fps,sine_fq,duration)
sine = sine_5Hz + sine_1Hz
filtered_sine = butter_highpass_filter(sine.data,10,fps)
plt.figure(figsize=(20,10))
plt.subplot(211)
plt.plot(range(len(sine)),sine)
plt.title('generated signal')
plt.subplot(212)
plt.plot(range(len(filtered_sine)),filtered_sine)
plt.title('filtered signal')
plt.show()
Run Code Online (Sandbox Code Playgroud)
小智 8
由于我的声誉很低,我无法对您的问题发表评论 - “截止和过滤顺序之间有什么关系?” 这不是对您原始问题的回答。
对于 FIR 滤波器,对于给定的截止频率,脉冲响应图的斜率(|H(f)| vs f)对于高阶滤波器更陡峭。因此,要在不需要的频率范围内实现更高的衰减,您可以增加滤波器阶数。但是当滤波器阶数如此之高以至于脉冲响应是理想的盒函数时会发生什么?您将看到符号间干扰(数字通信中的 ISI)效果。当截止频率与采样频率的比值变小时,这种效应的强度会增加(想想频域中盒函数的宽度与正弦函数的主瓣宽度之间的关系)。
当我尝试在 TI DSP 微控制器上实现一个非常窄带的低通 IIR 滤波器时,我第一次观察到了这一点。TI 库将滤波器实现为级联双二阶结构,以处理众所周知的截断效应。这仍然没有解决问题,因为问题不仅仅是由于截断造成的。我解决这个问题的方法是使用抗混叠滤波器,然后对输入信号进行下采样,然后使用我想要的低通 IIR 滤波器。
我知道您正在实施 HPF,它是在频域中转换的 LPF。希望这能回答您的一些问题。让我知道下采样是否适合您。
| 归档时间: |
|
| 查看次数: |
26827 次 |
| 最近记录: |