A thought you might want to consider:
if you multiply the current value, y(i) by the previous value y(i-1), this product is only negative when y(i) has crossed zero.
If y(i) and y(i-1) are both positive, the product is positive, likewise, if they are both negative, the product is positive.
zerocross = y(i)*y(i-1) < 0 ;
Now, if you care whether it's rising or falling, you need to test the sign on y(i)
rising = y(i) > 0 ;
falling = y(i) < 0 ;
You can make this a function :
function zerocross = detectzerocross(x)
zerocross = x*last>0;
last = x;
This function "remembers" the last value of x each time you call it.