In [1]:
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:
In [2]:
x, fs = librosa.load('simple_loop.wav')
Listen to the signal:
In [3]:
IPython.display.Audio(x, rate=fs)
Out[3]:
Plot the signal:
In [4]:
librosa.display.waveplot(x, sr=fs)
Out[4]:
Let's zoom in:
In [5]:
plt.plot(x[1500:2000])
Out[5]:
I count three zero crossings. Let's compute the zero crossings using librosa.
In [6]:
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
:
In [7]:
print sum(zero_crossings)
To find the zero-crossing rate over time, use zero_crossing_rate
:
In [8]:
zcrs = librosa.feature.zero_crossing_rate(x)
print zcrs.shape
Plot the zero-crossing rate:
In [9]:
plt.plot(zcrs[0])
Out[9]: