-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_noise.py
More file actions
32 lines (27 loc) · 807 Bytes
/
generate_noise.py
File metadata and controls
32 lines (27 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import numpy as np
from math import sqrt,log,sin,cos,pi,exp
def exp_decay(t, A, K):
return A * np.exp(-K*t)
def coloredNoise(params,length):
noise=[]
D=params[0]
lam=params[1]
delta_t=1
n,m = np.random.uniform(0.0,1.0,2)
E=lambda x:exp(-x*delta_t)
e_prev=sqrt(-2*D*lam*log(m))*cos(2*pi*n)
noise.append(e_prev)
for i in range(length-1):
a,b = np.random.uniform(0.0,1.0,2)
h=sqrt(-2*D*lam*(1-E(lam)**2)*log(a))*cos(2*pi*b)
e_next=e_prev*E(lam)+h
noise.append(e_next)
e_prev=e_next
return np.array(noise)
autocorr_params=[30.0,1.0/30.0]
noise_signal=coloredNoise(autocorr_params, 1000)
f_h=open("noisy_signal"+str(autocorr_params[0])+".dat",'w')
for e in noise_signal:
f_h.write(str(-70+e))
f_h.write("\n")
f_h.close