SignalForge 0.0.2__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.
- SignalForge/__init__.py +6 -0
- SignalForge/nonstationary_nongaussian.py +522 -0
- SignalForge/single_chan_signal.py +1083 -0
- SignalForge/stationary_gaussian.py +110 -0
- SignalForge/stationary_nongaussian.py +934 -0
- SignalForge/utils.py +526 -0
- signalforge-0.0.2.dist-info/METADATA +23 -0
- signalforge-0.0.2.dist-info/RECORD +11 -0
- signalforge-0.0.2.dist-info/WHEEL +5 -0
- signalforge-0.0.2.dist-info/licenses/LICENSE +21 -0
- signalforge-0.0.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import scipy as sp
|
|
3
|
+
import matplotlib.pyplot as plt
|
|
4
|
+
|
|
5
|
+
from .utils import *
|
|
6
|
+
from .single_chan_signal import SingleChanSignal
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class StationaryGaussian(SingleChanSignal):
|
|
10
|
+
"""
|
|
11
|
+
Generates a stationary Gaussian signal with a specified power spectral density (PSD).
|
|
12
|
+
This class inherits from SingleChanSignal.
|
|
13
|
+
|
|
14
|
+
Parameters
|
|
15
|
+
----------
|
|
16
|
+
fpsd : np.ndarray
|
|
17
|
+
Frequency vector of the power spectral density.
|
|
18
|
+
psd : np.ndarray
|
|
19
|
+
Power spectral density values.
|
|
20
|
+
T : float
|
|
21
|
+
Duration of the signal (in seconds).
|
|
22
|
+
dfpsd : float, optional
|
|
23
|
+
Frequency discretization for PSD storage, by default 0.5.
|
|
24
|
+
name : str, optional
|
|
25
|
+
Name of the signal (for plots), by default "".
|
|
26
|
+
var : str, optional
|
|
27
|
+
Variable name (for plots), by default "x".
|
|
28
|
+
unit : str, optional
|
|
29
|
+
Unit of measurement of the signal (for plots), by default "$m/s^2$".
|
|
30
|
+
seed : int, optional
|
|
31
|
+
Seed for the random generator (for reproducibility), by default None.
|
|
32
|
+
interp : str, optional
|
|
33
|
+
Interpolation method for PSD ("lin" or "log"), by default "lin".
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def __init__(
|
|
37
|
+
self,
|
|
38
|
+
fpsd: np.ndarray,
|
|
39
|
+
psd: np.ndarray,
|
|
40
|
+
T: float,
|
|
41
|
+
fs : float = None,
|
|
42
|
+
dfpsd: float = 0.5,
|
|
43
|
+
name: str = "",
|
|
44
|
+
var: str = "x",
|
|
45
|
+
unit: str = "$m/s^2$",
|
|
46
|
+
seed: int = None,
|
|
47
|
+
interp: str = "lin"
|
|
48
|
+
):
|
|
49
|
+
|
|
50
|
+
# Check input dimensions
|
|
51
|
+
if len(fpsd) != len(psd):
|
|
52
|
+
raise AttributeError(
|
|
53
|
+
'The frequency vector and the PSD vector must be the same size.'
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
# Set internal parameters
|
|
57
|
+
if fs is None:
|
|
58
|
+
self.fs = fpsd[-1] * 2 # Nyquist frequency
|
|
59
|
+
else:
|
|
60
|
+
self.fs = fs
|
|
61
|
+
self.T = T
|
|
62
|
+
|
|
63
|
+
# Generate time-domain Gaussian signal
|
|
64
|
+
self.x = self._get_timehistory(fpsd, psd, self.fs, seed, interp)
|
|
65
|
+
|
|
66
|
+
self.signal_type = 'Stationary - Gaussian'
|
|
67
|
+
|
|
68
|
+
# Initialize parent class with signal and metadata
|
|
69
|
+
super().__init__(
|
|
70
|
+
x=self.x,
|
|
71
|
+
fs=self.fs,
|
|
72
|
+
dfpsd=dfpsd,
|
|
73
|
+
name=name,
|
|
74
|
+
var=var,
|
|
75
|
+
unit=unit,
|
|
76
|
+
signal_type=self.signal_type
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
def _get_timehistory(
|
|
80
|
+
self,
|
|
81
|
+
fpsd: np.ndarray,
|
|
82
|
+
psd: np.ndarray,
|
|
83
|
+
fs: float,
|
|
84
|
+
seed: int = None,
|
|
85
|
+
interp: str = 'lin'
|
|
86
|
+
) -> np.ndarray:
|
|
87
|
+
"""
|
|
88
|
+
Generates a Gaussian time history from the given PSD.
|
|
89
|
+
-> called by __init__
|
|
90
|
+
|
|
91
|
+
Parameters
|
|
92
|
+
----------
|
|
93
|
+
fpsd : np.ndarray
|
|
94
|
+
Frequency vector of the power spectral density.
|
|
95
|
+
psd : np.ndarray
|
|
96
|
+
Power spectral density values.
|
|
97
|
+
seed : int, optional
|
|
98
|
+
Random seed for reproducibility.
|
|
99
|
+
|
|
100
|
+
Returns
|
|
101
|
+
-------
|
|
102
|
+
np.ndarray
|
|
103
|
+
Time-domain Gaussian signal.
|
|
104
|
+
"""
|
|
105
|
+
_, signal = get_stationary_gaussian(fpsd, psd, self.T,fs, seed, interp)
|
|
106
|
+
return signal
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
if __name__ == "__main__":
|
|
110
|
+
pass
|