平滑来自传感器的数据 [英] Smoothing data from a sensor

查看:193
本文介绍了平滑来自传感器的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个3D传感器,可以测量v(x,y,z)数据。我只使用x和y数据。只需平滑x和y就足够了。

I have a 3D sensor which measures v(x,y,z) data. I'm only using the x and y data. Smoothing only x and y would be enough.

如果我使用日志显示数据,它将显示如下信息:
(时间)0.1。 ..(数据日志)x = 1.1234566667
(时间)0.2 ...(数据日志)x = 1.1245655666
(时间)0.3 ...(数据日志)x = 1.2344445555

If I use a log to show the data, it shows me something like this: (time) 0.1 ... (Data log) x = 1.1234566667 (time) 0.2 ... (Data log) x = 1.1245655666 (time) 0.3 ... (data log) x = 1.2344445555

实际上数据更精确,但是我想在1.1234值和1.2344值之间进行平滑处理,因为对我来说,它是相同的,所以我可以使用整数到,只显示 x = 1,但我也需要小数,因此,我需要在此处显示一种平滑值。

Well the data is more exact actually, but I want to smooth between the 1.1234 value and the 1.2344 value, because for me it's the same, I can use integers to, showing only "x= 1" but I need the decimals too, then, I need to show a sort of "smoothed" value here.

有人知道吗?我正在用C#编程,但并非所有功能都可以正常工作,因此我需要构建自己的功能。

Anyone has any idea? I'm programming in c# but not all the functions are working, so I need to build my own function.

推荐答案

最简单的方法是对数据进行移动平均。也就是说,保留传感器数据读数的数组并取平均值。诸如此类(伪代码):

The simplest is to do a moving average of your data. That is, to keep an array of sensor data readings and average them. Something like this (pseudocode):

  data_X = [0,0,0,0,0];

  function read_X () {
      data_X.delete_first_element();
      data_X.push(get_sensor_data_X());
      return average(data_X);
   }

这样做需要权衡。使用的数组越大,结果将越平滑,但结果与实际读数之间的滞后时间越大。例如:

There is a trade-off when doing this. The larger the array you use, the smoother the result will be but the larger the lag between the result and the actual reading is. For example:

                           /\_/\
                        /\/     \_/\
  Sensor reading:  __/\/            \/\
                                       \/\  _/\___________
                                          \/
                              _
                           __/ \_
                       ___/      \__
  Small array:     ___/             \_/\_       _
                                         \   __/ \________
                                          \_/

                                 ____
                              __/    \__
                           __/           \__
  Large array:     _______/                 \__      __
                                               \_   /  \__
                                                 \_/


(forgive my ASCII-ART but I'm hoping it's good enough for illustration).

如果您想要快速响应但无论如何都能保持良好的平滑度,则使用的是加权平均值数组。这基本上是数字信号处理(带有大写DSP),与它的名称相反,它与模拟设计更紧密相关。这是一篇简短的维基百科文章(带有良好的外部链接,如果您想走这条路,则应阅读该文章): http://zh.wikipedia.org/wiki/Digital_filter

If you want fast response but good smoothing anyway then what you'd use is a weighted average of the array. This is basically Digital Signal Processing (with capital DSP) which contrary to its name is more closely related to analog design. Here's a short wikipedia article about it (with good external links which you should read if you want to go down this path): http://en.wikipedia.org/wiki/Digital_filter

以下是一些有关低通滤波器的代码,它们可能适合您的需求:< a href = https://stackoverflow.com/questions/344343/low-pass-filter-software>低通滤波器软件?。请注意,在该答案的代码中,他正在使用大小为4 (或信号处理术语中为4的数组),因为此类滤波器称为四阶滤波器,实际上可以通过四阶多项式方程来建模:ax ^ 4 + bx ^ 3 + cx ^ 2 + dx)

Here's some code from SO about a low pass filter which may suit your needs: Low pass filter software?. Notice that in the code in that answer he's using an array of size 4 (or order 4 in signal processing terminology because such filters are called fourth-order filter, it can actually be modeled by a 4th order polynomial equation: ax^4 + bx^3 + cx^2 + dx).

这篇关于平滑来自传感器的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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