Sunday, March 18, 2018
How to find zero crossing rate using pyAudio
That's a lot of unnecessary multiplication. Using a Boolean comparison and running it through np.diff
will probably be faster:
zero_crosses = np.nonzero(np.diff(audioData > 0)))[0]
What this is doing:
- creates a boolean array of where the signal is above 0 (
audioData > 0
) - does a pairwise difference (
np.diff
) so locations of zero crossings become 1 (rising) and -1 (falling) - picks the index of the array where those nonzero values are (
np.nonzero
).
Then if you want the number of crossings, you can just take zero_crosses.size
.
As a bonus you have the timings of all the crosses so you can do things like a histogram that shows where more crosses are happening in your time history.
Subscribe to:
Posts (Atom)