Skip to main content

Synchrosqueezing in Python

ssqueezepy CI codecov PyPI version Codacy Badge License: MIT

Synchrosqueezing is a powerful reassignment method that focuses time-frequency representations, and allows extraction of instantaneous amplitudes and frequencies. Friendly overview.

Features

  • Continuous Wavelet Transform (CWT), forward & inverse, and its Synchrosqueezing
  • Short-Time Fourier Transform (STFT), forward & inverse, and its Synchrosqueezing
  • Wavelet visualizations and testing suite
  • Generalized Morse Wavelets
  • Ridge extraction
  • Fastest wavelet transforms in Python1, beating MATLAB

1: feel free to open Issue showing otherwise

Installation

pip install ssqueezepy. Or, for latest version (most likely stable):

pip install git+https://github.com/OverLordGoldDragon/ssqueezepy

GPU & CPU acceleration

Multi-threaded execution is enabled by default (disable via os.environ['SSQ_PARALLEL'] = '0'). GPU requires CuPy >= 8.0.0 and PyTorch >= 1.8.0 installed (enable via os.environ['SSQ_GPU'] = '1'). pyfftw optionally supported for maximum CPU FFT speed. See Performance guide.

Benchmarks

Code. Transforms use padding, float32 precision (float64 supported), and output shape (300, len(x)), averaged over 10 runs. pyfftw not used, which'd speed 1-thread & parallel further. Benched on author's i7-7700HQ, GTX 1070.

len(x)-transform 1-thread CPU parallel gpu pywavelets scipy librosa
10k-cwt 0.126 0.0462 0.00393 3.58 0.523 -
10k-stft 0.108 0.0385 0.00534 - 0.118 0.0909
10k-ssq_cwt 0.372 0.148 0.00941 - - -
10k-ssq_stft 0.282 0.147 0.0278 - - -
160k-cwt 2.99 1.25 0.0367 12.7 10.7 -
160k-stft 1.66 0.418 0.0643 - 1.93 1.38
160k-ssq_cwt 8.38 3.16 0.0856 - - -
160k-ssq_stft 4.65 2.48 0.159 - - -

Examples

1. Signal recovery under severe noise

image

2. Medical: EEG

3. Testing suite: CWT vs STFT, reflect-added parallel linear chirp

4. Ridge extraction: cubic polynom. F.M. + pure tone; noiseless & 1.69dB SNR

More

5. Testing suite: GMW vs Morlet, reflect-added hyperbolic chirp (extreme time-loc.)

6. Higher-order GMW CWT, reflect-added parallel linear chirp, 3.06dB SNR

More examples

Introspection

ssqueezepy is equipped with a visualization toolkit, useful for exploring wavelet behavior across scales and configurations. (Also see explanations and code)


Minimal example

import numpy as np
import matplotlib.pyplot as plt
from ssqueezepy import ssq_cwt, ssq_stft

def viz(x, Tx, Wx):
    plt.imshow(np.abs(Wx), aspect='auto', cmap='jet')
    plt.show()
    plt.imshow(np.abs(Tx), aspect='auto', vmin=0, vmax=.2, cmap='jet')
    plt.show()

#%%# Define signal ####################################
N = 2048
t = np.linspace(0, 10, N, endpoint=False)
xo = np.cos(2 * np.pi * 2 * (np.exp(t / 2.2) - 1))
xo += xo[::-1]  # add self reflected
x = xo + np.sqrt(2) * np.random.randn(N)  # add noise

plt.plot(xo); plt.show()
plt.plot(x);  plt.show()

#%%# CWT + SSQ CWT ####################################
Twxo, Wxo, *_ = ssq_cwt(xo)
viz(xo, Twxo, Wxo)

Twx, Wx, *_ = ssq_cwt(x)
viz(x, Twx, Wx)

#%%# STFT + SSQ STFT ##################################
Tsxo, Sxo, *_ = ssq_stft(xo)
viz(xo, np.flipud(Tsxo), np.flipud(Sxo))

Tsx, Sx, *_ = ssq_stft(x)
viz(x, np.flipud(Tsx), np.flipud(Sx))

Also see ridge extraction README.

Learning resources

  1. Continuous Wavelet Transform, & vs STFT
  2. Synchrosqueezing's phase transform, intuitively
  3. Wavelet time & frequency resolution visuals
  4. Why oscillations in SSQ of mixed sines? Separability visuals
  5. Zero-padding's effect on spectrum

DSP fundamentals: I recommend starting with 3b1b's Fourier Transform, then proceeding with DSP Guide chapters 7-11. The Discrete Fourier Transform lays the foundation of signal processing with real data. Deeper on DFT coefficients here, also 3b1b.

Contributors (noteworthy)

  • David Bondesson: ridge extraction (ridge_extraction.py; examples/: extracting_ridges.py, ridge_extraction/README.md)

References

ssqueezepy was originally ported from MATLAB's Synchrosqueezing Toolbox, authored by E. Brevdo and G. Thakur [1]. Synchrosqueezed Wavelet Transform was introduced by I. Daubechies and S. Maes [2], which was followed-up in [3], and adapted to STFT in [4]. Many implementation details draw from [5]. Ridge extraction based on [6].

  1. G. Thakur, E. Brevdo, N.-S. Fučkar, and H.-T. Wu. "The Synchrosqueezing algorithm for time-varying spectral analysis: robustness properties and new paleoclimate applications", Signal Processing 93:1079-1094, 2013.
  2. I. Daubechies, S. Maes. "A Nonlinear squeezing of the Continuous Wavelet Transform Based on Auditory Nerve Models".
  3. I. Daubechies, J. Lu, H.T. Wu. "Synchrosqueezed Wavelet Transforms: a Tool for Empirical Mode Decomposition", Applied and Computational Harmonic Analysis 30(2):243-261, 2011.
  4. G. Thakur, H.T. Wu. "Synchrosqueezing-based Recovery of Instantaneous Frequency from Nonuniform Samples", SIAM Journal on Mathematical Analysis, 43(5):2078-2095, 2011.
  5. Mallat, S. "Wavelet Tour of Signal Processing 3rd ed".
  6. D. Iatsenko, P. V. E. McClintock, A. Stefanovska. "On the extraction of instantaneous frequencies from ridges in time-frequency representations of signals".

License

ssqueezepy is MIT licensed, as found in the LICENSE file. Some source functions may be under other authorship/licenses; see NOTICE.txt.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ssqueezepy-0.6.1.tar.gz (106.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ssqueezepy-0.6.1-py3-none-any.whl (121.7 kB view details)

Uploaded Python 3

File details

Details for the file ssqueezepy-0.6.1.tar.gz.

File metadata

  • Download URL: ssqueezepy-0.6.1.tar.gz
  • Upload date:
  • Size: 106.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

File hashes

Hashes for ssqueezepy-0.6.1.tar.gz
Algorithm Hash digest
SHA256 6657c4ddc3fa2763dfd4e49b25b36a9990d3a502ed735fd70dac277d93136766
MD5 dae27a8454c45fbb3e03027a03429920
BLAKE2b-256 1f50654b82460667d3750fcae316ab1b07c77311fc4140c0065914575456306b

See more details on using hashes here.

File details

Details for the file ssqueezepy-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: ssqueezepy-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 121.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

File hashes

Hashes for ssqueezepy-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b26483ddf0496f9aa5585a451a0ebbb9c89aa4a59eed6cded24b22f5d5cf4d53
MD5 b4206c22f2da02d85574115707325db7
BLAKE2b-256 12a29e7a9b3e827a2600e4ebb719ade7b6b7269b7b7ef36e221d4f871749fcbc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page