Find zero crossings for a given 2D curve.

버전 1.0.1 (29.7 KB) 작성자: Peter Seibold
The code is very simple and needs only one line for basic results.
다운로드 수: 40
업데이트 날짜: 2022/7/21

라이선스 보기

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!
버전 게시됨 릴리스 정보
1.0.1

Some changes in demo.

1.0.0