Skip to main content

Synchrosqueezing in Python

Build Status Coverage Status 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
  • Clean code with explanations and learning references
  • Wavelet visualizations

Coming soon

  • Generalized Morse Wavelets

Installation

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

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

Examples

1. Signal recovery under severe noise

image

2. Medical: EEG

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.flipud(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]
x = xo + np.sqrt(2) * np.random.randn(N)

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

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

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

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

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

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.

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].

  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".

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.5.5.tar.gz (47.7 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.5.5-py3-none-any.whl (56.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ssqueezepy-0.5.5.tar.gz
  • Upload date:
  • Size: 47.7 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.5.5.tar.gz
Algorithm Hash digest
SHA256 68b6aad8eace0709261ff464a4fd3532e69cdf017f934505f3ec17d040d8aab8
MD5 44441da189a338f0740cff8cf6c7bb7d
BLAKE2b-256 07aa51fb89ec6ffb52bc216781dd27eacdab2279a5aad2a4b98ea627e1562f5e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ssqueezepy-0.5.5-py3-none-any.whl
  • Upload date:
  • Size: 56.2 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.5.5-py3-none-any.whl
Algorithm Hash digest
SHA256 77f702e52c28c35f53e008aaa7a6e24df91eb6e6c3d8a8e108f6a0929b8d896f
MD5 e90b8fa623f4442ae89b2cc59cbe936e
BLAKE2b-256 d5c8ec2db7ce89df54b59d4b1f66aa416259fdcb1b288f8c1b0c297b2a6f2e39

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 Sentry Error logging StatusPage Status page