【问题标题】:Find local "flat" in addition to local maxima and minima of noised data除了噪声数据的局部最大值和最小值之外,还找到局部“平坦”
【发布时间】:2020-07-04 06:26:13
【问题描述】:

有一个包含 10,000 条记录计数的时间压力谱。

以 10e-5 到 1HZ 的随机频率记录时间戳压力。

一开始我试图找到:

  • 局部峰谷,波动高于某个阈值(例如 0.6 个单位)。
  • 只是一种极其简单的方法,可以滤除一些噪音并记录压力的显着变化。

我在网上搜索,常见的方法是去噪并找到局部最大值和最小值。

另一方面,我以以下方式(在 Javascript 中)实现的遗留代码。

  function filtSpectrum(res, minor){  
    var filted = []; //array of filted minor cycles
    var lookformax = 1; // 1 for look for max, 0 for look for min
    var currentstress;
    var mx_index = 0;
    var mn_index = 0;
  
    for (var i=0; i < arrayLength; i++){
      currentstress = res[i].psi;
      if(currentstress > res[mx_index].psi){
        mx_index = i;
      }
      if (currentstress < res[mn_index].psi){
        mn_index = i;
      }
      if(lookformax === 1){
        if(currentstress < res[mx_index].psi - minor){
          filted.push(res[mx_index]);
          mn_index = i;
          lookformax =0;
        }
      }else if (currentstress > res[mn_index].psi + minor){
        filted.push(res[mn_index]);
        mx_index = i;
        lookformax = 1;
      }
    }
    return filted;
  }

输出如下图的结果是没有问题的

现在频谱由峰-谷类型的点表示。

但是如果图片中间有一些区域是平坦。过度简化忽略了平坦区域,并歪曲了峰谷的斜率/(或频率)。

是否有一些简单的算法可以将原始信号转换为 peak-flat-valley 类型的表示?

我对 DSP 比较陌生。提前感谢您的任何建议和反馈。

就像下图中的红色虚线一样。

【问题讨论】:

  • 你能在这张图中画出你想要的吗?
  • @appleapple 谢谢,问题中添加了所需的图表。
  • 您需要更详细地定义 flat 的含义,例如,为什么开头部分不被视为 flat (或者为什么会这样偏离实际值)?为什么开始部分和您现在拥有的部分没有组合为单个flat?公寓允许一些坡度吗?
  • 想一想当你想要匹配对数曲线时会发生什么也可能会有所帮助?罪恶曲线?方波?
  • @appleapple 谢谢。开始部分将以同样的方式处理。抱歉,我只标记了中间区域以供说明。理想情况下,公寓应该是平坦的,没有坡度。只有峰值和谷点(以及可能的平坦点)是必需的信息。点之间的线仅用于说明目的。对不起,我在图表中用直线连接了点,使它看起来像曲线拟合。

标签: javascript c++ algorithm signal-processing data-processing


【解决方案1】:

一个想法是:

  • 始终选择系列的第一个和最后一个点
  • 寻找与通过这两个端点的线最大偏离的点,并选择该点。
  • 在新选择的点将系列分成两部分,这样该点是第一个子系列中的最后一个,第二个子系列中的第一个。然后使用递归将上述算法应用于这两个子系列。
  • 当发现的最大偏差小于阈值时停止递归。在这种情况下,只保留端点。

这是一个实现,其中包含与您在问题中所描绘的类似的数据集的演示,但它的结构是一个简单的 [x, y] 对数组,因为我无法从您的问题中完全看到您的数据结构如何(但y 似乎对应于psi):

function simplify(polyline, maxdy) {
    function recur(first, last) {
        let [x0, y0] = polyline[first];
        let [x1, y1] = polyline[last];
        let m = (y1 - y0) / (x1 - x0);
        let localMaxdy = 0;
        let choice = 0;
        for (let i = first + 1; i < last; i++) {
            let [x, y] = polyline[i];
            let dy = Math.abs(y0 + m*(x - x0) - y);
            if (dy > localMaxdy) {
                choice = i;
                localMaxdy = dy;
            }
        }
        return localMaxdy < maxdy ? [[x0, y0]] // Only keep first point
               : recur(first, choice).concat(recur(choice, last));
    }        
    return recur(0, polyline.length - 1).concat(polyline.slice(-1)); // always add last point
}

const ctx = document.querySelector('canvas').getContext('2d');

function drawPolyline(polyline, color) {
    ctx.lineWidth = 1.5;
    ctx.strokeStyle = color;
    ctx.beginPath();
    for (const [x, y] of polyline) ctx.lineTo(x, y);
    ctx.stroke();
}

// Demo
let data = [[0,0],[81.5,1.5],[97.5,7.5],[98,8.5],[113,10.5],[113.5,12],[123,10.5],[127.5,12],[131.5,13.5],[132.5,15.5],[133,10],[133.5,30],[136,14.5],[138,15.5],[139.5,20],[140.5,21.5],[141,33],[149,35.5],[149.5,37.5],[152,40],[152.5,41],[159.5,45],[167.5,46],[171.5,47.5],[208,48.5],[290.5,52.5],[322,56.5],[330.5,64.5],[335,66],[345,63.5],[347.5,61.5],[352,65],[362.5,66.5],[367.5,64.5],[369.5,66],[386,65],[390,66],[391,67.5],[392,76],[394,80],[396,151.5],[396.5,154],[398,155],[400,159],[401.5,152.5],[402.5,140],[403.5,137.5],[405.5,180],[407.5,168],[409,139.5],[410,129.5],[412,126.5],[413.5,127.5],[415,123],[415.5,117],[416.5,114],[417.5,105.5],[419,102.5],[419.5,96],[420.5,91.5],[422.5,89.5],[423.5,78],[424.5,71.5],[426,69],[429,77],[432,43.5],[433,50.5],[434,52.5],[435.5,51.5],[436,54.5],[439,57],[440.5,60.5],[442.5,58.5],[444.5,58],[446,56],[447,51.5]];

drawPolyline(data, "grey");
let simple = simplify(data, 10);
drawPolyline(simple, "red");
&lt;canvas width="500" height="180"&gt;&lt;/canvas&gt;

【讨论】:

    猜你喜欢
    • 2023-01-05
    • 2021-09-12
    • 1970-01-01
    相关资源
    最近更新 更多