From 227a8978404f41ebaf087371a5527553243cbafe Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Wed, 26 Apr 2023 14:51:49 +0200 Subject: [PATCH] Pulse: noise realisation option to normalise --- simulations/11_pulsed_timing.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/simulations/11_pulsed_timing.py b/simulations/11_pulsed_timing.py index 1a91bba..bdabee5 100755 --- a/simulations/11_pulsed_timing.py +++ b/simulations/11_pulsed_timing.py @@ -53,8 +53,13 @@ class Waveform: def __len__(): return len(self.signal) -def white_noise_realisation(N_samples, noise_sigma=1, rng=rng): - return rng.normal(0, noise_sigma or 0, size=N_samples) +def white_noise_realisation(N_samples, noise_sigma=1, rng=rng, normalise=False): + noise = rng.normal(0, noise_sigma or 0, size=N_samples) + + if normalise: + noise /= max(noise) + + return noise def antenna_bp(trace, low_bp, high_bp, dt, order=3): fs = 1/dt @@ -170,7 +175,7 @@ if __name__ == "__main__": N_residuals = 50*3 if len(sys.argv) < 2 else int(sys.argv[1]) snr_factors = np.concatenate( # 1/noise_amplitude factor ( - [0.25, 0.5, 0.75], + #[0.25, 0.5, 0.75], [1, 1.5, 2, 2.5, 3, 4, 5, 7], [10, 20, 30, 50], [100, 200, 300, 500] @@ -279,7 +284,7 @@ if __name__ == "__main__": ## Add noise noise_amplitude = max(template.signal) * 1/snr_sigma_factor - noise_realisation = noise_amplitude * white_noise_realisation(len(antenna.signal)) + noise_realisation = noise_amplitude * white_noise_realisation(len(antenna.signal), normalise=False) filtered_noise = antenna_bp(noise_realisation, *bp_freq, antenna.dt) antenna.signal += filtered_noise