另外,这个算法对我来说也很好…
sensitivity = 4;
dwindow = 4;
k = dwindow;
data = [1., 1., 1., 1., 1., 1., 1., 1.1, 1., 0.8, 0.9,
1., 1.2, 0.9, 1., 1., 1.1, 1.2, 1., 1.5, 1., 3.,
2., 5., 3., 2., 1., 1., 1., 0.9, 1., 1., 3.,
2.6, 4., 3., 3.2, 2., 1., 1., 1., 1., 1.
];
//data = data.concat(data);
//data = data.concat(data);
var data1 = [{
name: 'original source',
y: data
}];
Plotly.newPlot('stage1', data1, {
title: 'Sensor data',
yaxis: {
title: 'signal'
}
});
filtered = data.map((a,b,c)=>a>=Math.max(...c.slice(b-k,b))?a**3:0);
var data2 = [{
name: 'filtered source',
y: filtered
}];
Plotly.newPlot('stage2', data2, {
title: 'Filtered data<br>aₙ = aₙ³',
yaxis: {
title: 'signal'
}
});
dwindow = 6;
k = dwindow;
detected = filtered.map((a,b,c)=>a>Math.max(...c.slice(2))/sensitivity).map((a,b,c)=>(b>k) && c.slice(b-k,b).indexOf(a)==-1 );
var data3 = [{
name: 'detected peaks',
y: detected
}];
Plotly.newPlot('stage3', data3, {
title: 'Maximum in a window of 6',
yaxis: {
title: 'signal'
}
});
dwindow = 10;
k = dwindow;
detected = filtered.map((a, b, c) => a > Math.max(...c.slice(2)) / 20).map((a, b, c) => (b > k) && c.slice(b - k, b).indexOf(a) == -1)
var data4 = [{
name: 'detected peaks',
y: detected
}];
Plotly.newPlot('stage4', data4, {
title: 'Maximum in a window of 10',
yaxis: {
title: 'signal'
}
});
<script src="https://cdn.jsdelivr.net/npm/plotly.js@2.16.5/dist/plotly.min.js"></script>
<div id="stage1"></div>
<div id="stage2"></div>
<div id="stage3"></div>
<div id="stage4"></div>