电池电压显示的平滑功能可减少嵌入式系统中的尖峰
读取嵌入式设备中的电池电压。然而,实际电压根据系统负载的不同而变化很大。我们需要一种方法来减少电压的波动以显示最佳值。
目前,我们使用滚动/移动平均线。然而,在最近15次读数中,结果仍然波动太大。
在阅读有关平滑算法的内容时,似乎 B 样条、核滤波器或其他一些平滑算法是理想的。但是,我找不到一个不使用 numpy 或 mathcad 等内部函数的简单示例。
有人知道一个易于实现的函数可以帮助解决这个问题吗?这是一个 C++ 项目(使用 Qt 4.5),仅包含最少的库。我更愿意留在整数域(显示 3300-4200 之间的毫伏电压)。
TIA 麦克风
Reading a battery voltage in an embedded device. However, the actual voltage varies greatly depending upon system load. We need a method to reduce the fluctuation of the voltage to display the best value.
Currently, we're using a rolling/moving average. However, over the last 15 readings, the result still fluctuates too much.
In reading about smoothing algorithms, it appears that b-splines, kernel filters, or some other smoothing algorithms would be ideal. However, I can't find a simple example that doesn't use numpy or intrinsic functions within mathcad or some such.
Anybody know of a simple-to-implement function that could help with this? This is a C++ project (using Qt 4.5) with just the bar minimum of libraries. I'd prefer to stay in the integer domain (showing the voltage in millivolts from 3300-4200).
TIA
Mike
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
嗯,如果没有具体的情况,很难说出你需要什么。例如,您的传感器采样率是多少,以及您试图消除的传感器波动和噪声的特征如何?
但是,如果您已经实施了移动平均线,我可能建议尝试使用移动中位数。 (最后 n 个样本的中值,而不是平均值。)这往往会减少输出中与正常情况相比较大的短期偏差的影响。
如果您能找到有效的参数,那么根据 CPU 和内存要求,最好使用某种形式的离散时间低通滤波器。这些非常容易实现,只需要了解先前的输出值和当前输入即可计算当前输出。例如:(
其中
Y
是当前输出,Y[n-1]
是最后计算的输出,X
是最新的传感器)A
实际上是低通滤波器的时间常数,但它是离散时间,因此它取决于采样率。具体来说,A = dt / tau
,其中dt
是以秒为单位的采样周期,tau
大致类似于连续时间时间常数。Well, it's a bit tough to tell what you need without specifics on your situation. For example, what is your sensor sampling rate, and how is the sensor fluctuation and noise that you're trying to remove characterized?
However, if you already have moving average implemented, I might recommend trying a moving median instead. (Median of the last n samples, rather than average.) This will tend to reduce the impact of large short-term aberrations from normal from your output.
If you can find parameters that work, it would be preferrable for CPU and memory requirements to use some form of a discrete-time low-pass filter. These are quite easy to implement, and only require knowledge of the previous output value and the current input to compute the current output. For example:
(Where
Y
is the current output,Y[n-1]
is the last computed output, andX
is your latest sensor reading.)A
is effectively the time constant of the low pass filter, but it's discrete time, so it depends on the sampling rate. Specifically,A = dt / tau
, wheredt
is your sampling period in seconds, andtau
is roughly analagous to the continuous-time time constant.你可以在经典的NR书籍中找到解释和源代码:
http://apps.nrbook.com/c/index.html,
即第3章:
http://www.arcetri.astro.it/irlab /library/recipes/bookcpdf/c3-3.pdf
you can find explanations and source code in classical NR book:
http://apps.nrbook.com/c/index.html,
namely chapter 3:
http://www.arcetri.astro.it/irlab/library/recipes/bookcpdf/c3-3.pdf
您是否考虑过简单地对值应用倾斜限制?
Have you considered simply applying a skew limit to the value?
有可能深入了解信号处理技术和复杂的数学,但是您必须问自己是否真的有必要?
如果此显示是一个简单的瞬时数字输出,则用于“仅指示”,而不是说连续的图或数据日志(即您不需要重建信号),那么通常可以完全接受,只需采取一个<< em>周期性平均而不是移动平均值。由于这不需要历史记录存储,因此您可以平均使用任意数量的样本,这将取决于显示更新所需的频率。
它不是巧妙的,但通常足以适应该任务。这是对其使用的示例和测试模拟。
这种技术的完善将产生甚至更平稳的输出,但以相同的频率产生结果将是使用定期的平均输出作为移动平均过滤器的输入。如果您要在100个样本期间使用我的每秒100个示例,然后将其放入15个样本移动平均线,您将使用15秒的采样数据,同时每秒获得结果,几乎没有其他内存用法。
显然,您可以更改时期,移动平均长度和采样率,以在需要的更新频率下获得所需的结果。我建议您在需要更新的时期内采取尽可能多的样本,然后只要您想负担得起即可移动平均值。
It would be possible to get very deep into signal processing techniques and complex math, but you have to ask yourself if it is really necessary?
If this display is a simple instantaneous numeric output, used for "indication only" rather than say a continuous graph or data log (i.e. you do not need to reconstruct the signal), then it would often be perfectly acceptable, to simply take a periodic average rather than a moving average. Since that requires no history storage, you can average over as many samples as you wish, and this would be determined by the required frequency of display update.
It is not clever, but it is often adequate for the task. Here's an example and a test simulation of its use.
A refinement of this technique that will produce even smoother output but generate results at the same frequency would be use the periodic mean output as input to your moving average filter. If you were to use my 100 samples per second example with the 100 sample period, and then put it through your 15 sample moving average, you will have used 15 seconds worth of sampling data while still getting a result every second, with little additional memory usage.
Obviously you can change the period, the moving average length, and the sampling rate to get the results you need at the update frequency you need. I suggest that you take as many samples as you can for the period for which you need an update, then make the moving average as long as you wish to afford.
我知道这并不能直接回答你的问题,但是平均条有帮助吗?换句话说,显示 15 秒窗口内的最小值/最大值/平均值/中值,而不仅仅是平均值。
I know this doesn't directly answer your question, but would average bars help? In other words, show min/max/mean/median over say 15 second windows instead of just a mean.
对我来说这确实听起来像是硬件问题。是锂离子电池还是镍氢电池?放电曲线是什么样的?电池和 ADC 之间有哪些组件?在开始实施各种数字滤波器之前,您需要了解这些事情。
This really sounds like a hardware problem to me. Is it a Li-Io or NiMH battery? What does the discharge curve look like? What components are there between the battery cells and your ADC? You need to know these things before running off to implement various digital filters.
如果您没有答案,这是打印一些内容的好方法
在 pololu 3pi 等机器人上。
If you don't have your answer this is a good way to print out something
on a robot such as a pololu 3pi.