%% zerocountdemo
%% return the number of "interpolated" zeros between samples of a periodic function
%% this demo shows graphs of function used to obtain the number of zeros

T = (0:31)/32;
X = sin(3*2*pi*T); 
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 
subplot(2,1,1)
plot(1:N,X,1:N,Y,1:N,XY,1:N,zeros(size(X)));
subplot(2,1,2)
plot(1:N,X,'+r',1:N,Y,'+g',1:N,XY,'ok',1:N,zeros(size(X)))
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;


   
   
