improved from_time_series constructor
This commit is contained in:
@@ -42,7 +42,12 @@ class NoiseMeasurement:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_time_series(
|
def from_time_series(
|
||||||
cls, signal: Sequence[float], dt: float, window: str = "Hann", num_segments: int = 1
|
cls,
|
||||||
|
signal: Sequence[float],
|
||||||
|
dt: float,
|
||||||
|
window: str = "Hann",
|
||||||
|
num_segments: int = 1,
|
||||||
|
force_no_dc: bool = True,
|
||||||
) -> NoiseMeasurement:
|
) -> NoiseMeasurement:
|
||||||
"""
|
"""
|
||||||
compute a PSD from a time-series measurement.
|
compute a PSD from a time-series measurement.
|
||||||
@@ -61,11 +66,21 @@ class NoiseMeasurement:
|
|||||||
num_segments : int, optional
|
num_segments : int, optional
|
||||||
number of segments to cut the signal into. This will trade lower frequency information
|
number of segments to cut the signal into. This will trade lower frequency information
|
||||||
for better variance of the estimated PSD. The default 1 means no cutting.
|
for better variance of the estimated PSD. The default 1 means no cutting.
|
||||||
|
force_no_dc : bool, optional
|
||||||
|
take out the DC component (0-frequency) of each segement after segmentation
|
||||||
"""
|
"""
|
||||||
signal = np.asanyarray(signal)
|
signal = np.asanyarray(signal)
|
||||||
signal_segments = segments(signal, num_segments)
|
signal_segments = segments(signal, num_segments)
|
||||||
|
if force_no_dc:
|
||||||
|
signal_segments = (signal_segments.T - signal_segments.mean(axis=1)).T
|
||||||
n = signal_segments.shape[-1]
|
n = signal_segments.shape[-1]
|
||||||
|
try:
|
||||||
window_arr = cls._window_functions[window](n)
|
window_arr = cls._window_functions[window](n)
|
||||||
|
except KeyError:
|
||||||
|
raise ValueError(
|
||||||
|
f"window function {window!r} not found. "
|
||||||
|
f"Possible values are {set(cls._window_functions)}"
|
||||||
|
) from None
|
||||||
window_correction = np.sum(window_arr**2) / n
|
window_correction = np.sum(window_arr**2) / n
|
||||||
signal_segments = signal_segments * window_arr
|
signal_segments = signal_segments * window_arr
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user