Created
October 12, 2017 09:55
-
-
Save daguiam/992e5f5f37476f3d9cff6b47d11bf92e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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