python - 如何使用平滑和过滤技术从一组测量中生成估计值
问题描述
我对平滑/过滤传感器数据/计算值比较陌生。
我想在给定的时间轴上使用 pandas 的测量数据框生成类似下面的曲线。
我的数据是这样的:
charge_cycle cumulative_chargetime_Ah calculated_res
1 0.002199 0.075790
2 0.003123 0.071475
3 0.007699 0.097084
4 0.012086 0.050456
5 0.016609 0.077575
... ... ...
123169 478.228427 0.110583
123170 478.236834 0.139948
123171 478.239822 0.121189
123172 478.242608 0.144464
123173 478.251933 0.115232
我想要得到的输出如下所示。蓝色嘈杂的 computed_res 类似变量是我目前拥有的,它显然非常嘈杂,我需要对此进行某种形式的过滤以生成更有用的变量。红色图,我知道我可以使用内插法生成或通过在其上拟合一维多项式。
但是我真的不确定如何生成估计值,这是覆盖原始数据图的蓝色粗散点图。我可以就如何获得这个“估计值”获得一些建议吗?
我认为它确实与过滤有关,但我不确定如何将其应用于此用例。
解决方案
这确实看起来像是应用于测量值的某种过滤。这是一个使用savgol_filter
from的示例SciPy
。
import numpy as np
from scipy.signal import savgol_filter
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_context("paper", font_scale=2.5)
sns.set_style('whitegrid')
sns.set_palette("Set1")
N = 200
T = 1/200
rnd = np.random.RandomState(12345)
x = np.linspace(0.0, 2*N*T, N)
signal = np.sin(np.pi*x)
noisy_signal = signal + rnd.normal(0, 1, N)
filtered = savgol_filter(noisy_signal, window_length=31, polyorder=1)
plt.figure(figsize=(8, 4))
sns.lineplot(x, noisy_signal, label='Noisy', lw=0.5)
sns.lineplot(x, filtered, label='Filtered', lw=2);
ax = sns.regplot(x, noisy_signal, order=3, label='Best fit', scatter_kws={'s':2})
ax.legend(loc="best");
推荐阅读
- url - 获取错误的 URL
- python - pyOpenGL 2D 图像倾斜绘制
- r - 是否有 R 函数来创建 Square 序列
- python-3.x - 如何在 Python 中打印马拉地语字符“”?
- oracle - Apache Kafka 用于使用 Oracle DB 的现有获取请求
- vue.js - 导出变量时如何解决 ESLint 的“首选默认导出”错误?
- javascript - API弹出窗口中的按钮不触发功能,传单路由机
- spark-ar-studio - 在 Spark AR 中,如何根据处于活动状态的摄像头启用不同的自定义指令?
- regex - 如何在 Emacs 的注释中不突出显示值?
- python - 从字典中绘制多个数字