import numpy, scipy, matplotlib.pyplot as plt, urllib, IPython.display
plt.rcParams['figure.figsize'] = (14,5)
The zero crossing rate indicates the number of times that a signal crosses the horizontal axis.
Let's load a signal:
x, fs = librosa.load('simple_loop.wav')
Listen to the signal:
IPython.display.Audio(x, rate=fs)
Plot the signal:
librosa.display.waveplot(x, sr=fs)
Let's zoom in:
plt.plot(x[1500:2000])
I count three zero crossings. Let's compute the zero crossings using librosa.
zero_crossings = librosa.zero_crossings(x[1500:2000], pad=False)
That computed each individual zero crossing. To find the total number of zero crossings, use sum
:
print sum(zero_crossings)
To find the zero-crossing rate over time, use zero_crossing_rate
:
zcrs = librosa.feature.zero_crossing_rate(x)
print zcrs.shape
Plot the zero-crossing rate:
plt.plot(zcrs[0])