find exactly "0" for real data is almost impossible if not impossible.
What I do is look for a change in sign.
For a positive going zero crossing:
start a FOR loop from 1 to the sizeof the array
use this variable (prob i) to index the matrix/array
keep incrementing throught the array until the value at that location is negative.
When it is negative, then start incrementing and wait until the value becomes greater than zero (ie positive).
I have a matlab fn that does this at work, but it is 7pm here now and you will have to wait until tomorrow
%############################################
%# Function to find position of the positive going zero #
%# crossing of supplied data #
%############################################
function offset = zero_cross(volts,offset)
swt = 0;
while ( swt == 0 )
if (offset+1 >= size(volts,1))
swt = 1;
else
offset = offset + 1;
end
if (offset+1 >size(volts,1) )
swt = 1;
end
if( volts(offset)<=0)
if( volts(offset+1)>=0)
swt = 1;
end;
end
end