消除算法中的噪声
我本质上有一堆数据对象,它们将时间戳(以毫秒为单位)映射到浮点值。我希望本质上找到给定范围内数据的峰值/最大值。我基本上一直在使用这样的东西:
float previousValue = 0;
for (int i = 0; i < data.size(); i++) {
MyData value = data.get(i);
if (value.getData() < previousValue) {
// found the peak!
break;
} else {
previousValue = value.getData();
}
}
这个算法的唯一问题是它没有考虑噪声。本质上,我可以有这样的值:
[0.1025, 0.3000, 0.3025, 0.3500, 0.3475, 0.3525, 0.1025]
实际峰值位于 0.3525,但我上面的算法会将其视为 0.3500,因为它排在第一位。由于计算的性质,我不能只对数组执行 max()
并找出最大值,我需要找到在下降之前首先出现的最大值。
如何在考虑噪声差异的同时找到峰值?
I essentially have a bunch of data objects which map timestamps in milliseconds to float values. I'm looking to essentially find the peak/max of the data in a given range. I've been essentially using something like this:
float previousValue = 0;
for (int i = 0; i < data.size(); i++) {
MyData value = data.get(i);
if (value.getData() < previousValue) {
// found the peak!
break;
} else {
previousValue = value.getData();
}
}
The only problem with this algorithm is that it doesn't account for noise. Essentially, I could have values like this:
[0.1025, 0.3000, 0.3025, 0.3500, 0.3475, 0.3525, 0.1025]
The actual peak is at 0.3525, but my algorithm above would see it as 0.3500, as it comes first. Due to the nature of my calculations, I can't just do max()
on the array and find out the largest value, I need to find the largest value that comes first before it falls.
How can I find the top of my peak, while accounting for some variance in noise?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两个问题:
看来您已经有了 2 的解决方案,并且需要解决 1 的问题。
要滤除噪音,您需要某种 低通滤波器。 移动平均线就是这样的一个过滤器。例如,指数移动平均线非常容易实现并且应该运行良好。
总之:将您的系列通过过滤器,然后应用峰值查找算法。
There are two issues:
It seems like you already have a solution for 2, and need to solve 1.
To filter out the noise, you need some kind of low-pass filter. A moving average is one such filter. For example, exponential moving average is very easy to implement and should work well.
In summary: put your series through the filter, and then apply the peak finding algorithm.
在数组(任何数值数组:int、double)中查找单个峰值(或最高值)的更简单方法是循环遍历数组并将变量设置为最高值...
示例:(所有示例都使用 我使用了这种
方法:
这可能不是最有效的方法,但它可以完成工作!
an easier method to find a single peak (or the highest value) in an array (any numeric array: int, double) is to loop through the array and set a variable to the highest value...
Example: (all examples use a float array called "data")
to find multiple peaks in noisy data filtering some of the noise out I used this method:
this may not be the most efficient way to do this but it gets the job done!