noise improvements

This commit is contained in:
Benoît Sierro
2023-11-02 15:12:46 +01:00
parent e1aa43eaf8
commit dff35df096
3 changed files with 18 additions and 0 deletions

View File

@@ -96,6 +96,7 @@ class NoiseMeasurement:
phase = math.mean_angle(psd)
psd = psd.real**2 + psd.imag**2
psd[..., 1:-1] *= 2
return cls(freq, psd.mean(axis=0) / window_correction, phase=phase)
def plottable(

View File

@@ -149,6 +149,9 @@ class Spectrum(np.ndarray):
return self * np.exp(-(((self.l - pos) / (pulse.fwhm_to_T0_fac["gaussian"] * width)) ** 2))
def measure(self) -> tuple[float, float, float]:
"""returns fwhm, peak power and energy"""
if self.ndim > 1:
return np.asarray([p.measure() for p in self]).T
return pulse.measure_field(self.t, self.time_amp)
def coherence(self, axis: int = 0) -> np.ndarray:

View File

@@ -55,6 +55,20 @@ def test_time_and_back():
assert new_noise.psd == pytest.approx(noise.psd)
def test_nyquist():
"""
generating a time series and tranforming it back yields the same spectrum.
Using segements, the nyquist frequency at least is the same
"""
signal = np.cos(np.arange(1024) * np.pi)
n1 = sc.noise.NoiseMeasurement.from_time_series(signal, 1, None, 1)
n3 = sc.noise.NoiseMeasurement.from_time_series(signal, 1, None, 3)
n15 = sc.noise.NoiseMeasurement.from_time_series(signal, 1, None, 15)
assert n1.psd[-1] == n3.psd[-1] == n15.psd[-1]
def test_sampling():
f = np.geomspace(10, 2e6, 138)
spec = 1 / (f + 1)