File Exchange

image thumbnail

Zero Crossing Rate

version (1.24 KB) by Jose R Zapata
Calculates the Zero Crossing Rate for a array of values, work for vector and matrix


Updated 03 Jun 2011

View License

Zero Crossing Rate
Works for vector and matrix
Vectorized function,very fast

if x is a Vector returns the zero crossing rate of the vector
Ex: x = [1 2 -3 4 5 -6 -2 -6 2];
y = ZCR(x) -> y = 0.444

if x is a matrix returns a row vector with the zero crossing rate of
the columns values

By: Jose Ricardo Zapata
Universidad Pontificia Bolivariana

Cite As

Jose R Zapata (2021). Zero Crossing Rate (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (6)

Kwaku Owusu

Hi Jose,

Please, I have an acoustic signal and I would like to find the ZCR of the signal. I realised ZCR function is not in Matlab.
I tried your code but seems to give an error message. Please, any help.

Thank you.

Yingming Gao

Rownaq Tahia


very neat, thanks! if x is a matrix, and number of cols > number of rows, length(x) is incorrect. here's a bugfix for that, with some additional asserts. :)

function y = zcr(x)
assert( ismatrix(x) );

[M,N] = size(x);

if isvector(x)
L = length(x);
assert( M>=2 && N>=2 );
L = M;
assert( L >= 1 );

y = sum(abs(diff(x>0))) / L;



Thank you for this post. Very efficient.
I have an addition, if you replace x>0, by x>threshold, you can use a threshold for hysteresis. So for example if threshold == 10, a crossing will only be detected if the signal went from -10 to +10 or +10 to -10.


Nice neat implementation, thanks for uploading

MATLAB Release Compatibility
Created with R2010a
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!