Detect zero crossings
System object™ counts the number of times the signal crosses zero, or changes sign. To detect
if a signal in a given channel crosses zero, the object looks for the following conditions,
where, xi-l is the current signal value and
xi-1 is the previous signal value:
xi < 0 and xi-1 > 0
xi > 0 and xi-1 < 0
For some positive integer L, xi < 0, xi-l = 0, and xi-L-1 > 0, where .
For some positive integer L, xi > 0, xi-l = 0, and xi-L-1 < 0, where .
For the first input value, xi-1 and xi-2 are zero.
To count the number of times a signal crosses zero or changes sign:
Create the dsp.ZeroCrossingDetector object.
Call the object with arguments, as if it were a function.
To learn more about how System objects work, see What Are System Objects?
zero crossing detection object that calculates the number of times the signal crosses
zcd = dsp.ZeroCrossingDetector
input— Data input
Data input whose zero crossings are counted by the object, specified as a vector or a matrix.
zcdOut— Number of zero crossings
Number of zero crossings in the data input, returned as one of the following:
scalar –– When the data input is a column vector, the scalar output is the number of zero crossings in the data input..
row vector –– When the data input is a matrix, each element in the row vector output is the number of zero crossings in the corresponding column of the data input.
To use an object function, specify the
System object as the first input argument. For
example, to release system resources of a System object named
Note: If you are using R2016a or an earlier release, replace each call to the object with the equivalent
step syntax. For example,
Find the number of zero crossings in electrocardiogram data.
EcgData = ecg(500)'; zcd = dsp.ZeroCrossingDetector; numZeroCross = zcd(EcgData)
numZeroCross = uint32 4
plot(1:500,EcgData,'b',[0 500],[0 0],'r','linewidth',2)
Usage notes and limitations:
See System Objects in MATLAB Code Generation (MATLAB Coder).