finding zeroes of data
Show older comments
How do you find zeroes from data? I have two data sets, a for acceleration and t for time. I plotted acceleration with respect to time, and I want to find when the acceleration hits zero, so at what time. I know there is fzero, but that is mainly for functions and this is just a plot from data. Do I make the data into some sort of function or can I use the find function somehow?
Accepted Answer
More Answers (2)
Walter Roberson
on 28 Jul 2016
accpos = acceleration>0;
goes_nonpos = strfind(accpos, [1 0]);
now goes_nonpos is the index of locations where the acceleration is positive and then is non-positive immediately after (which might be 0 exactly or might have passed through to negative)
Generally when you use this kind of strfind() trick, you need to pay careful attention to the edge conditions: what do you want to do if the acceleration starts zero?
Also this pattern does not locate places where the acceleration stays 0 (or non-positive), which might be of interest to you. It is common to be interested not just in when it goes from positive to zero (perhaps by passing through on the way to negative) but also when it ends that and goes positive again. You can do that with a pair of strfind() but to you need to be think about the boundary conditions and also about whether you want to use equalities or inequalities for the comparisons.
Pietro Innocenzi
on 14 Nov 2022
Edited: Pietro Innocenzi
on 14 Nov 2022
0 votes
If you consider the absolute value of your signal, the minimum will be at zero. Now consider the opposite of the absolute value: the maxima will be your zeros. So you need to find the peaks of the opposite of the absolute value of your signal.
In one line:
[zeros, ind_zeros] = findpeaks(-abs(acceleration));
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!