Wave Upward Zero Crossing Function

This function detects an upward zero crossing of a given wave signal.
719 Downloads
Updated 3 Nov 2020

View License

WaveUpZeroCrossing
==================

.. code:: MATLAB

[H,T,Time,UpCrossIndex,UpCrossTime,UpCrossValue,TroughTime,TroughValue,CrestTime,CrestValue]=WaveUpZeroCrossing(x,crosslevel,fs,dispout)

Description
-----------

| Detects upward zero crossing of a given wave signal
| The code only detects a full oscillation.
| If the first or the last wave does not have a full oscillation (based on upward zero crossing method), code ignores them.
| This is done to prevent wrong period detection for the very first or last wave.
| This function is a part of and modified from the ScientiMate packages.
| For more information visit: www.arashkarimpour.com and https://scientimate.readthedocs.io

Inputs
------

x
Input wave time series (oscillatory) data
crosslevel='zero';
| Define to remove mean from input data or not ('yes': remove, 'no': not remove)
| 'zero': crossing is calculated respect to zero
| 'mean': crossing is calculated respect to a mean of the data
fs=1;
| Sampling frequency that data collected at in (Hz)
| If fs is not given, then default fs is fs=1;
| If fs=1, then index of data points represents time as well
dispout='no';
Define to display outputs or not ('yes': display, 'no': not display)

Outputs
-------

H
Wave height data series with same unit as input
T
Wave period data series (second)
Time
Time (second)
UpCrossIndex
Index of up-crossing location
UpCrossTime
Time of up-crossing location
UpCrossValue
Value of up-crossing
TroughTime
Time of wave trough location
TroughValue
Value of wave trough
CrestTime
Time of wave crest location
CrestValue
Value of wave crest

Examples
--------

.. code:: MATLAB

fs=2; %Sampling frequency
duration=32; %Duration of the data
N=fs*duration; %Total number of points
dt=1/fs; %Time difference, dt=1/fs
t(:,1)=linspace(0,duration-dt,N); %Time
x(:,1)=0.1+(0.5.*cos(2*pi*0.2*t)+(-0.1+(0.1-(-0.1))).*rand(N,1));
[H,T,Time,UpCrossIndex,UpCrossTime,UpCrossValue,TroughTime,TroughValue,CrestTime,CrestValue]=WaveUpZeroCrossing(x,'zero',fs,'yes');

References
----------

* http://www.arashkarimpour.com
* https://scientimate.readthedocs.io

Cite As

Arash Karimpour (2025). Wave Upward Zero Crossing Function (https://se.mathworks.com/matlabcentral/fileexchange/59342-wave-upward-zero-crossing-function), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2013b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.4.0.0

Performance improvement
Bug fix

1.0.1.0

Improved document

1.0.0.0

Performance improvement
Bug fix
Performance improvement
Bug fix
Performance improvement
Bug fix