Skip to content

Instantly share code, notes, and snippets.

@daguiam
Created October 12, 2017 09:55
Show Gist options
  • Save daguiam/992e5f5f37476f3d9cff6b47d11bf92e to your computer and use it in GitHub Desktop.
Save daguiam/992e5f5f37476f3d9cff6b47d11bf92e to your computer and use it in GitHub Desktop.
import scipy.signal
def freq_hilbert(sig,Fs):
""" Calcultes the instantaneous frequency based on the hilbert
transform
"""
sigorig = sig
sig = sig.real
ts = 1.0/Fs
hilb = scipy.signal.hilbert(sig)
ampli = np.abs(hilb)
norm = sig/ampli
hilbnorm = scipy.signal.hilbert(norm)
env = np.abs(hilbnorm)
phase = np.unwrap(np.angle(hilbnorm))
#print 'phase1',phase
phase = np.unwrap(np.angle(sigorig))
#print 'phase2',phase
#exit()
phasediff = np.append([0],np.diff(phase))
#print 'phasediff',phasediff
freq = phasediff/(2*np.pi*ts)
#freq = freq/(2*np.pi)
return freq
def freq_hilbert_phase(sig,Fs):
""" Calcultes the instantaneous frequency based on the hilbert
transform
"""
sigorig = sig
sig = sig.real
ts = 1.0/Fs
hilb = scipy.signal.hilbert(sig)
ampli = np.abs(hilb)
norm = sig/ampli
hilbnorm = scipy.signal.hilbert(norm)
env = np.abs(hilbnorm)
phase = np.unwrap(np.angle(hilbnorm))
#print 'phase1',phase
phase = np.unwrap(np.angle(sigorig))
#print 'phase2',phase
#exit()
phasediff = np.append([0],np.diff(phase))
#print 'phasediff',phasediff
freq = phasediff/(2*np.pi*ts)
#freq = freq/(2*np.pi)
return freq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment