MATLAB: Finding zeroes of data

findfzero

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?

Best Answer

This is a routine I use to find as many zero-crossings in data as may exist. It interpolates or extrapolates from the points it identifies near the zero crossings to closely (linearly) approximate the actual zero crossings:
x = linspace(0,10*pi,1E+5); % Create Data

y = sin(10*pi*x.*cos(10*x).^2); % Create Data
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
dy = zci(y); % Indices of Approximate Zero-Crossings
for k1 = 1:size(dy,1)-1
b = [[1;1] [x(dy(k1)); x(dy(k1)+1)]]\[y(dy(k1)); y(dy(k1)+1)]; % Linear Fit Near Zero-Crossings
x0(k1) = -b(1)/b(2); % Interpolate ‘Exact’ Zero Crossing
mb(:,k1) = b; % Store Parameter Estimates (Optional)
end
It should work for your data without much, if any, modification. The zero-crossings are in the ‘x0’ vector.
Related Question