消除算法中的噪声

发布于 2025-01-03 12:48:40 字数 618 浏览 1 评论 0原文

我本质上有一堆数据对象,它们将时间戳(以毫秒为单位)映射到浮点值。我希望本质上找到给定范围内数据的峰值/最大值。我基本上一直在使用这样的东西:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

¢蛋碎的人ぎ生 2025-01-10 12:48:40

有两个问题:

  1. 滤除噪音;
  2. 找到峰值。

看来您已经有了 2 的解决方案,并且需要解决 1 的问题。

要滤除噪音,您需要某种 低通滤波器移动平均线就是这样的一个过滤器。例如,指数移动平均线非常容易实现并且应该运行良好。

总之:将您的系列通过过滤器,然后应用峰值查找算法。

There are two issues:

  1. filtering out the noise;
  2. finding the peak.

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.

浅语花开 2025-01-10 12:48:40

在数组(任何数值数组:int、double)中查找单个峰值(或最高值)的更简单方法是循环遍历数组并将变量设置为最高值...

示例:(所有示例都使用 我使用了这种

float highest = 0; //use a number equal to or below the lowest possible value
for (int i = 0; i < data.length; i++){
    if (data[i] > highest){
        highest = data[i];
    }
}

方法:

boolean[] isPeak = new boolean[20]; // I am looking for 20 highest peaks
float[] filter = new float[9]; // the range to which I want to define a peak is 9
float[] peaks = new float[20]; // again the 20 peaks I want to find
float lowpeak = 100; // use a value higher than the highest possible value
// first we start the filter cycling through the data
for (int i = 0; i < data.length; i++){
    for (int a = filter.length-1; a > 0; a--){
        filter[a] = filter[a-1];
    }
    filter[0] = data[1]
    // now we check to see if the filter detects a peak
    if (filter[4]>filter[0] && filter[4]>filter[1] && filter[4]>filter[2] &&
            filter[4]>filter[3] && filter[4]>filter[5] && filter[4]>filter[6] &&
            filter[4]>filter[7] && filter[4]>filter[8]){
        // now we find the lowest peak
        for (int x = 0; x < peaks.lengt-1; x++){
            if (peaks[x] < lowpeak){
                lowpeak = peaks[x];
            }
        }
        // now we check to see if the peak is above the lowest peak 
        for (int x = 0; x < peaks.length; x++){
            if (peaks[x] > lowpeak && peaks[x] != peaks[x+1]){
                for (int y = peaks.length-1; y > 0 && !isPeak[y]; y--){
                peaks[y] = peaks[y-1];
                }
                peaks[0] = filter[4];
            }
        }
    }
}

这可能不是最有效的方法,但它可以完成工作!

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")

float highest = 0; //use a number equal to or below the lowest possible value
for (int i = 0; i < data.length; i++){
    if (data[i] > highest){
        highest = data[i];
    }
}

to find multiple peaks in noisy data filtering some of the noise out I used this method:

boolean[] isPeak = new boolean[20]; // I am looking for 20 highest peaks
float[] filter = new float[9]; // the range to which I want to define a peak is 9
float[] peaks = new float[20]; // again the 20 peaks I want to find
float lowpeak = 100; // use a value higher than the highest possible value
// first we start the filter cycling through the data
for (int i = 0; i < data.length; i++){
    for (int a = filter.length-1; a > 0; a--){
        filter[a] = filter[a-1];
    }
    filter[0] = data[1]
    // now we check to see if the filter detects a peak
    if (filter[4]>filter[0] && filter[4]>filter[1] && filter[4]>filter[2] &&
            filter[4]>filter[3] && filter[4]>filter[5] && filter[4]>filter[6] &&
            filter[4]>filter[7] && filter[4]>filter[8]){
        // now we find the lowest peak
        for (int x = 0; x < peaks.lengt-1; x++){
            if (peaks[x] < lowpeak){
                lowpeak = peaks[x];
            }
        }
        // now we check to see if the peak is above the lowest peak 
        for (int x = 0; x < peaks.length; x++){
            if (peaks[x] > lowpeak && peaks[x] != peaks[x+1]){
                for (int y = peaks.length-1; y > 0 && !isPeak[y]; y--){
                peaks[y] = peaks[y-1];
                }
                peaks[0] = filter[4];
            }
        }
    }
}

this may not be the most efficient way to do this but it gets the job done!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文