Hello I new with python and also with sound signal analysis. I am trying to get the envelope of a birth song (zebra finch). It has a very rapid signal fluctuations and I tried w
The envelope of a signal can be computed using the absolute value of the corresponding analytic signal. Scipy implements the function scipy.signal.hilbert to compute the analytic signal.
From its documentation:
We create a chirp of which the frequency increases from 20 Hz to 100 Hz and apply an amplitude modulation.
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import hilbert, chirp
duration = 1.0
fs = 400.0
samples = int(fs*duration)
t = np.arange(samples) / fs
signal = chirp(t, 20.0, t[-1], 100.0)
signal *= (1.0 + 0.5 * np.sin(2.0*np.pi*3.0*t))
The amplitude envelope is given by magnitude of the analytic signal.
analytic_signal = hilbert(signal)
amplitude_envelope = np.abs(analytic_signal)
Looks like
plt.plot(t, signal, label='signal')
plt.plot(t, amplitude_envelope, label='envelope')
plt.show()
It can also be used to compute the instantaneous frequency (see documentation).