Closed notthetup closed 4 years ago
Not a bug. The signal you gave it as an input has a DC offset in the second half of the signal. The way scipy
implements the Hilbert transform, it effectively assumes a periodic signal, so it means your signal had a DC offset before it started. So the Hilbert transform has a non-zero imaginary part in the first 200 samples to try and match to the DC offsets on both sides, and that results in the envelope you see.
I recognize that it is non-intuitive that the envelope doesn't hug the signal here, but the Hilbert envelope (definition of the envelope
function in arlpy
) is indeed what you see. If you zero pad your signal at the end, to allow it to go back to zero, you'll get the result you desire.
asig.envelope
has a strange window like artefact in the first few samples.