PySDKit 0.1__py3-none-any.whl → 0.4__py3-none-any.whl
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.dist-info/LICENSE +121 -0
- PySDKit-0.4.dist-info/METADATA +100 -0
- PySDKit-0.4.dist-info/RECORD +42 -0
- PySDKit-0.4.dist-info/top_level.txt +1 -0
- pysdkit/__init__.py +14 -0
- pysdkit/data/__init__.py +20 -0
- pysdkit/data/_add_noise.py +35 -0
- pysdkit/data/_generator.py +240 -0
- pysdkit/emd/EMD.py +456 -0
- pysdkit/emd/__init__.py +2 -0
- pysdkit/emd/_find_extrema.py +137 -0
- pysdkit/emd/_prepare_points.py +270 -0
- pysdkit/emd/_splines.py +96 -0
- pysdkit/ewt/__init__.py +2 -0
- pysdkit/ewt/_ewt.py +449 -0
- pysdkit/metrics/_Index_of_Orthogonality.py +40 -0
- pysdkit/metrics/__init__.py +7 -0
- pysdkit/plot/__init__.py +2 -0
- pysdkit/plot/_fourier_spectra.py +134 -0
- pysdkit/plot/_functions.py +102 -0
- pysdkit/plot/_plot_imfs.py +111 -0
- pysdkit/plot/main.py +4 -0
- pysdkit/utils/__init__.py +34 -0
- pysdkit/utils/_differ.py +28 -0
- pysdkit/utils/_fft.py +22 -0
- pysdkit/utils/_function.py +58 -0
- pysdkit/utils/_smooth1d.py +93 -0
- pysdkit/utils/hilbert.py +104 -0
- pysdkit/utils/mirror.py +30 -0
- pysdkit/utils/process.py +142 -0
- pysdkit/vmd/__init__.py +4 -0
- pysdkit/vmd/_avmd.py +20 -0
- pysdkit/vmd/_mvmd.py +213 -0
- pysdkit/vmd/_svmd.py +21 -0
- pysdkit/vmd/_vmd_c.py +201 -0
- pysdkit/vmd/_vmd_f.py +138 -0
- pysdkit/vmd/base.py +70 -0
- pysdkit/vncmd/__init__.py +1 -0
- pysdkit/vncmd/vncmd.py +284 -0
- PySDKit-0.1.dist-info/METADATA +0 -27
- PySDKit-0.1.dist-info/RECORD +0 -11
- PySDKit-0.1.dist-info/top_level.txt +0 -5
- mvmd/__init__.py +0 -0
- vmd/__init__.py +0 -2
- vmd/vmd_c.py +0 -129
- vmd/vmd_f.py +0 -159
- vncmd/__init__.py +0 -0
- {PySDKit-0.1.dist-info → PySDKit-0.4.dist-info}/WHEEL +0 -0
- /emd/__init__.py → /pysdkit/emd/BEMD.py +0 -0
- {ewt → pysdkit/emd2d}/__init__.py +0 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Creative Commons Legal Code
|
|
2
|
+
|
|
3
|
+
CC0 1.0 Universal
|
|
4
|
+
|
|
5
|
+
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
|
6
|
+
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
|
7
|
+
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
|
8
|
+
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
|
9
|
+
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
|
10
|
+
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
|
11
|
+
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
|
12
|
+
HEREUNDER.
|
|
13
|
+
|
|
14
|
+
Statement of Purpose
|
|
15
|
+
|
|
16
|
+
The laws of most jurisdictions throughout the world automatically confer
|
|
17
|
+
exclusive Copyright and Related Rights (defined below) upon the creator
|
|
18
|
+
and subsequent owner(s) (each and all, an "owner") of an original work of
|
|
19
|
+
authorship and/or a database (each, a "Work").
|
|
20
|
+
|
|
21
|
+
Certain owners wish to permanently relinquish those rights to a Work for
|
|
22
|
+
the purpose of contributing to a commons of creative, cultural and
|
|
23
|
+
scientific works ("Commons") that the public can reliably and without fear
|
|
24
|
+
of later claims of infringement build upon, modify, incorporate in other
|
|
25
|
+
works, reuse and redistribute as freely as possible in any form whatsoever
|
|
26
|
+
and for any purposes, including without limitation commercial purposes.
|
|
27
|
+
These owners may contribute to the Commons to promote the ideal of a free
|
|
28
|
+
culture and the further production of creative, cultural and scientific
|
|
29
|
+
works, or to gain reputation or greater distribution for their Work in
|
|
30
|
+
part through the use and efforts of others.
|
|
31
|
+
|
|
32
|
+
For these and/or other purposes and motivations, and without any
|
|
33
|
+
expectation of additional consideration or compensation, the person
|
|
34
|
+
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
|
35
|
+
is an owner of Copyright and Related Rights in the Work, voluntarily
|
|
36
|
+
elects to apply CC0 to the Work and publicly distribute the Work under its
|
|
37
|
+
terms, with knowledge of his or her Copyright and Related Rights in the
|
|
38
|
+
Work and the meaning and intended legal effect of CC0 on those rights.
|
|
39
|
+
|
|
40
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
41
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
|
42
|
+
Related Rights"). Copyright and Related Rights include, but are not
|
|
43
|
+
limited to, the following:
|
|
44
|
+
|
|
45
|
+
i. the right to reproduce, adapt, distribute, perform, display,
|
|
46
|
+
communicate, and translate a Work;
|
|
47
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
|
48
|
+
iii. publicity and privacy rights pertaining to a person's image or
|
|
49
|
+
likeness depicted in a Work;
|
|
50
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
|
51
|
+
subject to the limitations in paragraph 4(a), below;
|
|
52
|
+
v. rights protecting the extraction, dissemination, use and reuse of data
|
|
53
|
+
in a Work;
|
|
54
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
|
55
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
|
56
|
+
protection of databases, and under any national implementation
|
|
57
|
+
thereof, including any amended or successor version of such
|
|
58
|
+
directive); and
|
|
59
|
+
vii. other similar, equivalent or corresponding rights throughout the
|
|
60
|
+
world based on applicable law or treaty, and any national
|
|
61
|
+
implementations thereof.
|
|
62
|
+
|
|
63
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention
|
|
64
|
+
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
|
65
|
+
irrevocably and unconditionally waives, abandons, and surrenders all of
|
|
66
|
+
Affirmer's Copyright and Related Rights and associated claims and causes
|
|
67
|
+
of action, whether now known or unknown (including existing as well as
|
|
68
|
+
future claims and causes of action), in the Work (i) in all territories
|
|
69
|
+
worldwide, (ii) for the maximum duration provided by applicable law or
|
|
70
|
+
treaty (including future time extensions), (iii) in any current or future
|
|
71
|
+
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
|
72
|
+
including without limitation commercial, advertising or promotional
|
|
73
|
+
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
|
74
|
+
member of the public at large and to the detriment of Affirmer's heirs and
|
|
75
|
+
successors, fully intending that such Waiver shall not be subject to
|
|
76
|
+
revocation, rescission, cancellation, termination, or any other legal or
|
|
77
|
+
equitable action to disrupt the quiet enjoyment of the Work by the public
|
|
78
|
+
as contemplated by Affirmer's express Statement of Purpose.
|
|
79
|
+
|
|
80
|
+
3. Public License Fallback. Should any part of the Waiver for any reason
|
|
81
|
+
be judged legally invalid or ineffective under applicable law, then the
|
|
82
|
+
Waiver shall be preserved to the maximum extent permitted taking into
|
|
83
|
+
account Affirmer's express Statement of Purpose. In addition, to the
|
|
84
|
+
extent the Waiver is so judged Affirmer hereby grants to each affected
|
|
85
|
+
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
|
86
|
+
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
|
87
|
+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
|
88
|
+
maximum duration provided by applicable law or treaty (including future
|
|
89
|
+
time extensions), (iii) in any current or future medium and for any number
|
|
90
|
+
of copies, and (iv) for any purpose whatsoever, including without
|
|
91
|
+
limitation commercial, advertising or promotional purposes (the
|
|
92
|
+
"License"). The License shall be deemed effective as of the date CC0 was
|
|
93
|
+
applied by Affirmer to the Work. Should any part of the License for any
|
|
94
|
+
reason be judged legally invalid or ineffective under applicable law, such
|
|
95
|
+
partial invalidity or ineffectiveness shall not invalidate the remainder
|
|
96
|
+
of the License, and in such case Affirmer hereby affirms that he or she
|
|
97
|
+
will not (i) exercise any of his or her remaining Copyright and Related
|
|
98
|
+
Rights in the Work or (ii) assert any associated claims and causes of
|
|
99
|
+
action with respect to the Work, in either case contrary to Affirmer's
|
|
100
|
+
express Statement of Purpose.
|
|
101
|
+
|
|
102
|
+
4. Limitations and Disclaimers.
|
|
103
|
+
|
|
104
|
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
|
105
|
+
surrendered, licensed or otherwise affected by this document.
|
|
106
|
+
b. Affirmer offers the Work as-is and makes no representations or
|
|
107
|
+
warranties of any kind concerning the Work, express, implied,
|
|
108
|
+
statutory or otherwise, including without limitation warranties of
|
|
109
|
+
title, merchantability, fitness for a particular purpose, non
|
|
110
|
+
infringement, or the absence of latent or other defects, accuracy, or
|
|
111
|
+
the present or absence of errors, whether or not discoverable, all to
|
|
112
|
+
the greatest extent permissible under applicable law.
|
|
113
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
|
114
|
+
that may apply to the Work or any use thereof, including without
|
|
115
|
+
limitation any person's Copyright and Related Rights in the Work.
|
|
116
|
+
Further, Affirmer disclaims responsibility for obtaining any necessary
|
|
117
|
+
consents, permissions or other rights required for any use of the
|
|
118
|
+
Work.
|
|
119
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
|
120
|
+
party to this document and has no duty or obligation with respect to
|
|
121
|
+
this CC0 or use of the Work.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: PySDKit
|
|
3
|
+
Version: 0.4
|
|
4
|
+
Summary: A Python library for signal decomposition algorithms with a unified interface
|
|
5
|
+
Home-page: https://github.com/wwhenxuan/PySDKit
|
|
6
|
+
Author: whenxuan
|
|
7
|
+
Author-email: wwhenxuan@gmail.com
|
|
8
|
+
Keywords: signal,decomposition
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Requires-Python: >=3.6
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: numpy (>=1.24.3)
|
|
24
|
+
Requires-Dist: scipy (>=1.11.1)
|
|
25
|
+
Requires-Dist: matplotlib (>=3.7.2)
|
|
26
|
+
|
|
27
|
+
# PySDKit: signal decomposition in Python
|
|
28
|
+
|
|
29
|
+
[](https://pypi.org/project/PySDKit/)  [](https://codecov.io/gh/wwhenxuan/PySDKit) [](https://arxiv.org/abs/1234.56789) [](https://pepy.tech/project/pysdkit)  
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
A Python library for signal decomposition algorithms
|
|
33
|
+
|
|
34
|
+
<div align="center">
|
|
35
|
+
<img src=".\images\Logo_sd.png" alt="Logo_sd" width="500"/>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
You can install `PySDKit` through pip.
|
|
41
|
+
|
|
42
|
+
~~~
|
|
43
|
+
pip install pysdkit
|
|
44
|
+
~~~
|
|
45
|
+
|
|
46
|
+
We only used [`NumPy`](https://numpy.org/), [`Scipy`](https://scipy.org/) and [`matplotlib`](https://matplotlib.org/) when developing the project.
|
|
47
|
+
|
|
48
|
+
## Example script
|
|
49
|
+
|
|
50
|
+
This project integrates simple signal processing methods, signal decomposition and visualization, and builds a general interface similar to [`Scikit-learn`](https://scikit-learn.org/stable/). It is mainly divided into three steps:
|
|
51
|
+
1. Import the signal decomposition method;
|
|
52
|
+
2. Create an instance for signal decomposition;
|
|
53
|
+
3. Use the `fit_transform` method to implement signal decomposition;
|
|
54
|
+
4. Visualize and analyze the original signal and the intrinsic mode functions IMFs obtained by decomposition.
|
|
55
|
+
|
|
56
|
+
~~~python
|
|
57
|
+
from pysdkit import EMD
|
|
58
|
+
from pysdkit.data import test_emd
|
|
59
|
+
from pysdkit.plot import plot_IMFs
|
|
60
|
+
|
|
61
|
+
t, signal = test_emd()
|
|
62
|
+
|
|
63
|
+
# create an instance for signal decomposition
|
|
64
|
+
emd = EMD()
|
|
65
|
+
# implement signal decomposition
|
|
66
|
+
IMFs = emd.fit_transform(signal, max_imf=2)
|
|
67
|
+
plot_IMFs(signal, IMFs)
|
|
68
|
+
~~~
|
|
69
|
+
|
|
70
|
+
<img src=".\images\example.jpg" alt="example" />
|
|
71
|
+
|
|
72
|
+
The EMD in the above example is the most classic `empirical mode decomposition` algorithm in signal decomposition. For more complex signals, you can try other algorithms such as variational mode decomposition ([`VMD`](https://ieeexplore.ieee.org/abstract/document/6655981)).
|
|
73
|
+
|
|
74
|
+
~~~python
|
|
75
|
+
from pysdkit import VMD
|
|
76
|
+
|
|
77
|
+
# load new signal
|
|
78
|
+
signal = np.load("example.npy")
|
|
79
|
+
|
|
80
|
+
# use variational mode decomposition
|
|
81
|
+
vmd = VMD(alpha=500, K=3, tau=0.0, tol=1e-9)
|
|
82
|
+
IMFs = vmd.fit_transform(signal=signal)
|
|
83
|
+
print(IMFs.shape)
|
|
84
|
+
|
|
85
|
+
vmd.plot_IMFs(save_figure=True)
|
|
86
|
+
~~~
|
|
87
|
+
|
|
88
|
+
<img src=".\images\vmd_example.jpg" alt="vmd_example.jpg" />
|
|
89
|
+
|
|
90
|
+
Better observe the characteristics of the decomposed intrinsic mode function in the frequency domain.
|
|
91
|
+
|
|
92
|
+
~~~python
|
|
93
|
+
from pysdkit.plot import plot_IMFs_amplitude_spectra
|
|
94
|
+
|
|
95
|
+
# frequency domain visualization
|
|
96
|
+
plot_IMFs_amplitude_spectra(IMFs, smooth="exp") # use exp smooth
|
|
97
|
+
~~~
|
|
98
|
+
|
|
99
|
+
<img src=".\images\frequency_example.jpg" alt="frequency_example" />
|
|
100
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
pysdkit/__init__.py,sha256=nsuYXOdFNc3J-NNu5kkMXbeF8z_CBVLIo3tTKwEP53k,259
|
|
2
|
+
pysdkit/data/__init__.py,sha256=i_ZMKR_FcLq8wWXJ0MyLA4S41iXTMWbpf9sGpoLWdpw,621
|
|
3
|
+
pysdkit/data/_add_noise.py,sha256=8cGzAquIPlf0hzTMUOBj8R1SEjGd2-JveWyzPPII05M,949
|
|
4
|
+
pysdkit/data/_generator.py,sha256=gW7D9A8OTKJ5CBQ40oTbowu9PMZx-WiyN43oz42OAL4,12119
|
|
5
|
+
pysdkit/emd/BEMD.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
pysdkit/emd/EMD.py,sha256=xyQT7IqitAQ9mdOfDDh4QEwlFU7SODl_9y5wd3M-v-k,18090
|
|
7
|
+
pysdkit/emd/__init__.py,sha256=HdOfha6kuiKz2sdTENF_7bHTN2BT2Qtr5i1xXc9dOm8,22
|
|
8
|
+
pysdkit/emd/_find_extrema.py,sha256=EnUZB9Z4uUaVTfuH2J2hERUR6cmsWQ890gQt8BpE1f0,5368
|
|
9
|
+
pysdkit/emd/_prepare_points.py,sha256=XwEkwRPmHTZZcHhjiBx2lv_Qvj-gx2lw76locyOBf-8,10528
|
|
10
|
+
pysdkit/emd/_splines.py,sha256=aaAULcznyn6mSciDeht4hdKZx1MhvKTvd0Z-bQVpd9E,2575
|
|
11
|
+
pysdkit/emd2d/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
+
pysdkit/ewt/__init__.py,sha256=Yz5QcfLHTqf_69qJ663ESoUzrbKSnhHY0angsegqhvk,60
|
|
13
|
+
pysdkit/ewt/_ewt.py,sha256=TVo7GbVtBtFr7vHFQmE2PPyxX3hp0Pe3aNQyNAH_P5E,15703
|
|
14
|
+
pysdkit/metrics/_Index_of_Orthogonality.py,sha256=nmUEP56TVeZqKogP0QqylJwLL3QMxUNLup273PM1yV4,1128
|
|
15
|
+
pysdkit/metrics/__init__.py,sha256=4TgRjJuOxNMCEloP-Vnq-z5VnrzYKQCypUaAMJb_nkI,169
|
|
16
|
+
pysdkit/plot/__init__.py,sha256=_SklnKYnFm42Yso9R_UGkzwyyi98tTngkHhgQ4JrIug,92
|
|
17
|
+
pysdkit/plot/_fourier_spectra.py,sha256=7HzjHf6EeZ2DScgvMvveIQYSPVhXLfQSL6sGSUJmGZc,5068
|
|
18
|
+
pysdkit/plot/_functions.py,sha256=rakosRbEg6KgdQJB26x6DGO6On3Ht9KD2MR2Wu7gSyc,4040
|
|
19
|
+
pysdkit/plot/_plot_imfs.py,sha256=YsVyazrSwBzQ3EmLj7pzZqVmxolTbSljYnAP-sIJRdQ,4239
|
|
20
|
+
pysdkit/plot/main.py,sha256=O_CKGAPPVaNBOqZwA7FrWcGJJEz76bbL_PomNJMtO7w,102
|
|
21
|
+
pysdkit/utils/__init__.py,sha256=6M-DhV8ghK_O2PoMBnj6tLbv_3XcR1CeAqxw-DM0Ass,1076
|
|
22
|
+
pysdkit/utils/_differ.py,sha256=q0AoYecFLOlPsFcbjV7G_r4AGfp8WfVJ3aD9rbHIdJo,866
|
|
23
|
+
pysdkit/utils/_fft.py,sha256=VgluJaLeuuJ333_kJH1CKDbnlc6m_KX60pNfdRbv73Q,472
|
|
24
|
+
pysdkit/utils/_function.py,sha256=dBF4gSjEBavAZjx0PrnZ8Z_iBk5T-zLmU3XEC1XvwTE,1436
|
|
25
|
+
pysdkit/utils/_smooth1d.py,sha256=ICovGCD53Wb0YX2b0eOPEsrK85RNccbbb_zA_Wu4_Bw,3485
|
|
26
|
+
pysdkit/utils/hilbert.py,sha256=74DLvAmfWOdhS391RoRBAzJ-P6rnldaPLYc3xexNPWI,3793
|
|
27
|
+
pysdkit/utils/mirror.py,sha256=I4mV_pskDQjuPxLfq20jIOY0MRHI1doZd3wxvaxQhTI,1195
|
|
28
|
+
pysdkit/utils/process.py,sha256=mtlY6ftqwdtjXVLVxvczUb0_ug41jZa5k__29hUR1cc,6149
|
|
29
|
+
pysdkit/vmd/__init__.py,sha256=nNmNpo65_SlqZhqQXsYj-FRkCO-KHSRY2XeGp5vmzPo,73
|
|
30
|
+
pysdkit/vmd/_avmd.py,sha256=xUtmiyFOqkol7Oqh_yDPzGAr6b7FrfVXG6AlDOnTvr8,473
|
|
31
|
+
pysdkit/vmd/_mvmd.py,sha256=ANXqmfJA0Y5Ib80Yw0URzqHIIFFiJfg5p1CswTXiM1o,9109
|
|
32
|
+
pysdkit/vmd/_svmd.py,sha256=JDoR0BrocbsHn-zeg2fJ4wkuykEVh700yZKdgPk5M2o,384
|
|
33
|
+
pysdkit/vmd/_vmd_c.py,sha256=BxgdERwbyEE88NWvaKCuhSBxB3gz9hUr-2qWDoRpfZU,8758
|
|
34
|
+
pysdkit/vmd/_vmd_f.py,sha256=kb2GiAThe_xqU7qLATkOdlbXj4kWFFLayKJ1nouc6eQ,5402
|
|
35
|
+
pysdkit/vmd/base.py,sha256=frcDhMadR2WHM6UTnjGgufAiZhweqrNti9E71h7zUQI,3442
|
|
36
|
+
pysdkit/vncmd/__init__.py,sha256=n9grWZ12fpbtfAtiQO50Bkg1sB0eiUDXbiMmbWk_i8c,25
|
|
37
|
+
pysdkit/vncmd/vncmd.py,sha256=digpTAUGRsddbS3bM-9p6-5tENq-__AT7aonYgVHEzA,12362
|
|
38
|
+
PySDKit-0.4.dist-info/LICENSE,sha256=ogEPNDSH0_dhiv_lT3ifVIdgIzHAqNA_SemnxUfPBJk,7048
|
|
39
|
+
PySDKit-0.4.dist-info/METADATA,sha256=of4rNNif_JkVzmWHNyit6nXJjnqvKGTV4anDdQ9HOFw,4268
|
|
40
|
+
PySDKit-0.4.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
|
41
|
+
PySDKit-0.4.dist-info/top_level.txt,sha256=wN_Yil0woB5Tu_WrIRt4_T4eoRyXljCYvH0dL6-7ei0,8
|
|
42
|
+
PySDKit-0.4.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pysdkit
|
pysdkit/__init__.py
ADDED
pysdkit/data/__init__.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Created on 2024/7/22 22:56
|
|
4
|
+
@author: Whenxuan Wang
|
|
5
|
+
@email: wwhenxuan@gmail.com
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
# A series of functions for generating 1D NumPy signals
|
|
9
|
+
from ._generator import generate_sin_signal, generate_cos_signal
|
|
10
|
+
from ._generator import generate_square_wave, generate_triangle_wave, generate_sawtooth_wave
|
|
11
|
+
from ._generator import generate_am_signal, generate_exponential_signal
|
|
12
|
+
|
|
13
|
+
# Generates the main test sample signal
|
|
14
|
+
from ._generator import test_emd
|
|
15
|
+
|
|
16
|
+
# Functions that generate signal visualizations
|
|
17
|
+
from ._generator import plot_generate_signal
|
|
18
|
+
|
|
19
|
+
# add Gaussian noise
|
|
20
|
+
from ._add_noise import add_noise
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Created on Sat Mar 8 21:45:02 2024
|
|
4
|
+
@author: Whenxuan Wang
|
|
5
|
+
@email: wwhenxuan@gmail.com
|
|
6
|
+
"""
|
|
7
|
+
import numpy as np
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def add_noise(N: int, Mean: float, STD: float) -> np.ndarray:
|
|
11
|
+
"""
|
|
12
|
+
Generate Gaussian white noise with mean values Mean and standard deviation STD.
|
|
13
|
+
:param N: The number of samples.
|
|
14
|
+
:param Mean: The mean value of the noise.
|
|
15
|
+
:param STD: The standard deviation of the noise.
|
|
16
|
+
:return: numpy.ndarray: Generated Gaussian white noise.
|
|
17
|
+
"""
|
|
18
|
+
# Generate noise using the given mean and standard deviation
|
|
19
|
+
y = np.random.randn(N)
|
|
20
|
+
# Standardize y so that its standard deviation is 1
|
|
21
|
+
y = y / np.std(y)
|
|
22
|
+
# Adjust y so that its mean is 0
|
|
23
|
+
y = y - np.mean(y)
|
|
24
|
+
# Generate noise using the given mean and standard deviation
|
|
25
|
+
y = Mean + STD * y
|
|
26
|
+
|
|
27
|
+
return y
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
if __name__ == '__main__':
|
|
31
|
+
N = 1000
|
|
32
|
+
Mean = 0
|
|
33
|
+
STD = 1
|
|
34
|
+
noise = add_noise(N, Mean, STD)
|
|
35
|
+
print(noise)
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Created on Sat Mar 8 21:45:02 2024
|
|
4
|
+
@author: Whenxuan Wang
|
|
5
|
+
@email: wwhenxuan@gmail.com
|
|
6
|
+
"""
|
|
7
|
+
import numpy as np
|
|
8
|
+
from scipy.signal import sawtooth
|
|
9
|
+
from matplotlib import pyplot as plt
|
|
10
|
+
|
|
11
|
+
from typing import Tuple
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def generate_sin_signal(duration: float = 1.0, sampling_rate: int = 1000, noise_level: float = 0.2,
|
|
15
|
+
frequency: float = 10.0, rand_state: int = 42) -> Tuple[np.array, np.array]:
|
|
16
|
+
"""
|
|
17
|
+
Generate a Cosine signal with Gaussian noise and a sinusoidal component.
|
|
18
|
+
:param duration: Length of the signal in seconds.
|
|
19
|
+
:param sampling_rate: Number of samples per second.
|
|
20
|
+
:param noise_level: Standard deviation of the Gaussian noise.
|
|
21
|
+
:param frequency: Frequency of the sinusoidal component.
|
|
22
|
+
:param rand_state: Random seed for the noise in signal.
|
|
23
|
+
:return: Array of the Cosine signal.
|
|
24
|
+
"""
|
|
25
|
+
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
|
|
26
|
+
signal = np.sin(2 * np.pi * frequency * t) # Sinusoidal signal
|
|
27
|
+
np.random.seed(seed=rand_state)
|
|
28
|
+
noise = np.random.normal(0, noise_level, signal.shape) # Gaussian noise
|
|
29
|
+
emg_signal = signal + noise # Superimpose signal and noise
|
|
30
|
+
return t, emg_signal
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def generate_cos_signal(duration: float = 1.0, sampling_rate: int = 1000, noise_level: float = 0.2,
|
|
34
|
+
frequency: float = 10.0, rand_state: int = 42) -> Tuple[np.array, np.array]:
|
|
35
|
+
"""
|
|
36
|
+
Generate a Cosine signal with Gaussian noise and a sinusoidal component.
|
|
37
|
+
:param duration: Length of the signal in seconds.
|
|
38
|
+
:param sampling_rate: Number of samples per second.
|
|
39
|
+
:param noise_level: Standard deviation of the Gaussian noise.
|
|
40
|
+
:param frequency: Frequency of the sinusoidal component.
|
|
41
|
+
:param rand_state: Random seed for the noise in signal.
|
|
42
|
+
:return: Array of the Cosine signal.
|
|
43
|
+
"""
|
|
44
|
+
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
|
|
45
|
+
signal = np.cos(2 * np.pi * frequency * t) # Sinusoidal signal
|
|
46
|
+
np.random.seed(seed=rand_state)
|
|
47
|
+
noise = np.random.normal(0, noise_level, signal.shape) # Gaussian noise
|
|
48
|
+
emg_signal = signal + noise # Superimpose signal and noise
|
|
49
|
+
return t, emg_signal
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def generate_square_wave(duration: float = 1.0, sampling_rate: int = 1000, noise_level: float = 0.2,
|
|
53
|
+
frequency: float = 10.0, rand_state: int = 42) -> Tuple[np.array, np.array]:
|
|
54
|
+
"""
|
|
55
|
+
Generate a square wave signal with Gaussian noise.
|
|
56
|
+
:param duration: Length of the signal in seconds.
|
|
57
|
+
:param sampling_rate: Number of samples per second.
|
|
58
|
+
:param noise_level: Standard deviation of the Gaussian noise.
|
|
59
|
+
:param frequency: Frequency of the square wave component.
|
|
60
|
+
:param rand_state: Random seed for the noise in signal.
|
|
61
|
+
:return: Tuple containing time array and the square wave signal with noise.
|
|
62
|
+
"""
|
|
63
|
+
np.random.seed(rand_state)
|
|
64
|
+
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
|
|
65
|
+
square_wave = np.sign(np.sin(2 * np.pi * frequency * t)) # Generate a basic square wave
|
|
66
|
+
noise = np.random.normal(0, noise_level, square_wave.shape) # Gaussian noise
|
|
67
|
+
noisy_square_wave = square_wave + noise
|
|
68
|
+
return t, noisy_square_wave
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def generate_triangle_wave(duration: float = 1.0, sampling_rate: int = 1000, noise_level: float = 0.2,
|
|
72
|
+
frequency: float = 10.0, rand_state: int = 42) -> Tuple[np.array, np.array]:
|
|
73
|
+
"""
|
|
74
|
+
Generate a triangular wave signal with Gaussian noise.
|
|
75
|
+
:param duration: Length of the signal in seconds.
|
|
76
|
+
:param sampling_rate: Number of samples per second.
|
|
77
|
+
:param noise_level: Standard deviation of the Gaussian noise.
|
|
78
|
+
:param frequency: Frequency of the triangular wave component.
|
|
79
|
+
:param rand_state: Random seed for the noise in signal.
|
|
80
|
+
:return: Tuple containing time array and the triangular wave signal with noise.
|
|
81
|
+
"""
|
|
82
|
+
np.random.seed(rand_state) # Set random seed for reproducibility
|
|
83
|
+
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
|
|
84
|
+
# Generate the triangular wave using the sawtooth function and converting it to a triangular shape
|
|
85
|
+
from scipy.signal import sawtooth
|
|
86
|
+
triangle_wave = 2 * np.abs(sawtooth(2 * np.pi * frequency * t, 0.5)) - 1
|
|
87
|
+
noise = np.random.normal(0, noise_level, triangle_wave.shape) # Add Gaussian noise
|
|
88
|
+
noisy_triangle_wave = triangle_wave + noise # Combine triangle wave with noise
|
|
89
|
+
return t, noisy_triangle_wave
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def generate_sawtooth_wave(duration: float = 1.0, sampling_rate: int = 1000, noise_level: float = 0.2,
|
|
93
|
+
frequency: float = 10.0, rand_state: int = 42) -> Tuple[np.array, np.array]:
|
|
94
|
+
"""
|
|
95
|
+
Generate a sawtooth wave signal with Gaussian noise.
|
|
96
|
+
:param duration: Length of the signal in seconds.
|
|
97
|
+
:param sampling_rate: Number of samples per second.
|
|
98
|
+
:param noise_level: Standard deviation of the Gaussian noise.
|
|
99
|
+
:param frequency: Frequency of the sawtooth wave component.
|
|
100
|
+
:param rand_state: Random seed for the noise in signal.
|
|
101
|
+
:return: Tuple containing time array and the sawtooth wave signal with noise.
|
|
102
|
+
"""
|
|
103
|
+
np.random.seed(rand_state) # Set the random seed for reproducibility
|
|
104
|
+
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
|
|
105
|
+
saw_wave = sawtooth(2 * np.pi * frequency * t) # Generate a pure sawtooth wave
|
|
106
|
+
noise = np.random.normal(0, noise_level, saw_wave.shape) # Add Gaussian noise
|
|
107
|
+
noisy_saw_wave = saw_wave + noise # Combine sawtooth wave with noise
|
|
108
|
+
return t, noisy_saw_wave
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def generate_am_signal(duration: float = 1.0, sampling_rate: int = 1000, noise_level: float = 0.1,
|
|
112
|
+
carrier_freq: float = 100.0, modulating_freq: float = 5.0, mod_index: float = 1.0,
|
|
113
|
+
rand_state: int = 42) -> Tuple[np.array, np.array]:
|
|
114
|
+
"""
|
|
115
|
+
Generate an Amplitude Modulated (AM) signal with Gaussian noise.
|
|
116
|
+
:param duration: Length of the signal in seconds.
|
|
117
|
+
:param sampling_rate: Number of samples per second.
|
|
118
|
+
:param noise_level: Standard deviation of the Gaussian noise.
|
|
119
|
+
:param carrier_freq: Frequency of the carrier signal.
|
|
120
|
+
:param modulating_freq: Frequency of the modulating signal.
|
|
121
|
+
:param mod_index: Modulation index.
|
|
122
|
+
:param rand_state: Random seed for the noise generation.
|
|
123
|
+
:return: Tuple containing time array and the AM signal with noise.
|
|
124
|
+
"""
|
|
125
|
+
np.random.seed(rand_state) # Set the random seed for reproducibility
|
|
126
|
+
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
|
|
127
|
+
# Carrier signal
|
|
128
|
+
carrier = np.cos(2 * np.pi * carrier_freq * t)
|
|
129
|
+
# Modulating signal
|
|
130
|
+
modulating_signal = np.cos(2 * np.pi * modulating_freq * t)
|
|
131
|
+
# Amplitude Modulated signal
|
|
132
|
+
am_signal = (1 + mod_index * modulating_signal) * carrier
|
|
133
|
+
# Add Gaussian noise
|
|
134
|
+
noise = np.random.normal(0, noise_level, am_signal.shape)
|
|
135
|
+
noisy_am_signal = am_signal + noise # AM signal with noise
|
|
136
|
+
return t, noisy_am_signal
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def generate_exponential_signal(duration: float = 1.0, sampling_rate: int = 1000, noise_level: float = 0.1,
|
|
140
|
+
decay_rate: float = 1.0, initial_amplitude: float = 1.0,
|
|
141
|
+
rand_state: int = 42) -> Tuple[np.array, np.array]:
|
|
142
|
+
"""
|
|
143
|
+
Generate an exponentially decaying signal with Gaussian noise.
|
|
144
|
+
:param duration: Length of the signal in seconds.
|
|
145
|
+
:param sampling_rate: Number of samples per second.
|
|
146
|
+
:param noise_level: Standard deviation of the Gaussian noise.
|
|
147
|
+
:param decay_rate: Exponential decay rate (larger values decay faster).
|
|
148
|
+
:param initial_amplitude: Initial amplitude of the signal.
|
|
149
|
+
:param rand_state: Random seed for the noise generation.
|
|
150
|
+
:return: Tuple containing time array and the exponentially decaying signal with noise.
|
|
151
|
+
"""
|
|
152
|
+
np.random.seed(rand_state) # Set the random seed for reproducibility
|
|
153
|
+
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
|
|
154
|
+
# Exponentially decaying signal
|
|
155
|
+
exp_signal = initial_amplitude * np.exp(-decay_rate * t)
|
|
156
|
+
# Add Gaussian noise
|
|
157
|
+
noise = np.random.normal(0, noise_level, exp_signal.shape)
|
|
158
|
+
noisy_exp_signal = exp_signal + noise # Exponential signal with noise
|
|
159
|
+
return t, noisy_exp_signal
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def base_example(duration: float = 6.0, sampling_rate: int = 128, noise_level: float = 0.0,
|
|
163
|
+
random_state: int = 42) -> Tuple[np.array, np.array]:
|
|
164
|
+
"""
|
|
165
|
+
Generate 5 * sin(2 * pi * t) + 3 * sin(2 * pi * t)
|
|
166
|
+
:param duration: Length of the signal in seconds.
|
|
167
|
+
:param sampling_rate: Number of samples per second.
|
|
168
|
+
:param noise_level: Standard deviation of the Gaussian noise.
|
|
169
|
+
:param random_state: Random seed for the noise generation.
|
|
170
|
+
:return: Tuple containing time array and the 5 * sin(2 * pi * t) + 3 * sin(2 * pi * t) signal with noise.
|
|
171
|
+
"""
|
|
172
|
+
np.random.seed(seed=random_state)
|
|
173
|
+
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
|
|
174
|
+
signal = 5 * np.sin(2 * np.pi * t) + 3 * np.sin(2 * np.pi * t)
|
|
175
|
+
noise = np.random.normal(0, noise_level, signal.shape)
|
|
176
|
+
noise_signal = signal + noise
|
|
177
|
+
return t, noise_signal
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def fun(duration: float = 10.0, sampling_rate: int = 128) -> Tuple[np.array, np.array]:
|
|
181
|
+
"""
|
|
182
|
+
Generate 3 * 2 ^ (-t) * sin(sin(2 * pi * t))
|
|
183
|
+
:param duration: Length of the signal in seconds.
|
|
184
|
+
:param sampling_rate: Number of samples per second.
|
|
185
|
+
:return: Tuple containing time array and the 3 * 2 ^ (-t) * sin(sin(2 * pi * t)) signal.
|
|
186
|
+
"""
|
|
187
|
+
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
|
|
188
|
+
signal = 3 * 2 ^ (-t) * np.sin(np.sin(2 * np.pi * t))
|
|
189
|
+
return t, signal
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def test_emd(duration: float = 1.0, sampling_rate: int = 1000, noise_level: float = 0.1,
|
|
193
|
+
random_state: int = 42) -> Tuple[np.array, np.array]:
|
|
194
|
+
"""
|
|
195
|
+
Generate cos(22 * pi * t ^ 2) + 6 * t ^ 2 for emd test.
|
|
196
|
+
:param duration: Length of the signal in seconds.
|
|
197
|
+
:param sampling_rate: Number of samples per second.
|
|
198
|
+
:param noise_level: Standard deviation of the Gaussian noise.
|
|
199
|
+
:param random_state: Random seed for the noise generation.
|
|
200
|
+
:return: Tuple containing time array and the cos(22 * pi * t ^ 2) + 6 * t ^ 2 signal with noise.
|
|
201
|
+
"""
|
|
202
|
+
np.random.seed(seed=random_state)
|
|
203
|
+
t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)
|
|
204
|
+
signal = np.cos(22 * np.pi * t ** 2) + 2 * t ** 2
|
|
205
|
+
noise = np.random.normal(0, noise_level, signal.shape)
|
|
206
|
+
noise_signal = signal + noise
|
|
207
|
+
return t, noise_signal
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def plot_generate_signal(t: np.array, signal: np.array, color: str = 'royalblue', save: bool = False,
|
|
211
|
+
figsize: Tuple = (12, 4), dpi: int = 600, fontsize: int = 15) -> plt.figure:
|
|
212
|
+
"""
|
|
213
|
+
Plot and optionally save an amplitude modulated (AM) signal with time on the x-axis and amplitude on the y-axis.
|
|
214
|
+
:param t: Array of time points corresponding to the signal.
|
|
215
|
+
:param signal: Array containing the signal data to be plotted.
|
|
216
|
+
:param color: Color of the plot line.
|
|
217
|
+
:param save: Boolean flag to indicate whether the plot should be saved to a file.
|
|
218
|
+
:param figsize: Tuple representing the width and height of the figure in inches.
|
|
219
|
+
:param dpi: Dots per inch (resolution) of the figure, if saved.
|
|
220
|
+
:param fontsize: Font size of the axis labels.
|
|
221
|
+
:return: The figure object containing the plot.
|
|
222
|
+
"""
|
|
223
|
+
# Create a figure and a single subplot
|
|
224
|
+
fig, ax = plt.subplots(figsize=figsize)
|
|
225
|
+
# Plot the signal against time with specified line color
|
|
226
|
+
ax.plot(t, signal, color=color)
|
|
227
|
+
# Set the x-axis label with specified font size
|
|
228
|
+
ax.set_xlabel('Time (seconds)', fontsize=fontsize)
|
|
229
|
+
# Set the y-axis label with default font size
|
|
230
|
+
ax.set_ylabel('Amplitude')
|
|
231
|
+
# Enable grid for better readability
|
|
232
|
+
ax.grid(True)
|
|
233
|
+
# Display the plot
|
|
234
|
+
plt.show()
|
|
235
|
+
# Check if the figure needs to be saved
|
|
236
|
+
if save:
|
|
237
|
+
# Save the figure with the specified dpi and bounding box tightly around the figure
|
|
238
|
+
fig.savefig("generate_signal.jpg", dpi=dpi, bbox_inches='tight')
|
|
239
|
+
# Return the figure object
|
|
240
|
+
return fig
|