PySDKit 0.1__tar.gz → 0.3__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.1 → PySDKit-0.3}/PKG-INFO +2 -2
- {PySDKit-0.1 → PySDKit-0.3}/PySDKit.egg-info/PKG-INFO +2 -2
- PySDKit-0.3/PySDKit.egg-info/SOURCES.txt +33 -0
- PySDKit-0.3/PySDKit.egg-info/top_level.txt +1 -0
- PySDKit-0.3/pysdkit/__init__.py +5 -0
- PySDKit-0.3/pysdkit/data/__init__.py +10 -0
- PySDKit-0.3/pysdkit/data/generator.py +191 -0
- PySDKit-0.3/pysdkit/emd/EMD.py +455 -0
- PySDKit-0.3/pysdkit/emd/__init__.py +2 -0
- PySDKit-0.3/pysdkit/emd/_find_extrema.py +137 -0
- PySDKit-0.3/pysdkit/emd/_prepare_points.py +270 -0
- PySDKit-0.3/pysdkit/plot/__init__.py +0 -0
- PySDKit-0.3/pysdkit/plot/functions.py +80 -0
- PySDKit-0.3/pysdkit/plot/imf.py +6 -0
- PySDKit-0.3/pysdkit/plot/main.py +4 -0
- PySDKit-0.3/pysdkit/utils/__init__.py +17 -0
- PySDKit-0.3/pysdkit/utils/base.py +45 -0
- PySDKit-0.3/pysdkit/utils/fft.py +22 -0
- PySDKit-0.3/pysdkit/utils/hilbert.py +104 -0
- PySDKit-0.3/pysdkit/utils/mirror.py +24 -0
- PySDKit-0.3/pysdkit/utils/process.py +143 -0
- PySDKit-0.3/pysdkit/utils/splines.py +96 -0
- PySDKit-0.3/pysdkit/vmd/vmd_c.py +172 -0
- PySDKit-0.3/pysdkit/vmd/vmd_f.py +138 -0
- PySDKit-0.3/pysdkit/vncmd/__init__.py +0 -0
- {PySDKit-0.1 → PySDKit-0.3}/setup.py +3 -3
- PySDKit-0.1/PySDKit.egg-info/SOURCES.txt +0 -14
- PySDKit-0.1/PySDKit.egg-info/top_level.txt +0 -5
- PySDKit-0.1/vmd/vmd_c.py +0 -129
- PySDKit-0.1/vmd/vmd_f.py +0 -159
- {PySDKit-0.1 → PySDKit-0.3}/PySDKit.egg-info/dependency_links.txt +0 -0
- {PySDKit-0.1 → PySDKit-0.3}/PySDKit.egg-info/requires.txt +0 -0
- {PySDKit-0.1 → PySDKit-0.3}/README.md +0 -0
- /PySDKit-0.1/emd/__init__.py → /PySDKit-0.3/pysdkit/emd/BEMD.py +0 -0
- {PySDKit-0.1/ewt → PySDKit-0.3/pysdkit/emd2d}/__init__.py +0 -0
- {PySDKit-0.1/mvmd → PySDKit-0.3/pysdkit/ewt}/__init__.py +0 -0
- {PySDKit-0.1/vncmd → PySDKit-0.3/pysdkit/mvmd}/__init__.py +0 -0
- {PySDKit-0.1 → PySDKit-0.3/pysdkit}/vmd/__init__.py +0 -0
- {PySDKit-0.1 → PySDKit-0.3}/setup.cfg +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PySDKit
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 0.3
|
|
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
|
|
7
7
|
Author-email: wwhenxuan@gmail.com
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PySDKit
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 0.3
|
|
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
|
|
7
7
|
Author-email: wwhenxuan@gmail.com
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
PySDKit.egg-info/PKG-INFO
|
|
4
|
+
PySDKit.egg-info/SOURCES.txt
|
|
5
|
+
PySDKit.egg-info/dependency_links.txt
|
|
6
|
+
PySDKit.egg-info/requires.txt
|
|
7
|
+
PySDKit.egg-info/top_level.txt
|
|
8
|
+
pysdkit/__init__.py
|
|
9
|
+
pysdkit/data/__init__.py
|
|
10
|
+
pysdkit/data/generator.py
|
|
11
|
+
pysdkit/emd/BEMD.py
|
|
12
|
+
pysdkit/emd/EMD.py
|
|
13
|
+
pysdkit/emd/__init__.py
|
|
14
|
+
pysdkit/emd/_find_extrema.py
|
|
15
|
+
pysdkit/emd/_prepare_points.py
|
|
16
|
+
pysdkit/emd2d/__init__.py
|
|
17
|
+
pysdkit/ewt/__init__.py
|
|
18
|
+
pysdkit/mvmd/__init__.py
|
|
19
|
+
pysdkit/plot/__init__.py
|
|
20
|
+
pysdkit/plot/functions.py
|
|
21
|
+
pysdkit/plot/imf.py
|
|
22
|
+
pysdkit/plot/main.py
|
|
23
|
+
pysdkit/utils/__init__.py
|
|
24
|
+
pysdkit/utils/base.py
|
|
25
|
+
pysdkit/utils/fft.py
|
|
26
|
+
pysdkit/utils/hilbert.py
|
|
27
|
+
pysdkit/utils/mirror.py
|
|
28
|
+
pysdkit/utils/process.py
|
|
29
|
+
pysdkit/utils/splines.py
|
|
30
|
+
pysdkit/vmd/__init__.py
|
|
31
|
+
pysdkit/vmd/vmd_c.py
|
|
32
|
+
pysdkit/vmd/vmd_f.py
|
|
33
|
+
pysdkit/vncmd/__init__.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pysdkit
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# A series of functions for generating 1D NumPy signals
|
|
2
|
+
from .generator import generate_sin_signal, generate_cos_signal
|
|
3
|
+
from .generator import generate_square_wave, generate_triangle_wave, generate_sawtooth_wave
|
|
4
|
+
from .generator import generate_am_signal, generate_exponential_signal
|
|
5
|
+
|
|
6
|
+
# Generates the main test sample signal
|
|
7
|
+
from .generator import test_emd
|
|
8
|
+
|
|
9
|
+
# Functions that generate signal visualizations
|
|
10
|
+
from .generator import plot_generate_signal
|
|
@@ -0,0 +1,191 @@
|
|
|
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 test_emd(duration: float = 1.0, sampling_rate: int = 1000, noise_level: float = 0.1,
|
|
163
|
+
random_state: int = 42) -> Tuple[np.array, np.array]:
|
|
164
|
+
"""
|
|
165
|
+
Generate cos(22 * pi * t ^ 2) + 6 * t ^ 2 for emd test.
|
|
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 cos(22 * pi * t ^ 2) + 6 * t ^ 2 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 = np.cos(22 * np.pi * t ** 2) + 2 * t ** 2
|
|
175
|
+
noise = np.random.normal(0, noise_level, signal.shape)
|
|
176
|
+
noise_signal = signal + noise
|
|
177
|
+
return t, noise_signal
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def plot_generate_signal(t: np.array, signal: np.array, save: bool = False,
|
|
181
|
+
figsize: Tuple = (12, 4), dpi: int = 600, fontsize: int = 15) -> plt.figure:
|
|
182
|
+
fig, ax = plt.subplots(figsize=figsize)
|
|
183
|
+
ax.plot(t, signal)
|
|
184
|
+
ax.set_xlabel('Time (seconds)', fontsize=fontsize)
|
|
185
|
+
ax.set_ylabel('Amplitude')
|
|
186
|
+
ax.grid(True)
|
|
187
|
+
plt.show()
|
|
188
|
+
# whether to save the figure
|
|
189
|
+
if save is True:
|
|
190
|
+
fig.save("generate_signal.jpg", dpi=dpi, bbox_inches='tight')
|
|
191
|
+
return fig
|