Skip to content

Commit 65181a3

Browse files
author
dl
committed
initial
0 parents  commit 65181a3

File tree

4 files changed

+586
-0
lines changed

4 files changed

+586
-0
lines changed

Example1D_STFT.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/python -u
2+
3+
# the needed extern modules
4+
import numpy as np
5+
6+
# own module
7+
import sigmatransform as st
8+
9+
# setup
10+
np.set_printoptions(precision=2,edgeitems=10,linewidth=120)
11+
12+
# the channels
13+
Fs = 143000;
14+
chan = np.linspace(-Fs/2.0,Fs/2.0,400);
15+
16+
# the Gaussian window
17+
def win(x):
18+
return np.exp(-np.pi* ( x / Fs * 400 / 16.0 )**2 );
19+
20+
# the (trivial) diffeomorphism (for STFT)
21+
def sig(x): return x;
22+
23+
# the signal
24+
f = np.loadtxt("bat.asc");
25+
26+
# get an instance
27+
STFT = st.SigmaTransform(
28+
sig , # the diffeomorphism handle
29+
win , # the window handle
30+
Fs , # the sampling Frequency
31+
chan # the channels in warped Fourier domain
32+
);
33+
34+
# analyze the signal f (coeff is stored internally, so no need to capture "coeff" right now)...
35+
STFT.analyze( f );
36+
# ...and get coeffs
37+
co = STFT.coeff;
38+
39+
# try to reconstruct "f" from its coefficients (without dual frame, so depends on the chosen channels)
40+
# and store in "recVec"
41+
recVec = STFT.synthesize().rec;
42+
43+
# plot the modulus of the ceofficients
44+
STFT.plotCoeff();
45+
46+
# apply multiplier...
47+
STFT.analyze(f).applyMaskFunc(lambda x,y : (x>.5)*(y>0)+.5 ).synthesize();
48+
recMasked = STFT.rec;
49+
STFT.plotCoeff();
50+
51+
# ...or short:
52+
recMasked = st.SigmaTransform(
53+
lambda x : x,
54+
lambda x : np.exp(-np.pi*(x/Fs*400.0/16.0)**2),
55+
143000,
56+
np.linspace(-Fs/2.0,Fs/2.0,400)
57+
).multiplier(
58+
np.loadtxt("bat.asc"),
59+
lambda x,y : (x < .5)*(y<0) + .2
60+
).plotCoeff();

Example1D_Wavelet.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/python -u
2+
3+
# the needed extern modules
4+
import numpy as np
5+
6+
# own module
7+
import sigmatransform as st
8+
9+
# setup
10+
np.set_printoptions(precision=2,edgeitems=10,linewidth=120)
11+
numsteps = 400.0;
12+
winwidth = 4.0;
13+
14+
# the channels
15+
Fs = 143000.0;
16+
chan = np.linspace( np.log2(Fs*0.005) , np.log2(Fs/2.0*1.1) , numsteps );
17+
18+
# the diffeomorphism
19+
def sig(x):
20+
return np.log2( x * (x>0.0) );
21+
22+
# the adapted Gaussian window in warped domain
23+
def win(x):
24+
return np.exp(-np.pi*( x / sig(Fs) * numsteps / winwidth )**2 );
25+
26+
# the signal
27+
f = np.loadtxt("bat.asc");
28+
29+
# get an instance
30+
Wavelet = st.SigmaTransform(
31+
sig , # the diffeomorphism handle
32+
win , # the window handle
33+
Fs , # the sampling Frequency
34+
chan # the channels in warped Fourier domain
35+
);
36+
37+
# analyze the signal f (coeff is stored internally, so no need to capture "coeff" right now)...
38+
Wavelet.analyze( f );
39+
# ...and get coeffs
40+
co = Wavelet.coeff;
41+
42+
# try to reconstruct "f" from its coefficients (without dual frame, so depends on the chosen channels)
43+
# and store in "recVec"
44+
recVec = Wavelet.synthesize().rec;
45+
46+
# plot the modulus of the ceofficients
47+
Wavelet.plotCoeff();
48+
49+
# apply Wavelet-Multiplier...
50+
Wavelet.analyze(f).applyMaskFunc(lambda x,y : (x>.5)*(y>10)+.5 ).synthesize();
51+
#recMasked = Wavelet.rec;
52+
Wavelet.plotCoeff();
53+
54+
# ...or, as a "one-liner":
55+
recMasked = st.SigmaTransform(
56+
lambda x : np.log2( x * (x>0.0) ),
57+
lambda x : np.exp(-np.pi*( x / sig(Fs) * 400.0 / 4.0 )**2 ),
58+
143000,
59+
np.linspace( np.log2(Fs*0.005) , np.log2(Fs/2.0*1.1) , 400 )
60+
).multiplier(
61+
np.loadtxt("bat.asc"),
62+
lambda x,y : (x < .5)*(y>10) + .2
63+
).plotCoeff();

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
# SigmaTransform-Python
3+
Implements the Sigma Transform in Python
4+
5+
## Contents
6+
- [General Information](#general-information)
7+
- [Usage and Examples](#usage-and-examples)
8+
9+
# General information
10+
This repository shows an exemplary implementation of the "SigmaTransform", as defined in the thesis _"Quantum Frames and Uncertainty Principles arising from Symplectomorphisms"_, written in Python.
11+
12+
Note that this library is not intended to show maximal performance, but show the usability of the universal interface of the "Sigma Transform" to perform well-known signal processing transforms / algorithms like the Short-Time Fourier Transform and Wavelet Transform.
13+
14+
Currently, only the one-dimensional SigmaTransform is implemented
15+
16+
# Usage and Examples
17+
Clone this repository, or copy the file "sigmatransform.py" to a local folder.
18+
## Usage
19+
Perform a STFT on a signal "f" and save coefficients as numpy array
20+
```python
21+
import sigmatransform as st
22+
...
23+
# define diffeomorphism
24+
sig = lambda x : x;
25+
# get an instance
26+
STFT = st.SigmaTransform(
27+
sig , # the diffeomorphism handle
28+
win , # the window handle
29+
Fs , # the sampling Frequency
30+
chan # the channels in warped Fourier domain
31+
);
32+
# analyze the signal "f", given as numpy array ...
33+
STFT.analyze( f );
34+
# ...and get coeffs, as numpy array
35+
coeff = STFT.coeff;
36+
```
37+
38+
Perform a Wavelet transform on a signal "f" and plot coefficients
39+
```python
40+
import sigmatransform as st
41+
...
42+
# define diffeomorphism
43+
sig = lambda x : np.log2(x*(x>0));
44+
# get an instance
45+
Wavelet = st.SigmaTransform(
46+
sig , # the diffeomorphism handle
47+
win , # the window handle
48+
Fs , # the sampling Frequency
49+
chan # the channels in warped Fourier domain
50+
);
51+
# analyze the signal "f", given as numpy array ...
52+
Wavelet.analyze( f );
53+
# ... and plot coeffs
54+
Wavelet.plotCoeff();
55+
```
56+
57+
## Examples
58+
The python scripts
59+
```
60+
Example1D_STFT.py
61+
Example1D_Wavelet.py
62+
```
63+
provide more elaborated usage examples.

0 commit comments

Comments
 (0)