How to find the zero crossing in x and time data sets?
Ältere Kommentare anzeigen
How can I find the zero crossing in the data sets?
figure()
plot(x,t)
3 Kommentare
Scott MacKenzie
am 9 Jun. 2021
Nice plot. Just look at it -- you can easily find where the line crosses 0. Is there something else you might be looking for?
vimal kumar chawda
am 10 Jun. 2021
Rena Berman
am 25 Aug. 2021
(Answers Dev) Restored edit
Akzeptierte Antwort
Weitere Antworten (2)
Stefan Schuberth
am 27 Jul. 2022
Bearbeitet: Stefan Schuberth
am 27 Jul. 2022
2 Stimmen
If you have (x,y) data and want to do it without using loops try that:
i=find(y(1:end-1).*y(2:end)<0); % index of zero crossings
m=(y(i+1)-y(i))./(x(i+1)-x(i)); % slope
x0=-y(i)./m+x(i); % x coordinates of zero crossings linear interpolated
Joel Lynch
am 9 Jun. 2021
Bearbeitet: Joel Lynch
am 9 Jun. 2021
idx = find( f(2:end).*f(1:end-1)<0 )
Will return the left-hand indicies of cross-over points.
To get the exact X-values where the cross-over occurs, you would have to do some linear intepolation (inverted)
t_zero = zeros(size(idx));
for i=1:numel(idx)
j = idx(i); % Need both the index in the idx/t_zero vector, and the f/t vector
t_zero(i) = interp1( f(j:j+1), t(j:j+1), 0.0, 'linear' );
end
Note: this will fail if the cross-over happens on the last i value (i+1 would extend outside the range of the dataset)
4 Kommentare
vimal kumar chawda
am 10 Jun. 2021
Joel Lynch
am 10 Jun. 2021
Simplest solution is to put the interpolation line in an if statement
if j< numel(f)
% do j:j+1 interpret
else
t_zero(i) = interp1( f(j-1:j), t(j-1;j), 0.0, 'linear' );
end
or something similar
vimal kumar chawda
am 11 Jun. 2021
Scott MacKenzie
am 11 Jun. 2021
Bearbeitet: Scott MacKenzie
am 29 Jun. 2021
Yes, Joel's code gives the exact cross-over point. Bear in mind, however, that this is exact for the linearly interpolated data. The actual data are empirical, so it is not possible to know the exact cross-over point.
It probably doesn't matter much in this case, since the data appear to be gathered at a high sampling rate.
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
