Signal flatline detection?
21 次查看(过去 30 天)
显示 更早的评论
Hello!
I am working with a few signals in matlab and want the code to detect when the signal line flattens out.
Any ideas as to how to go about this?
0 个评论
采纳的回答
Star Strider
2021-3-30
One option is to use the islocalmin (or related islocalmax) funciton, and set 'FlatSelection' to 'first'.
3 个评论
Star Strider
2021-3-30
My pleasure!
Another option would be to use the gradient function to calculate a numerical derivative, then threshold it to detect a 0 derivative. The only problem with that is that it could also detect peaks or valleys in an oscillating signal, so since I have no idea what the signal looks like, I am sugesting it as an alternative only.
The derivative would be calculated as:
dydx = gradient(y) ./ gradient(x);
assuming here that both are vectors.
Star Strider
2021-3-30
If the arguments are vectors, yes.
For example:
v = [5 3 9 2 NaN 4 7 6 Inf 1 8 5]
v = v(isfinite(v))
If they are 2D (or greater dimension) arrays, this is more difficult because ‘empty’ entries are not permitted in numeric arrays. Every position must have some value, with NaN being the default for missing data. Removing isolated values (a opposed to rows or columns) destroys the matrix structure. Cell arrays can have empty entries, however before using them in numeric computations, the values must be recovered from the cell arrays (since cell arrays can contain anything), so the problem recurs.
So again, if the data are vectors, this would work:
x = [5 3 9 2 NaN 4 7 6 Inf 1 8 5]
y = randi(9, size(x))
L = isfinite(x)
xc = x(L)
yc = y(L)
If you have specific data and you would like to share them, please upload them.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!