I was reading a piece of code from here:
def freq_from_ZCR(sig, fs):
# Find all indices right before a rising-edge zero crossing
indices = find((sig[1:] >= 0) & (sig[:-1] < 0))
crossings = interpolate(indices, sig)
return fs / np.mean(np.diff(crossings))
I want to check my understanding of this, as I doesn't really make sense right now. According to the mlab docs, find "returns the indices where some condition is true". I would like some explanation to how this works. As I see it now, (sig[1:] >= 0) & (sig[:-1] < 0) is a statement that is either true or false. Also, why is there a bitwise & there instead of an and?
Finally, if I assume that the first line returns an array of the indices right before a rising-edge zero crossing. Then we'll have something like (for example):
indices = [1, 4, 7, 11, 15]
It makes sense then to find the np.mean(np.diff(indices)). Why do we need the interpolate function and where is it from? From a quick search I didn't find anything.