[英]Find local “flat” in addition to local maxima and minima of noised data
有一个包含 10,000 条记录计数的时间应力谱。
以 10e-5 到 1HZ 的随机频率记录时间戳压力。
一开始我试图找到:
我搜索了 web,常用的方法是去噪并找到局部最大值和最小值。
另一方面,我以以下方式(在 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;
}
现在频谱由峰 - 谷类型的点表示。
但是如果图片中间有一些区域是平坦的。 过度简化忽略了平坦区域并歪曲了峰谷的斜率/(或频率)。
是否有一些简单的算法可以将原始信号转换为峰平谷类型的表示?
我对DSP相当陌生。 提前感谢您的任何建议和反馈。
一个想法是:
这是一个实现,其中包含与您在问题中所描绘的类似的数据集的演示,但它的结构是[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");
<canvas width="500" height="180"></canvas>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.