new interp method
This commit is contained in:
@@ -15,7 +15,6 @@ class NoiseMeasurement:
|
|||||||
freq: np.ndarray
|
freq: np.ndarray
|
||||||
psd: np.ndarray
|
psd: np.ndarray
|
||||||
phase: np.ndarray | None = None
|
phase: np.ndarray | None = None
|
||||||
psd_interp: interp1d = field(init=False)
|
|
||||||
rng: np.random.Generator = field(default_factory=np.random.default_rng)
|
rng: np.random.Generator = field(default_factory=np.random.default_rng)
|
||||||
_window_functions: ClassVar[dict[str, Callable[[int], np.ndarray]]] = {}
|
_window_functions: ClassVar[dict[str, Callable[[int], np.ndarray]]] = {}
|
||||||
|
|
||||||
@@ -77,11 +76,6 @@ class NoiseMeasurement:
|
|||||||
psd = psd.real**2 + psd.imag**2
|
psd = psd.real**2 + psd.imag**2
|
||||||
return cls(freq, psd.mean(axis=0) / window_correction, phase=phase)
|
return cls(freq, psd.mean(axis=0) / window_correction, phase=phase)
|
||||||
|
|
||||||
def __post_init__(self):
|
|
||||||
self.psd_interp = interp1d(
|
|
||||||
self.freq, self.psd, fill_value=(0, self.psd[-1]), bounds_error=False
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def psd_dBc(self) -> np.ndarray:
|
def psd_dBc(self) -> np.ndarray:
|
||||||
return math.to_dB(self.psd, ref=1.0)
|
return math.to_dB(self.psd, ref=1.0)
|
||||||
@@ -168,7 +162,7 @@ class NoiseMeasurement:
|
|||||||
)
|
)
|
||||||
|
|
||||||
f = np.linspace(0, fmax, nt // 2 + 1)
|
f = np.linspace(0, fmax, nt // 2 + 1)
|
||||||
interp = self.psd_interp(f)
|
interp = np.interp(f, self.freq, self.psd, left=0, right=self.psd[-1])
|
||||||
interp[0] = 0
|
interp[0] = 0
|
||||||
return f, interp
|
return f, interp
|
||||||
|
|
||||||
@@ -208,10 +202,6 @@ class NoiseMeasurement:
|
|||||||
return integrated_noise(self.freq, self.psd)
|
return integrated_noise(self.freq, self.psd)
|
||||||
|
|
||||||
|
|
||||||
def log_power(x):
|
|
||||||
return 10 * np.log10(np.abs(np.where(x == 0, 1e-7, x)))
|
|
||||||
|
|
||||||
|
|
||||||
def integrated_noise(freq: np.ndarray, psd: np.ndarray) -> float:
|
def integrated_noise(freq: np.ndarray, psd: np.ndarray) -> float:
|
||||||
"""
|
"""
|
||||||
given a normalized spectrum, computes the total rms RIN in the provided frequency window
|
given a normalized spectrum, computes the total rms RIN in the provided frequency window
|
||||||
|
|||||||
Reference in New Issue
Block a user