WIP on Pulse Detection

This commit is contained in:
Eric-Teunis de Boone 2023-04-11 14:51:08 +02:00
parent 5ea4a0df17
commit 83811bbd1a
3 changed files with 261 additions and 3 deletions

View file

@ -3,7 +3,10 @@ Various useful utilities (duh)
"""
import numpy as np
import scipy.fft as ft
try:
import scipy.fft as ft
except ImportError:
import numpy.fft as ft
def sampled_time(sample_rate=1, start=0, end=1, offset=0):
return offset + np.arange(start, end, 1/sample_rate)
@ -82,7 +85,7 @@ def fft_bandpass(signal, band, samplerate):
return ft.irfft(fft, signal.size), (fft, freqs)
def deltapeak(timelength=1e3, samplerate=1, offset=None, peaklength=1):
def deltapeak(timelength=1e3, samplerate=1, offset=None, peaklength=1, rng=None):
"""
Generate a series of zeroes with a deltapeak.
@ -108,7 +111,19 @@ def deltapeak(timelength=1e3, samplerate=1, offset=None, peaklength=1):
offset_min = 0 if offset[0] is None else offset[0]
offset_max = N_samples if offset[-1] is None else offset[-1]
offset = (np.random.random(1)*(offset_max - offset_min)+offset_min).astype(int) % N_samples
if 0 < offset_min < 1:
offset_min *= N_samples
if 0 < offset_max < 1:
offset_max *= N_samples
if rng is not None:
rand = rng.random(1)
else:
rand = np.random.random(1)
rand = np.asarray(rand)
offset = (rand * (offset_max - offset_min)+offset_min).astype(int) % N_samples
position = (offset + np.arange(0, peaklength)).astype(int) % N_samples