如何“平滑” 数据并计算线梯度?
我正在从测量距离的设备读取数据。 我的采样率很高,因此我可以测量距离(即速度)的较大变化,但这意味着,当速度较低时,设备会提供许多相同的测量结果(由于设备的粒度)。 这会产生“阶梯式”曲线。
我需要做的是平滑曲线以计算速度。 接下来我需要计算加速度。
如何最好地解决这个问题?
(采样率高达1000Hz,计算率10Hz就可以了。在VS2005中使用C#)
I'm reading data from a device which measures distance. My sample rate is high so that I can measure large changes in distance (i.e. velocity) but this means that, when the velocity is low, the device delivers a number of measurements which are identical (due to the granularity of the device). This results in a 'stepped' curve.
What I need to do is to smooth the curve in order to calculate the velocity. Following that I then need to calculate the acceleration.
How to best go about this?
(Sample rate up to 1000Hz, calculation rate of 10Hz would be ok. Using C# in VS2005)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
moogs 的维基百科条目是平滑数据的一个很好的起点。 但这并不能帮助你做出决定。
这完全取决于您的数据以及所需的处理速度。
移动平均线
将使最高值变平。 如果您对最小值和最大值感兴趣,请不要使用此值。 另外,我认为使用移动平均值会影响您对加速度的测量,因为它会使您的数据(稍微)变平,从而加速度会显得更小。 这一切都取决于所需的准确性。
萨维茨基-戈莱
快速算法。 与移动平均线一样快。 这将保留山峰的高度。 实施起来有些困难。 并且您需要正确的系数。 我会选这个。
卡尔曼滤波器
如果您知道分布,这可以给您带来良好的结果(它用于 GPS 导航系统)。 也许实施起来有些困难。 我提到这一点是因为我过去使用过它们。 但对于这类事情的初学者来说,它们可能不是一个好的选择。
上述措施将减少信号中的噪音。
接下来你要做的就是检测“加速度”的起点和终点。 您可以通过创建原始信号的导数来实现此目的。 导数与 Y 轴(零)相交的点可能是信号中的峰值,并且可能指示加速度的开始和结束。
然后,您可以创建二阶导数来获得最小和最大加速度本身。
The wikipedia entry from moogs is a good starting point for smoothing the data. But it does not help you in making a decision.
It all depends on your data, and the needed processing speed.
Moving Average
Will flatten the top values. If you are interrested in the minimum and maximum value, don't use this. Also I think using the moving average will influence your measurement of the acceleration, since it will flatten your data (a bit), thereby acceleration will appear to be smaller. It all comes down to the needed accuracy.
Savitzky–Golay
Fast algorithm. As fast as the moving average. That will preserve the heights of peaks. Somewhat harder to implement. And you need the correct coefficients. I would pick this one.
Kalman filters
If you know the distribution, this can give you good results (it is used in GPS navigation systems). Maybe somewhat harder to implement. I mention this because I have used them in the past. But they are probably not a good choice for a starter in this kind of stuff.
The above will reduce noise on your signal.
Next you have to do is detect the start and end point of the "acceleration". You could do this by creating a Derivative of the original signal. The point(s) where the derivative crosses the Y-axis (zero) are probably the peaks in your signal, and might indicate the start and end of the acceleration.
You can then create a second degree derivative to get the minium and maximum acceleration itself.
您需要一个平滑滤波器,最简单的是“移动平均值”:只需计算最后 n 个点的平均值。
这里的问题是,如何确定n,您能告诉我们更多有关您的应用的信息吗?
(还有其他更复杂的过滤器。它们根据保存输入数据的方式而有所不同。Wikipedia 中有一个很好的列表)
编辑!对于 10Hz,计算最后 100 个值的平均值。
You need a smoothing filter, the simplest would be a "moving average": just calculate the average of the last n points.
The question here is, how to determine n, can you tell us more about your application?
(There are other, more complicated filters. They vary on how they preserve the input data. A good list is in Wikipedia)
Edit!: For 10Hz, average the last 100 values.
移动平均线通常很糟糕 - 但对于白噪声却很有效。 移动平均线和移动平均线 Savitzky-Golay 都可以归结为相关性,因此速度非常快并且可以实时实施。 如果您需要一阶导数和二阶导数等更高阶信息 - SG 是一个不错的选择。 SG 的神奇之处在于滤波器所需的恒定相关系数 - 一旦确定了局部拟合多项式的长度和次数,只需找到一次系数。 您可以使用 R (sgolay) 或 Matlab 计算它们。
您还可以通过 Savitzky-Golay 最佳拟合多项式估计噪声信号的一阶导数(有时称为 Savitzky-Golay 导数),并且通常可以很好地估计一阶导数。
卡尔曼滤波非常有效,但计算量较大 - 很难在速度上击败短卷积!
保罗
中心空间软件
Moving averages are generally terrible - but work well for white noise. Both moving averages & Savitzky-Golay both boil down to a correlation - and therefore are very fast and could be implemented in real time. If you need higher order information like first and second derivatives - SG is a good right choice. The magic of SG lies in the constant correlation coefficients needed for the filter - once you have decided the length and degree of polynomial to fit locally, the coefficients need only to be found once. You can compute them using R (sgolay) or Matlab.
You can also estimate a noisy signal's first derivative via the Savitzky-Golay best-fit polynomials - these are sometimes called Savitzky-Golay derivatives - and typically give a good estimate of the first derivative.
Kalman filtering can be very effective, but it's heavier computationally - it's hard to beat a short convolution for speed!
Paul
CenterSpace Software
除了上述文章之外,还可以查看 Catmull-Rom 样条线。
In addition to the above articles, have a look at Catmull-Rom Splines.
您可以使用移动平均值来平滑数据。
You could use a moving average to smooth out the data.
除了上面的 GvS 优秀答案之外,您还可以考虑使用一些通用曲线拟合(例如三次或二次样条)来平滑/减少平均结果的步进效应。
In addition to GvSs excellent answer above you could also consider smoothing / reducing the stepping effect of your averaged results using some general curve fitting such as cubic or quadratic splines.