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);
引用格式
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. 检索来源 .
MATLAB 版本兼容性
创建方式
R2022a
兼容任何版本
平台兼容性
Windows macOS Linux标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!