-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
54 lines (39 loc) · 1.24 KB
/
example.py
File metadata and controls
54 lines (39 loc) · 1.24 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
48
49
50
51
52
53
54
import numpy as np
import matplotlib.pyplot as plt
from hhtpy import decompose, hilbert_huang_transform
from hhtpy.plot import (
plot_imfs,
plot_hilbert_spectrum,
HilbertSpectrumConfig,
plot_marginal_hilbert_spectrum,
)
plt.style.use("seaborn-v0_8")
plt.rcParams["image.cmap"] = "viridis"
T = 5 # sec
f_s = 15000 # Hz
n = np.arange(T * f_s)
t = n / f_s # sec
# y = 0.3 * np.cos(2 * np.pi * 5 * t**2) + 2 * np.cos(2 * np.pi * 1 * t) + 1 * t
y = 1 * np.cos(2 * np.pi * 50 * t + 20 * np.sin(2 * np.pi * 0.5 * t)) + 2 * np.cos(
2 * np.pi * 20 * t
)
imfs, residue = hilbert_huang_transform(y, f_s)
fig, axs = plot_imfs(imfs, y, residue, t, max_number_of_imfs=2)
axs[1].set_ylim([-1.1, 1.1])
[ax.set_xlim([2.4, 2.5]) for ax in axs]
[ax.set_xticks([]) for ax in axs[:-1]]
axs[-1].set_xlabel("Time (s)")
axs[0].set_ylabel("Original\nSignal")
fig.tight_layout()
fig.savefig("figs/imfs.png", dpi=300)
fig, ax, clb = plot_hilbert_spectrum(
imfs,
config=HilbertSpectrumConfig(max_number_of_imfs=2),
)
fig.tight_layout()
ax.set_xlim([0.5, 4.5])
fig.savefig("figs/hilbert_spectrum.png", dpi=300)
fig, ax = plot_marginal_hilbert_spectrum(imfs)
ax.set_yscale("log")
fig.savefig("figs/marginal_hilbert_spectrum.png", dpi=300)
plt.show()