mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2025-05-17 05:19:24 +02:00
ZH: Determine SNR for Airshower vs Noise
This commit is contained in:
parent
aabdca4f98
commit
465b78c535
3 changed files with 113 additions and 14 deletions
|
@ -80,7 +80,7 @@ def bandpower(samples, samplerate=1, band=passband(), normalise_bandsize=True, d
|
|||
|
||||
return power
|
||||
|
||||
def signal_to_noise(samples, noise, samplerate=1, signal_band=passband(), noise_band=None, debug_ax=False):
|
||||
def signal_to_noise(samples, noise, samplerate=1, signal_band=passband(), noise_band=None, debug_ax=False, mode='sine'):
|
||||
if noise_band is None:
|
||||
noise_band = signal_band
|
||||
|
||||
|
@ -90,8 +90,25 @@ def signal_to_noise(samples, noise, samplerate=1, signal_band=passband(), noise_
|
|||
if debug_ax is True:
|
||||
debug_ax = plt.gca()
|
||||
|
||||
noise_power = bandpower(noise, samplerate, noise_band, debug_ax=debug_ax)
|
||||
if mode == 'sine':
|
||||
noise_power = bandpower(noise, samplerate, noise_band, debug_ax=debug_ax)
|
||||
noise_amplitude = np.sqrt(noise_power)
|
||||
|
||||
signal_power = bandpower(samples, samplerate, signal_band, debug_ax=debug_ax)
|
||||
signal_power = bandpower(samples, samplerate, signal_band, debug_ax=debug_ax)
|
||||
signal_amplitude = np.sqrt(signal_power)
|
||||
|
||||
return (signal_power/noise_power)**0.5
|
||||
elif mode == 'pulse':
|
||||
noise_amplitude = np.sqrt(np.mean(noise**2))
|
||||
|
||||
signal_amplitude = max(np.abs(samples))
|
||||
|
||||
if debug_ax:
|
||||
l1 = debug_ax.plot(noise, alpha=0.5)
|
||||
debug_ax.axhline(noise_amplitude, alpha=0.9, color=l1[0].get_color())
|
||||
|
||||
l2 = debug_ax.plot(samples, alpha=0.5)
|
||||
debug_ax.axhline(signal_amplitude, alpha=0.9, color=l2[0].get_color())
|
||||
else:
|
||||
raise NotImplementedError("mode not in ['sine', 'pulse']")
|
||||
|
||||
return signal_amplitude/noise_amplitude
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue