-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example1D_Wavelet.py
executable file
·65 lines (52 loc) · 1.66 KB
/
Example1D_Wavelet.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
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/python -u
# the needed extern modules
import numpy as np
# own module
import sigmatransform as st
# setup
np.set_printoptions(precision=2,edgeitems=10,linewidth=120)
numsteps = 400.0;
winwidth = 4.0;
# the channels
Fs = 143000.0;
chan = np.linspace( np.log2(Fs*0.005) , np.log2(Fs/2.0*1.1) , numsteps );
# the diffeomorphism
def sig(x):
return np.log2( x * (x>0.0) );
# the adapted Gaussian window in warped domain
def win(x):
return np.exp(-np.pi*( x / sig(Fs) * numsteps / winwidth )**2 );
# the signal
f = np.loadtxt("bat.asc");
# get an instance
Wavelet = st.SigmaTransform(
sig , # the diffeomorphism handle
win , # the window handle
Fs , # the sampling Frequency
len(f), # the length of the signal
chan # the channels in warped Fourier domain
);
# analyze the signal f (coeff is stored internally, so no need to capture "coeff" right now)...
Wavelet.analyze( f );
# ...and get coeffs
co = Wavelet.coeff;
# try to reconstruct "f" from its coefficients (without dual frame, so depends on the chosen channels)
# and store in "recVec"
recVec = Wavelet.synthesize().rec;
# plot the modulus of the ceofficients
Wavelet.plotCoeff();
# apply Wavelet-Multiplier...
Wavelet.analyze(f).applyMaskFunc(lambda x,y : (x>.5)*(y>10)+.5 ).synthesize();
#recMasked = Wavelet.rec;
Wavelet.plotCoeff();
# ...or, as a "one-liner":
recMasked = st.SigmaTransform(
lambda x : np.log2( x * (x>0.0) ),
lambda x : np.exp(-np.pi*( x / sig(Fs) * 400.0 / 4.0 )**2 ),
143000,
400,
np.linspace( np.log2(Fs*0.005) , np.log2(Fs/2.0*1.1) , 400 )
).multiplier(
np.loadtxt("bat.asc"),
lambda x,y : (x < .5)*(y>10) + .2
).plotCoeff();