powersys
Advanced Member level 1

zero crossing matlab
I found the following code to count the number of zero crossings in a signal. However, I don't understand how it works. Could someone pls explain the following code? Thanks.
I found the following code to count the number of zero crossings in a signal. However, I don't understand how it works. Could someone pls explain the following code? Thanks.
Code:
% ZC number of zero crossings in x
% [n] = zc(x) calculates the number of zero crossings in x
function [n] = zc(x)
s=sign(x);
t=filter([1 1],1,s);
n=(length(s)-length(find(t)))/length(s);