PySDKit 0.4.11__tar.gz → 0.4.12__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pysdkit-0.4.11 → pysdkit-0.4.12}/PKG-INFO +2 -1
- {pysdkit-0.4.11 → pysdkit-0.4.12}/PySDKit.egg-info/PKG-INFO +2 -1
- {pysdkit-0.4.11 → pysdkit-0.4.12}/PySDKit.egg-info/SOURCES.txt +2 -2
- {pysdkit-0.4.11 → pysdkit-0.4.12}/README.md +1 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/data/__init__.py +15 -3
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/data/_add_noise.py +0 -8
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/data/_generator.py +266 -30
- pysdkit-0.4.12/pysdkit/data/_image.py +364 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/emd/emd.py +6 -2
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/lmd/lmd.py +69 -44
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/lmd/rlmd.py +1 -1
- pysdkit-0.4.12/pysdkit/plot/__init__.py +19 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/plot/_fourier_spectra.py +2 -2
- pysdkit-0.4.12/pysdkit/plot/_plot_images.py +200 -0
- pysdkit-0.4.12/pysdkit/plot/_plot_imfs.py +541 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/vmd/mvmd.py +0 -1
- {pysdkit-0.4.11 → pysdkit-0.4.12}/setup.py +2 -2
- pysdkit-0.4.11/pysdkit/data/image.py +0 -44
- pysdkit-0.4.11/pysdkit/plot/__init__.py +0 -14
- pysdkit-0.4.11/pysdkit/plot/_plot_imfs.py +0 -132
- pysdkit-0.4.11/pysdkit/plot/plot_GrayScale.py +0 -57
- {pysdkit-0.4.11 → pysdkit-0.4.12}/PySDKit.egg-info/dependency_links.txt +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/PySDKit.egg-info/requires.txt +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/PySDKit.egg-info/top_level.txt +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/data/texture.txt +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/emd/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/emd/_find_extrema.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/emd/_prepare_points.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/emd/_splines.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/emd/ceemdan.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/emd/eemd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/emd/memd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/emd/remd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/emd2d/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/emd2d/bemd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/emd2d/bmemd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/emd2d/emd2d.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/esmd/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/esmd/esmd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/ewt/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/ewt/ewt.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/ewt/ewt2d.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/faemd/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/faemd/faemd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/faemd/md_faemd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/faemd/mv_faemd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/fmd/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/fmd/fmd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/hht/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/hht/hht.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/hvd/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/hvd/hvd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/ifd/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/itd/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/itd/itd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/jmd/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/jmd/jmd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/jmd/mjmd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/lmd/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/plot/_functions.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/ssa/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/ssa/ssa.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/tvf_emd/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/tvf_emd/tvf_emd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/utils/_Index_of_Orthogonality.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/utils/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/utils/_diagnalization.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/utils/_differ.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/utils/_fft.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/utils/_function.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/utils/_kernel_matrix.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/utils/_lags.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/utils/_smooth1d.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/utils/_types.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/utils/correlation.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/utils/hilbert.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/utils/instantaneous.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/utils/mirror.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/utils/process.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/vmd/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/vmd/acmd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/vmd/avmd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/vmd/ba_acmd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/vmd/base.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/vmd/svmd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/vmd/vmd_c.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/vmd/vmd_f.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/vmd2d/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/vmd2d/vmd2d.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/vncmd/__init__.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/vncmd/anvcmd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/vncmd/mncmd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/pysdkit/vncmd/vncmd.py +0 -0
- {pysdkit-0.4.11 → pysdkit-0.4.12}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: PySDKit
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.12
|
|
4
4
|
Summary: A Python library for signal decomposition algorithms with a unified interface.
|
|
5
5
|
Home-page: https://github.com/wwhenxuan/PySDKit
|
|
6
6
|
Author: whenxuan
|
|
@@ -43,6 +43,7 @@ Dynamic: summary
|
|
|
43
43
|

|
|
44
44
|
[](https://www.python.org/)
|
|
45
45
|
[](https://pepy.tech/project/pysdkit)
|
|
46
|
+

|
|
46
47
|
[](https://github.com/psf/black)
|
|
47
48
|
|
|
48
49
|
A Python library for signal decomposition algorithms 🥳
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: PySDKit
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.12
|
|
4
4
|
Summary: A Python library for signal decomposition algorithms with a unified interface.
|
|
5
5
|
Home-page: https://github.com/wwhenxuan/PySDKit
|
|
6
6
|
Author: whenxuan
|
|
@@ -43,6 +43,7 @@ Dynamic: summary
|
|
|
43
43
|

|
|
44
44
|
[](https://www.python.org/)
|
|
45
45
|
[](https://pepy.tech/project/pysdkit)
|
|
46
|
+

|
|
46
47
|
[](https://github.com/psf/black)
|
|
47
48
|
|
|
48
49
|
A Python library for signal decomposition algorithms 🥳
|
|
@@ -9,7 +9,7 @@ pysdkit/__init__.py
|
|
|
9
9
|
pysdkit/data/__init__.py
|
|
10
10
|
pysdkit/data/_add_noise.py
|
|
11
11
|
pysdkit/data/_generator.py
|
|
12
|
-
pysdkit/data/
|
|
12
|
+
pysdkit/data/_image.py
|
|
13
13
|
pysdkit/data/texture.txt
|
|
14
14
|
pysdkit/emd/__init__.py
|
|
15
15
|
pysdkit/emd/_find_extrema.py
|
|
@@ -51,8 +51,8 @@ pysdkit/lmd/rlmd.py
|
|
|
51
51
|
pysdkit/plot/__init__.py
|
|
52
52
|
pysdkit/plot/_fourier_spectra.py
|
|
53
53
|
pysdkit/plot/_functions.py
|
|
54
|
+
pysdkit/plot/_plot_images.py
|
|
54
55
|
pysdkit/plot/_plot_imfs.py
|
|
55
|
-
pysdkit/plot/plot_GrayScale.py
|
|
56
56
|
pysdkit/ssa/__init__.py
|
|
57
57
|
pysdkit/ssa/ssa.py
|
|
58
58
|
pysdkit/tvf_emd/__init__.py
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|

|
|
7
7
|
[](https://www.python.org/)
|
|
8
8
|
[](https://pepy.tech/project/pysdkit)
|
|
9
|
+

|
|
9
10
|
[](https://github.com/psf/black)
|
|
10
11
|
|
|
11
12
|
A Python library for signal decomposition algorithms 🥳
|
|
@@ -17,11 +17,23 @@ from ._generator import generate_am_signal, generate_exponential_signal
|
|
|
17
17
|
# Generates the main test sample signal
|
|
18
18
|
from ._generator import test_emd
|
|
19
19
|
|
|
20
|
+
# Generator for 1D univariate
|
|
21
|
+
from ._generator import test_uni_signal
|
|
22
|
+
|
|
23
|
+
# Generator for 1D multivariate
|
|
24
|
+
from ._generator import test_multi_signal
|
|
25
|
+
|
|
20
26
|
# Functions that generate signal visualizations
|
|
21
|
-
from ._generator import
|
|
27
|
+
from ._generator import plot_signal
|
|
22
28
|
|
|
23
29
|
# add Gaussian noise
|
|
24
30
|
from ._add_noise import add_noise
|
|
25
31
|
|
|
26
|
-
#
|
|
27
|
-
from .
|
|
32
|
+
# Test case for loading a 2D grayscale image
|
|
33
|
+
from ._image import test_grayscale
|
|
34
|
+
|
|
35
|
+
# Test case for univariate image
|
|
36
|
+
from ._image import test_uni_image
|
|
37
|
+
|
|
38
|
+
# Test case for multivariate image
|
|
39
|
+
from ._image import test_multi_image
|
|
@@ -198,7 +198,67 @@ def generate_exponential_signal(
|
|
|
198
198
|
return t, noisy_exp_signal
|
|
199
199
|
|
|
200
200
|
|
|
201
|
-
def
|
|
201
|
+
def test_uni_signal(
|
|
202
|
+
case: int = 1,
|
|
203
|
+
duration: float = 1.0,
|
|
204
|
+
sampling_rate: int = 1000,
|
|
205
|
+
) -> Tuple[np.array, np.array]:
|
|
206
|
+
"""
|
|
207
|
+
Select a test case for a one-dimensional univariate signal based on the input `case`
|
|
208
|
+
:param case: the test number in [1, 2, 3]
|
|
209
|
+
:param duration: Length of the signal in seconds.
|
|
210
|
+
:param sampling_rate: Number of samples per second.
|
|
211
|
+
:return: Tuple containing time array and the generated signal.
|
|
212
|
+
:return: the generated signal for univariate 1D.
|
|
213
|
+
"""
|
|
214
|
+
if case == 1:
|
|
215
|
+
return test_1D_1(duration, sampling_rate)
|
|
216
|
+
elif case == 2:
|
|
217
|
+
return test_1D_2(duration, sampling_rate)
|
|
218
|
+
elif case == 3:
|
|
219
|
+
return test_1D_3(duration, sampling_rate)
|
|
220
|
+
else:
|
|
221
|
+
# 当没有这个测试实例是返回`test_emd`这个函数
|
|
222
|
+
print(f"There is no case {case}, so it will return test_emd!")
|
|
223
|
+
return test_emd(duration, sampling_rate)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def test_1D_1(
|
|
227
|
+
duration: float = 1.0, sampling_rate: int = 1000
|
|
228
|
+
) -> Tuple[np.array, np.array]:
|
|
229
|
+
"""4 / np.pi * (np.sin(2 * np.pi * 10 * t) + np.sin(2 * np.pi * 30 * t) / 3 + np.sin(2 * np.pi * (50 * t + 20 * t ** 2)) / 2)
|
|
230
|
+
:param duration: Length of the signal in seconds.
|
|
231
|
+
:param sampling_rate: Number of samples per second.
|
|
232
|
+
:return: Tuple containing time array and the generated signal.
|
|
233
|
+
"""
|
|
234
|
+
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
|
|
235
|
+
signal = (
|
|
236
|
+
4
|
|
237
|
+
/ np.pi
|
|
238
|
+
* (
|
|
239
|
+
np.sin(2 * np.pi * 10 * t)
|
|
240
|
+
+ np.sin(2 * np.pi * 30 * t) / 3
|
|
241
|
+
+ np.sin(2 * np.pi * (50 * t + 20 * t**2)) / 2
|
|
242
|
+
)
|
|
243
|
+
)
|
|
244
|
+
return t, signal
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def test_1D_2(
|
|
248
|
+
duration: float = 10.0, sampling_rate: int = 128
|
|
249
|
+
) -> Tuple[np.array, np.array]:
|
|
250
|
+
"""
|
|
251
|
+
Generate 3 * 2 ^ (-t) * sin(sin(2 * pi * t))
|
|
252
|
+
:param duration: Length of the signal in seconds.
|
|
253
|
+
:param sampling_rate: Number of samples per second.
|
|
254
|
+
:return: Tuple containing time array and the 3 * 2 ^ (-t) * sin(sin(2 * pi * t)) signal.
|
|
255
|
+
"""
|
|
256
|
+
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
|
|
257
|
+
signal = 3 * 2 ^ (-t) * np.sin(np.sin(2 * np.pi * t))
|
|
258
|
+
return t, signal
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def test_1D_3(
|
|
202
262
|
duration: float = 6.0,
|
|
203
263
|
sampling_rate: int = 128,
|
|
204
264
|
noise_level: float = 0.0,
|
|
@@ -220,18 +280,6 @@ def base_example(
|
|
|
220
280
|
return t, noise_signal
|
|
221
281
|
|
|
222
282
|
|
|
223
|
-
def fun(duration: float = 10.0, sampling_rate: int = 128) -> Tuple[np.array, np.array]:
|
|
224
|
-
"""
|
|
225
|
-
Generate 3 * 2 ^ (-t) * sin(sin(2 * pi * t))
|
|
226
|
-
:param duration: Length of the signal in seconds.
|
|
227
|
-
:param sampling_rate: Number of samples per second.
|
|
228
|
-
:return: Tuple containing time array and the 3 * 2 ^ (-t) * sin(sin(2 * pi * t)) signal.
|
|
229
|
-
"""
|
|
230
|
-
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
|
|
231
|
-
signal = 3 * 2 ^ (-t) * np.sin(np.sin(2 * np.pi * t))
|
|
232
|
-
return t, signal
|
|
233
|
-
|
|
234
|
-
|
|
235
283
|
def test_emd(
|
|
236
284
|
duration: float = 1.0,
|
|
237
285
|
sampling_rate: int = 1000,
|
|
@@ -254,14 +302,156 @@ def test_emd(
|
|
|
254
302
|
return t, noise_signal
|
|
255
303
|
|
|
256
304
|
|
|
257
|
-
def
|
|
305
|
+
def test_multi_signal(
|
|
306
|
+
case: int = 1,
|
|
307
|
+
duration: float = 1.0,
|
|
308
|
+
sampling_rate: int = 1000,
|
|
309
|
+
) -> Tuple[np.array, np.array]:
|
|
310
|
+
"""
|
|
311
|
+
Select a test case for a 1D multivariate signal based on the input `case`
|
|
312
|
+
:param case: the test number in [1, 2, 3]
|
|
313
|
+
:param duration: Length of the signal in seconds.
|
|
314
|
+
:param sampling_rate: Number of samples per second.
|
|
315
|
+
:return: Tuple containing time array and the generated signal.
|
|
316
|
+
:return: the generated signal for multivariate 1D.
|
|
317
|
+
"""
|
|
318
|
+
if case == 1:
|
|
319
|
+
return test_multi_1D_1(duration=duration, sampling_rate=sampling_rate)
|
|
320
|
+
elif case == 2:
|
|
321
|
+
return test_multi_1D_2(duration=duration, sampling_rate=sampling_rate)
|
|
322
|
+
elif case == 3:
|
|
323
|
+
return test_multi_1D_3(duration=duration, sampling_rate=sampling_rate)
|
|
324
|
+
else:
|
|
325
|
+
# When there is no such test instance, the function returns `case==1`
|
|
326
|
+
print(f"There is no case {case}, so it will return case==1!")
|
|
327
|
+
return test_multi_1D_1(duration=duration, sampling_rate=sampling_rate)
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def test_multi_1D_1(
|
|
331
|
+
duration: float = 1.0, sampling_rate: int = 1000
|
|
332
|
+
) -> Tuple[np.array, np.array]:
|
|
333
|
+
"""
|
|
334
|
+
Generate some simple cosine and sine function for multivariate signal decomposition test
|
|
335
|
+
:param duration: Length of the signal in seconds.
|
|
336
|
+
:param sampling_rate: Number of samples per second.
|
|
337
|
+
:return: Tuple containing time array and the multivariate signals of shape [num_vars, seq_len].
|
|
338
|
+
"""
|
|
339
|
+
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
|
|
340
|
+
|
|
341
|
+
# Generate the multi-channels signals
|
|
342
|
+
signal_1 = np.cos(2 * np.pi * 5 * t + np.pi / 3) + 2.5 * np.cos(
|
|
343
|
+
2 * np.pi * 36 * t + np.pi / 2
|
|
344
|
+
)
|
|
345
|
+
signal_2 = 3 * np.cos(2 * np.pi * 24 * t) + 2 * np.cos(2 * np.pi * 36 * t)
|
|
346
|
+
|
|
347
|
+
# concat all channels
|
|
348
|
+
signal = np.vstack([signal_1, signal_2])
|
|
349
|
+
|
|
350
|
+
return t, signal
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def test_multi_1D_2(
|
|
354
|
+
duration: float = 1.0, sampling_rate: int = 1000
|
|
355
|
+
) -> Tuple[np.array, np.array]:
|
|
356
|
+
"""
|
|
357
|
+
Generate four channels simple cosine and sine function for multivariate signal decomposition
|
|
358
|
+
:param duration: Length of the signal in seconds.
|
|
359
|
+
:param sampling_rate: Number of samples per second.
|
|
360
|
+
:return: Tuple containing time array and the multivariate signals of shape [num_vars, seq_len].
|
|
361
|
+
"""
|
|
362
|
+
np.random.seed(seed=42)
|
|
363
|
+
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
|
|
364
|
+
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
|
|
365
|
+
|
|
366
|
+
# Generate the multi-channels signals
|
|
367
|
+
signal_1 = (
|
|
368
|
+
2 * np.cos(2 * np.pi * 3 * t**2)
|
|
369
|
+
+ 1.7 * np.cos(2 * np.pi * 20 * t)
|
|
370
|
+
+ np.cos(2 * np.pi * 40 * t)
|
|
371
|
+
+ np.random.uniform(0, 0.2, t.shape)
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
signal_2 = 1.5 * np.cos(2 * np.pi * 3 * t**2) + np.random.uniform(0, 0.2, t.shape)
|
|
375
|
+
|
|
376
|
+
signal_3 = (
|
|
377
|
+
2 * np.cos(2 * np.pi * 20 * t + np.pi / 3)
|
|
378
|
+
+ 1.8 * np.cos(2 * np.pi * 40 * t)
|
|
379
|
+
+ np.random.uniform(0, 0.2, t.shape)
|
|
380
|
+
)
|
|
381
|
+
|
|
382
|
+
signal_4 = (
|
|
383
|
+
1.8 * np.cos(2 * np.pi * 3 * t**2)
|
|
384
|
+
+ 2 * np.cos(2 * np.pi * 40 * t)
|
|
385
|
+
+ np.random.uniform(0, 0.2, t.shape)
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
# Concat all the input channels
|
|
389
|
+
signal = np.vstack([signal_1, signal_2, signal_3, signal_4])
|
|
390
|
+
|
|
391
|
+
return t, signal
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
def test_multi_1D_3(
|
|
395
|
+
duration: float = 1.0,
|
|
396
|
+
sampling_rate: int = 1000,
|
|
397
|
+
noise_level: float = 0.1,
|
|
398
|
+
random_state: int = 42,
|
|
399
|
+
) -> Tuple[np.ndarray, np.ndarray]:
|
|
400
|
+
"""
|
|
401
|
+
Generate some simple cosine function for multivariate signal decomposition test
|
|
402
|
+
:param duration: Length of the signal in seconds.
|
|
403
|
+
:param sampling_rate: Number of samples per second.
|
|
404
|
+
:param noise_level: Standard deviation of the Gaussian noise.
|
|
405
|
+
:param random_state: Random seed for the noise generation.
|
|
406
|
+
:return: Tuple containing time array and the multivariate signals of shape [num_vars, seq_len] with noise.
|
|
407
|
+
"""
|
|
408
|
+
np.random.seed(seed=random_state)
|
|
409
|
+
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
|
|
410
|
+
|
|
411
|
+
# Generate the multi-channels signals
|
|
412
|
+
f_channel1 = (
|
|
413
|
+
(10 * np.cos(2 * np.pi * 2 * t))
|
|
414
|
+
+ (9 * (np.cos(2 * np.pi * 36 * t)))
|
|
415
|
+
+ np.random.normal(0, noise_level, t.shape)
|
|
416
|
+
)
|
|
417
|
+
|
|
418
|
+
f_channel2 = (
|
|
419
|
+
(9 * (np.cos(2 * np.pi * 24 * t)))
|
|
420
|
+
+ (8 * (np.cos(2 * np.pi * 36 * t)))
|
|
421
|
+
+ np.random.normal(0, noise_level, t.shape)
|
|
422
|
+
)
|
|
423
|
+
|
|
424
|
+
f_channel3 = (
|
|
425
|
+
(8 * (np.cos(2 * np.pi * 28 * t)))
|
|
426
|
+
+ (7 * (np.cos(2 * np.pi * 48 * t)))
|
|
427
|
+
+ np.random.normal(0, noise_level, t.shape)
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
f_channel4 = (
|
|
431
|
+
(7 * (np.cos(2 * np.pi * 32 * t)))
|
|
432
|
+
+ (6 * (np.cos(2 * np.pi * 36 * t)))
|
|
433
|
+
+ np.random.normal(0, noise_level, t.shape)
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
f_channel5 = (
|
|
437
|
+
(6 * (np.cos(2 * np.pi * 19 * t)))
|
|
438
|
+
+ (5 * (np.cos(2 * np.pi * 64 * t)))
|
|
439
|
+
+ np.random.normal(0, noise_level, t.shape)
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
# concat all channels
|
|
443
|
+
f = np.vstack([f_channel1, f_channel2, f_channel3, f_channel4, f_channel5])
|
|
444
|
+
|
|
445
|
+
return t, f
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
def plot_signal(
|
|
258
449
|
t: np.array,
|
|
259
450
|
signal: np.array,
|
|
260
451
|
color: str = "royalblue",
|
|
261
452
|
save: bool = False,
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
fontsize: int = 15,
|
|
453
|
+
dpi: int = 128,
|
|
454
|
+
fontsize: int = 12,
|
|
265
455
|
) -> plt.figure:
|
|
266
456
|
"""
|
|
267
457
|
Plot and optionally save an amplitude modulated (AM) signal with time on the x-axis and amplitude on the y-axis.
|
|
@@ -269,26 +459,72 @@ def plot_generate_signal(
|
|
|
269
459
|
:param signal: Array containing the signal data to be plotted.
|
|
270
460
|
:param color: Color of the plot line.
|
|
271
461
|
:param save: Boolean flag to indicate whether the plot should be saved to a file.
|
|
272
|
-
:param figsize: Tuple representing the width and height of the figure in inches.
|
|
273
462
|
:param dpi: Dots per inch (resolution) of the figure, if saved.
|
|
274
463
|
:param fontsize: Font size of the axis labels.
|
|
275
464
|
:return: The figure object containing the plot.
|
|
276
465
|
"""
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
466
|
+
|
|
467
|
+
# Determine the number of input signals
|
|
468
|
+
n_dim = len(signal.shape)
|
|
469
|
+
|
|
470
|
+
if n_dim == 1:
|
|
471
|
+
# Create a figure and a single subplot
|
|
472
|
+
fig, ax = plt.subplots(figsize=(8, 3))
|
|
473
|
+
|
|
474
|
+
# Plot the signal against time with specified line color
|
|
475
|
+
ax.plot(t, signal, color=color)
|
|
476
|
+
|
|
477
|
+
# Set the x-axis label with specified font size
|
|
478
|
+
ax.set_xlabel("Time (seconds)", fontsize=fontsize)
|
|
479
|
+
|
|
480
|
+
# Set the y-axis label with default font size
|
|
481
|
+
ax.set_ylabel("Amplitude", fontsize=fontsize)
|
|
482
|
+
|
|
483
|
+
# Enable grid for better readability
|
|
484
|
+
ax.grid(True)
|
|
485
|
+
|
|
486
|
+
elif n_dim == 2:
|
|
487
|
+
# Determining the number of multivariate signals
|
|
488
|
+
n_vars = signal.shape[0]
|
|
489
|
+
|
|
490
|
+
# Create a figure and a single subplot
|
|
491
|
+
fig, ax = plt.subplots(nrows=n_vars, figsize=(10, 1 + 2 * n_vars), sharex=True)
|
|
492
|
+
|
|
493
|
+
for i in range(n_vars):
|
|
494
|
+
# Plot the signal against time with specified line color
|
|
495
|
+
ax[i].plot(t, signal[i, :], color=color)
|
|
496
|
+
|
|
497
|
+
# Set the y-axis label with default font size
|
|
498
|
+
ax[i].set_ylabel("Amplitude", fontsize=fontsize)
|
|
499
|
+
|
|
500
|
+
# Enable grid for better readability
|
|
501
|
+
ax[i].grid(True)
|
|
502
|
+
|
|
503
|
+
# Set the x-axis label with specified font size
|
|
504
|
+
ax[-1].set_xlabel("Time (seconds)", fontsize=fontsize)
|
|
505
|
+
|
|
506
|
+
else:
|
|
507
|
+
raise ValueError("Wrong input signal, please input the 1D signal.")
|
|
508
|
+
|
|
289
509
|
# Check if the figure needs to be saved
|
|
290
510
|
if save:
|
|
291
511
|
# Save the figure with the specified dpi and bounding box tightly around the figure
|
|
292
512
|
fig.savefig("generate_signal.jpg", dpi=dpi, bbox_inches="tight")
|
|
513
|
+
|
|
293
514
|
# Return the figure object
|
|
294
515
|
return fig
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
if __name__ == "__main__":
|
|
519
|
+
from pysdkit.data import test_emd, plot_signal, test_multi_signal
|
|
520
|
+
|
|
521
|
+
t, signal = test_uni_signal(case=1)
|
|
522
|
+
print(signal.shape)
|
|
523
|
+
|
|
524
|
+
fig = plot_signal(t, signal)
|
|
525
|
+
|
|
526
|
+
t, signal = test_multi_signal(case=2)
|
|
527
|
+
print(signal.shape)
|
|
528
|
+
|
|
529
|
+
fig = plot_signal(t, signal, save=False)
|
|
530
|
+
plt.show()
|