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
Jose R Zapata (2020). Zero Crossing Rate (https://www.mathworks.com/matlabcentral/fileexchange/31663-zero-crossing-rate), MATLAB Central File Exchange. Retrieved .
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);
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