Skip to content

chazzmoney/ssqueezepy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Synchrosqueezing in Python

Synchrosqueezing Toolbox ported to Python, authored by Eugene Brevdo, Gaurav Thakur. Original: https://github.com/ebrevdo/synchrosqueezing

Reviewers needed; the repository is in a development stage - details below.

Features

  • Forward & inverse CWT- and STFT-based Synchrosqueezing
  • Forward & inverse discretized Continuous Wavelet Transform (CWT)
  • Forward & inverse discretized Short-Time Fourier Transform (STFT)
  • Phase CWT & STFT

Reviewers needed

An eventual goal is a merged Pull Request to PyWavelets (relevant Issue). Points of review include:

  1. Correctness; plots generated from CWT transforms resemble those in the publications, but not entirely
  2. Completeness; parts of code in the original Github are missing or incorrect, and I'm unable to replace them all
  3. Unit tests; I'm not familiar with Synchrosqueezing itself, so I don't know how to validate its various functionalities
  4. Licensing; unsure how to proceed here; original's says to "Redistributions in binary form must reproduce the above copyright notice" - but I'm not "redistributing" it, I'm distributing my rewriting of it
  5. Code style; I'm aware PyWavelets conforms with PEP8 (but I don't), so I'll edit PR code accordingly

Review To-do:

Correctness:

  • 1. Example 1
  • 2. Example 2

Completeness:

  • 1. freqband in synsq_cwt_inv and synsq_stft_inf is defaulted to an integer, but indexed into as a 2D array; the two have nearly identical docstrings, and reference the same equation, but the equation appears completely irrelevant to both.
  • 2. quadgk has been ported as quadpy's quad (linked its wrapped function), which does not support infinite integration bounds, and has trouble with computing synsq_stft_inv's integral. Needs a workaround.
  • 3. As seen in examples, the y-axis shows "scales", not frequencies - and the relation between the two is neither clear nor linear; it also isn't linear w.r.t. len(t), nv, or fs. Publications show frequencies instead.

Unit tests: Whatever suffices for PyWavelets will suffice for me

Implementation To-do:

One checkmark = code written; two = reviewed

Status Toolbox name Repository name Repository file
[ ] [x] synsq_cwt_fw synsq_cwt_fwd synsq_cwt.py
[ ] [x] synsq_cwt_iw synsq_cwt_inv synsq_cwt.py
[ ] [x] synsq_stft_fw synsq_stft_fwd synsq_stft.py
[ ] [x] synsq_stft_iw synsq_stft_inv synsq_stft.py
[ ] [x] synsq_squeeze synsq_squeeze wavelet_transforms.py
[ ] [x] synsq_cwt_squeeze synsq_cwt_squeeze wavelet_transforms.py
[ ] [x] phase_cwt phase_cwt wavelet_transforms.py
[ ] [x] phase_cwt_num phase_cwt_num wavelet_transforms.py
[ ] [x] cwt_fw cwt_fwd wavelet_transforms.py
[ ] [ ] cwt_iw
[ ] [x] stft_fw stft_fwd stft_transforms.py
[ ] [x] stft_iw stft_inv stft_transforms.py
[ ] [x] phase_stft phase_stft stft_transforms.py
[ ] [x] padsignal padsignal utils.py
[ ] [x] wfiltfn wfiltfn utils.py
[ ] [ ] wfilth
[ ] [x] synsq_adm synsq_adm utils.py
[ ] [x] buffer buffer utils.py
[x] [x] est_riskshrink_thresh est_riskshrink_thresh utils.py
[x] [x] p2up p2up utils.py

There are more unlisted (see original repo), but not all will be implemented, in particular GUI implementations.

Differences w.r.t. original

  • Renamed variables/functions; more Pythonic & readable
  • Removed unused arguments / variables
  • Improved nan/inf handling
  • Added examples; original repo lacks any examples in README
  • Indexing / var references; MATLAB is 1-indexed, and handles object reference / assignment, and 'range' ops, differently
  • Edited docstrings; filled missing info, & few corrections
  • Moved functions; each no longer has its own file, but is grouped with other relevant functions
  • Code style; grouped parts of code as sub-functions for improved readability; indentation for vertical alignment; other
  • Performance; this repo may work faster or slower, as Numpy arrays are faster than C arrays, but some of original funcs use MEX-optimized code with no Numpy equivalent. Also using dense instead of sparse matrices (see below).
  • Performance; this repo will work 10x+ faster for some of the methods which were vectorized out of for-loops

Other:

  • Dense instead of sparse matrices for stft_fwd in stft_transforms.py, as Numpy doesn't handle latter in ops involved

Examples

See examples.py. Links to: paper [1], paper[2]. _inv methods (reconstruction, inversion) have been omitted as they involve freqband.

EX 1: Paper [1], pg. 1086

Only real components shown; imaginary are nearly identical, sometimes sign-opposite.

synsq-CWT (synsq_cwt_fwd) appears to produce strongest agreement with paper (FIG 4), while none of STFT yield any resemblance of anything in the papers. It's also unclear whether synsq_squeeze was used for "synsq" in FIG 4 instead.

EX 2: Paper [2], pg. 18

Similar situation as EX 1; again CWT has close resemblance, and STFT is in a separate reality. The two apparent discrepancies w/ CWT are: (1) slope of the forking incline, steeper in FIG. 3; (2) position of horizontal line, lower in FIG. 3. As for the black lines in FIG 3, they seem to be the (manual) "markings" mentioned under the figure in the paper.

About

Synchrosqueezing Toolbox ported to Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%