30 lines
559 B
Python
30 lines
559 B
Python
import numpy as np
|
|
import numba as nb
|
|
from numba import njit
|
|
|
|
|
|
|
|
def gussian_jitter(RMS_jitter, size, seed=None):
|
|
return np.random.default_rng(seed).normal(0, RMS_jitter/2, size)
|
|
|
|
|
|
@njit(fastmath=True)
|
|
def square_with_jitter(time, freq, jitter):
|
|
n = len(time)
|
|
wave = np.empty(n)
|
|
timestep = time[1] - time[0]
|
|
|
|
phase = 0.
|
|
for i in range(n):
|
|
phase += 360 * freq * (timestep + jitter[i])
|
|
wave[i] = square(phase)
|
|
return wave
|
|
|
|
|
|
@njit
|
|
def square(x):
|
|
if np.mod(x, 360) < 180:
|
|
return 0
|
|
else:
|
|
return 1
|