OHProcess.py (1003B)
1 import numpy as np 2 from scipy import signal 3 import matplotlib.pyplot as plt 4 5 # Code for simulating drift and variance for the wow control 6 # using an Ornstein-Uhlenbeck process 7 8 freq = 0.5 9 FS = 48000 10 mag = 1.0 11 N = int(FS * 20) 12 13 rr = np.random.normal(0, 1.0, N) 14 def oh_process(inp, N, amt, damping, mean): 15 y = 0 16 out = np.zeros(N) 17 sqrtdelta = 1.0 / np.sqrt(FS); 18 T = 1.0 / FS 19 20 for i in range(N): 21 # y = (y + T * amt * rr[i] + damping * T * mean) / (1.0 + T * damping) 22 y += sqrtdelta * rr[i] * amt 23 y += 0.001 * damping * (mean - y) * T 24 out[i] = y 25 return out 26 27 28 x = mag * np.sin(2 * np.pi * freq / FS * np.arange(N)) 29 plt.plot(x, label='sin') 30 31 for amt in [1.0]: # [0.0, 0.33, 0.67, 1.0]: 32 amt = np.power(amt, 1.15) 33 y = x + oh_process(x, N, amt * 0.5, amt * 0.5 + 0.25, 1.0 * amt) 34 b, a = signal.butter(2, Wn=10, fs=FS) 35 y = signal.lfilter(b, a, y) 36 plt.plot(y, label=f'{amt}') 37 38 # y = np.power(0.5 * (x + 1), 10.0) 39 # plt.plot(y) 40 41 plt.show()