%% zerocount %% return the number of "interpolated" zeros between samples of a periodic function function z = zerocount(X) eps = 10^(-10); X = X(:); % put in column vector form N = length(X); Y = [X(2:N);X(1)] ; XY = X.*Y; % sign changes where this is negative or zero z1 = length(find(XY < -eps)); % a zero between samples z2 = length(find(abs(XY) <= eps)); % an approximate zero at a sample, the zero is double counted. z = z1+z2/2;