Find zero crossings for a given 2D curve.

The code is very simple and needs only one line for basic results.
37 téléchargements
Mise à jour 21 juil. 2022

Afficher la licence

PURPOSE:
Find zero crossings of a given 2D curve.
If the curve is noisy, you might consider to smooth it beforehand,
e.g. with https://mathworks.com/matlabcentral/fileexchange/66099
Full call:
ZeroX=FindZeroCrossSimple(x,y,Interpolate)
INPUTS:
1 x: x-values. Vector with numbers.
2 y: y-values. Vector with numbers.
Optional value:
You may omit it.
3 Interpolate: 0: x zero position is nearest sample left of zero crossing
1: x zero position is at nearest sample
2: linear interpolation(default)
Output:
Zerox: Vector with zero x-positions
Empty vector for no zeros at all.
Processing time on my PC for 10^6 samples and 3.4*10^5 zero crossings is:
0) x zero position left of zero crossing: 9 ms
1) x zero position is at nearest sample: 21 ms
2) linear interpolation (default): 21 ms
If you process always in the same manner, you can delete many code lines.
E.g. you want allways all x zero position left of zero crossing:
ZeroX=x(diff(sign(y))~=0);
Or you want allways all x zero position with linear interpolation:
Zindx = find(diff(sign(y)));
y1=y(Zindx);
ZeroX=(y1*(x(1)-x(2)))./(y(Zindx+1)-y1)+x(Zindx);
Or you want only ascending zero crosses with linear interpolation:
Zindx = find(diff(sign(y))>0);%ascending zero crossings.
% For desending: Zindx = find(diff(sign(y))<0);%descending zero crossings.
y1=y(Zindx);
ZeroX=(y1*(x(1)-x(2)))./(y(Zindx+1)-y1)+x(Zindx);

Citation pour cette source

Peter Seibold (2024). Find zero crossings for a given 2D curve. (https://www.mathworks.com/matlabcentral/fileexchange/114340-find-zero-crossings-for-a-given-2d-curve), MATLAB Central File Exchange. Récupéré le .

Compatibilité avec les versions de MATLAB
Créé avec R2022a
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Publié le Notes de version
1.0.1

Some changes in demo.

1.0.0