-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathht.py
More file actions
56 lines (40 loc) · 1.22 KB
/
ht.py
File metadata and controls
56 lines (40 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 4 15:41:24 2020
@author: dong
"""
import numpy as np
import math
def FAhilbert(imfs, dt):
"""
Performs Hilbert transformation on imfs.
Returns frequency and amplitude of signal.
"""
n_imfs = imfs.shape[0]
f = []
a = []
for i in range(n_imfs - 1):
# upper, lower = pyhht.utils.get_envelops(imfs[i, :])
inst_imf = imfs[i, :] # /upper
inst_amp, phase = hilb(inst_imf, unwrap=True)
inst_freq = (1/dt)*np.diff(phase) / (2 * math.pi) #
inst_freq = np.insert(inst_freq, len(inst_freq), inst_freq[-1])
inst_amp = np.insert(inst_amp, len(inst_amp), inst_amp[-1])
f.append(inst_freq)
a.append(inst_amp)
return np.asarray(f).T, np.asarray(a).T
def hilb(s, unwrap=False):
"""
Performs Hilbert transformation on signal s.
Returns amplitude and phase of signal.
Depending on unwrap value phase can be either
in range [-pi, pi) (unwrap=False) or
continuous (unwrap=True).
"""
from scipy.signal import hilbert
H = hilbert(s)
amp = np.abs(H)
phase = np.arctan2(H.imag, H.real)
if unwrap: phase = np.unwrap(phase)
return amp, phase