Skip to content

Instantly share code, notes, and snippets.

@staticfloat
Created February 5, 2015 01:41
Show Gist options
  • Save staticfloat/4bfa7190e3c7af487c88 to your computer and use it in GitHub Desktop.
Save staticfloat/4bfa7190e3c7af487c88 to your computer and use it in GitHub Desktop.
A quick demonstration of calculating the Hilbert Envelope of a signal, made with love for Keyu
#!/usr/bin/env python
from numpy import *
from scipy import *
from scipy.signal import *
from pylab import *
# Generate AM-modulated sinusoid
N = 256
t = linspace(0,2,N)
# Modulator
m = 1 + .2*cos(2*pi*t)
# Carrier
c = sin(2*pi*20*t)
# Signal is modulator times carrier
x = m*c
# Calculate envelope, called m_hat via hilbert transform
m_hat = abs(hilbert(x))
# Plot x
plot(t, x)
plot(t, m_hat)
axis('tight')
xlabel('Time (seconds)')
ylabel('Amplitude')
title('X, with calculated envelope')
legend(['x', 'm_hat'])
ylim(-2,2)
show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment