Python中的信号拟合模型 [英] Signal fitting models in Python

查看:158
本文介绍了Python中的信号拟合模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在以下链接中共享了一个数据集:

I have a dataset shared in the following link:

https://drive.google.com/open?id=0B2Iv8dfU4fTUSV8wMmUwVGMyRE0

estimated_data.csv文件的简单绘图将生成以下绘图.

A simple plot of the estimated_data.csv file generates the following plot.

和一个简单的actual_data.csv情节(这是我的基本事实)会生成以下情节

and a simple plot of actual_data.csv (which is my ground truth) generates the following plot

当我们同时绘制实际信号和估计信号时,这就是我们得到的

When we plot both the actual and estimated signals together, this is what we got

我想找到估计信号和实际信号的最接近模式.我试图通过将数据加载到DataFrame中来找到使用pandas.rolling_max()的最接近模式,并计算最大滚动值,然后将整个序列转过来并向后计算窗口.这是我的Python脚本.

I wanted to find the closest pattern of the estimated and actual signals. I have tried to find the closest pattern using pandas.rolling_max() by loading the data into a DataFrame and calculate the rolling max and then turn around the whole series and to calculate the windows backwards. Hereunder is my Python script.

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
plt.ion()

df = pd.read_csv('estimated.csv', names=('x','y'))
df['rolling_max'] = df['y'].rolling(8500).max()
df['rolling_max_backwards'] = df['y'][::-1].rolling(850).max()
df.rolling_max.fillna(df.rolling_max_backwards, inplace=True)
plt.figure()
plt.plot(df['x'], df['rolling_max'], label = 'rolling')

plt.legend()
plt.title('Pattern')
plt.xlim(0,10)
plt.ylim(0,700)
plt.xlabel('Time [Seconds]')
plt.ylabel('Segments')
plt.grid()
plt.show(block=True)

最终会生成以下模式.

但是,当我将其与基本事实(actual_data.csv的图)进行比较时,我觉得这种模式不够接近.我们如何应用像Kalman Filter这样的过滤模型来找到类似信号的模式?

However, I don't feel this pattern is close enough when I compare it with my ground truth (the plot of actual_data.csv). How can we apply filtering models like Kalman Filter to find a pattern of such a signal?

推荐答案

卡尔曼滤波器对于输入数据具有真实平均值并添加了高斯噪声的情况非常有用.您可以测量或以其他方式知道随机噪声的方差,并将其作为测量噪声提供给算法.您的输入数据(称为估计信号")没有(平均)实际信号的值.它似乎有一个错误,导致它经常测量接近零,而很少高于实际值.它似乎只是超过实际值,以警告实际值将急剧下降.

A Kalman Filter is useful for input data which has the true mean value with Gaussian noise added. You measure or otherwise know the variance of the random noise and supply that to the algorithm as the measurement noise. Your input data (which you call "estimated signal") is does not have (on average) the value of your actual signal. It appears to have an error which causes it to measure near zero very often, and rarely higher than the actual value. It only appears to exceed the actual value as a warning that there is about to be a sharp drop in the actual value.

在这种情况下,卡尔曼过滤器不太可能为您提供帮助,因为此数据集强烈违反了其对输入数据的假设.最好的选择是改善输入数据(例如,在这种情况下,错误可能是由于传感器的缺陷引起的).如果这不可能,那么您自己对数据的直觉(最大滚动)比KF更符合行为.

In a case like this, a Kalman filter is unlikely to help you, because its assumptions about the input data are strongly violated by this dataset. Your best bet would be to improve your input data (in this case, for example, the error could be due to a flaw in a sensor). If that's not possible, your own intuition about the data (taking a rolling maximum) is more consistent with the behavior than a KF could be.

这篇关于Python中的信号拟合模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆