我试图过滤/平滑从采样频率为50 kHz的压力传感器获得的信号.示例信号如下所示:

我想在MATLAB中获得由黄土获得的平滑信号(我没有绘制相同的数据,值不同).

我使用matplotlib的psd()函数计算了功率谱密度,功率谱密度也在下面提供:

我尝试使用以下代码并获得过滤后的信号:
import csv
import numpy as np
import matplotlib.pyplot as plt
import scipy as sp
from scipy.signal import butter, lfilter, freqz
def butter_lowpass(cutoff, fs, order=5):
nyq = 0.5 * fs
normal_cutoff = cutoff / nyq
b, a = butter(order, normal_cutoff, btype='low', analog=False)
return b, a
def butter_lowpass_filter(data, cutoff, fs, order=5):
b, a = butter_lowpass(cutoff, fs, order=order)
y = lfilter(b, a, data)
return y
data = np.loadtxt('data.dat', skiprows=2, delimiter=',', unpack=True).transpose()
time = data[:,0]
pressure = data[:,1]
cutoff …Run Code Online (Sandbox Code Playgroud) 我正在按照食谱设计scipy中的带通滤波器.但是,如果我过多地降低滤波频率,我会在高阶滤波器中使用垃圾.我究竟做错了什么?
from scipy.signal import butter, lfilter
def butter_bandpass(lowcut, highcut, fs, order=5):
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
b, a = butter(order, [low, high], btype='band')
return b, a
if __name__ == "__main__":
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import freqz
# Sample rate and desired cutoff frequencies (in Hz).
fs = 25
# Plot the frequency response for a few different orders.
plt.figure(1)
plt.clf()
for order …Run Code Online (Sandbox Code Playgroud) 我想过滤掉20 Hz - 20000 Hz以外的所有信号.我正在使用巴特沃斯滤波器:
from scipy.io import wavfile
from scipy import signal
import numpy
sr, x = wavfile.read('sweep.wav')
nyq = 0.5 * sr
b, a = signal.butter(5, [20.0 / nyq, 20000.0 / nyq], btype='band')
x = signal.lfilter(b, a, x)
x = numpy.float32(x)
x /= numpy.max(numpy.abs(x))
wavfile.write('b.wav', sr, x)
Run Code Online (Sandbox Code Playgroud)
我注意到它适用于44.1 khz文件,但没有96 khz WAV文件(这里是演示文件)(它不是音频I/O问题):输出是空白(静音)或爆炸(有些其他输入wav文件).
1)是否存在使Butterworth滤波器不能用带通[b1,b2] b2 <0.5的东西?
2)更一般地说,如何使用Python/scipy进行过滤以保持20 - 20000Hz?(没有其他外部库)