【发布时间】:2019-12-13 19:11:25
【问题描述】:
我正在尝试对我的脉冲图的峰值数据点应用过滤器并将它们平滑,但它似乎不起作用。所需文件signal.csv
scipy savgol_filter
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from scipy.signal import find_peaks, savgol_filter
df = pd.read_csv('signal.csv')
df.plot(grid = 1,
c = (0,0,255/255),
linewidth = 0.5,
figsize = (10,5),
legend = False,
xlim = [df.index[0], df.index[-1]],
ylim = 0)
plt.xlabel('Zeit / ms')
plt.ylabel('UHF-Signal / mV')
plt.title('UHF')
x = df.T.to_numpy()[1]
peaks, _ = find_peaks(x, distance = 150, height = 4)
sgf = savgol_filter(peaks, 51, 3)
plt.plot(sgf, x[peaks], c = 'orange')
plt.plot(peaks, x[peaks], 'o', c = 'red')
plt.show()
scipy 黄油过滤器
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from scipy.signal import find_peaks, butter, filtfilt
df = pd.read_csv('signal.csv')
df.plot(grid = 1,
c = (0,0,255/255),
linewidth = 0.5,
figsize = (10,5),
legend = False,
xlim = [df.index[0], df.index[-1]],
ylim = 0)
plt.xlabel('Zeit / ms')
plt.ylabel('UHF-Signal / mV')
plt.title('UHF')
x = df['1'].values
peaks, _ = find_peaks(x, distance = 150, height = 4)
c, e = butter(10, 0.3)
z = filtfilt(c, e, peaks)
plt.plot(z, x[peaks], c = 'orange')
plt.plot(peaks, x[peaks], 'o', c = 'red')
plt.show()
如您所见,结果是相同的。我怎样才能平滑橙色线?我想要这样的东西:
提前致谢
【问题讨论】:
标签: python-3.x matplotlib filter scipy smoothing