-
Notifications
You must be signed in to change notification settings - Fork 0
/
whiten.py
55 lines (32 loc) · 1.22 KB
/
whiten.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from numpy import arange, sqrt, abs, multiply, conjugate, real
from obspy.signal.util import nextpow2
from scipy.fftpack import fft, ifft
import copy
def spectralwhitening(stream):
stream2 = copy.deepcopy(stream)
for trace in arange(len(stream2)):
data = stream2[trace].data
n = len(data)
nfft = nextpow2(n)
spec = fft(data, nfft)
spec_ampl = sqrt(abs(multiply(spec, conjugate(spec))))
spec /= spec_ampl # Do we need to do some smoothing here?
ret = real(ifft(spec, nfft)[:n])
stream2[trace].data = ret
return stream2
def spectralwhitening_smooth(stream, N):
stream2 = copy.deepcopy(stream)
for trace in arange(len(stream2)):
data = stream2[trace].data
n = len(data)
nfft = nextpow2(n)
spec = fft(data, nfft)
spec_ampl = sqrt(abs(multiply(spec, conjugate(spec))))
spec_ampl = smooth(spec_ampl, N)
spec /= spec_ampl # Do we need to do some smoothing here?
ret = real(ifft(spec, nfft)[:n])
stream2[trace].data = ret
return stream2
def smooth(spec_ampl, N):
spec_ampl_2 = spec_ampl
return spec_ampl_2