Skip to main content

Time-frequency analysis through Stockwell transform

Project description

Stockwell

Python package for time-frequency analysis through Stockwell transform.

Based on original code from NIMH MEG Core Facility.

changelog-badge cf-badge PyPI-badge license-badge

Installation

Using Anaconda

If you use Anaconda, the latest release of Stockwell is available via conda-forge.

To install, simply run:

conda install -c conda-forge stockwell

Using pip and PyPI

The latest release of Stockwell is available on the Python Package Index.

You can install it easily through pip:

pip install stockwell

Installation from source

If no precompiled package is available for you architecture on PyPI, or if you want to work on the source code, you will need to compile this package from source.

To obtain the source code, download the latest release from the releases page, or clone the GitHub project.

C compiler

Part of Stockwell is written in C, so you will need a C compiler.

On Linux (Debian or Ubuntu), install the build-essential package:

sudo apt install build-essential

On macOS, install the XCode Command Line Tools:

xcode-select --install

On Windows, install the Microsoft C++ Build Tools.

FFTW

To compile Stockwell, you will need to have FFTW installed.

On Linux and macOS, you can download and compile FFTW from source using the script get_fftw3.sh provided in the scripts directory:

./scripts/get_fftw3.sh

Alternatively, you can install FFTW using your package manager:

  • If you use Anaconda (Linux, macOS, Windows):

    conda install fftw
    
  • If you use Homebrew (macOS)

    brew install fftw
    
  • If you use apt (Debian or Ubuntu)

    sudo apt install libfftw3-dev
    

Install the Python package from source

Finally, install this Python package using pip:

pip install .

Or, alternatively, in "editable" mode:

pip install -e .

Usage

Example usage:

import numpy as np
from scipy.signal import chirp
import matplotlib.pyplot as plt
from stockwell import st

t = np.linspace(0, 10, 5001)
w = chirp(t, f0=12.5, f1=2.5, t1=10, method='linear')

fmin = 0  # Hz
fmax = 25  # Hz
df = 1./(t[-1]-t[0])  # sampling step in frequency domain (Hz)
fmin_samples = int(fmin/df)
fmax_samples = int(fmax/df)
stock = st.st(w, fmin_samples, fmax_samples)
extent = (t[0], t[-1], fmin, fmax)

fig, ax = plt.subplots(2, 1, sharex=True)
ax[0].plot(t, w)
ax[0].set(ylabel='amplitude')
ax[1].imshow(np.abs(stock), origin='lower', extent=extent)
ax[1].axis('tight')
ax[1].set(xlabel='time (s)', ylabel='frequency (Hz)')
plt.show()

You should get the following output:

stockwell.png

You can also compute the inverse Stockwell transform, ex:

inv_stock = st.ist(stock, fmin_samples, fmax_samples)
fig, ax = plt.subplots(2, 1, sharex=True)
ax[0].plot(t, w, label='original signal')
ax[0].plot(t, inv_stock, label='inverse Stockwell')
ax[0].set(ylabel='amplitude')
ax[0].legend(loc='upper right')
ax[1].plot(t, w - inv_stock)
ax[1].set_xlim(0, 10)
ax[1].set(xlabel='time (s)', ylabel='amplitude difference')
plt.show()

inv_stockwell.png

References

Stockwell, R.G., Mansinha, L. & Lowe, R.P., 1996. Localization of the complex spectrum: the S transform, IEEE Trans. Signal Process., 44(4), 998–1001, doi:10.1109/78.492555

S transform on Wikipedia.

Project details


Download files

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

Source Distribution

stockwell-1.1.2.tar.gz (40.7 kB view hashes)

Uploaded Source

Built Distributions

stockwell-1.1.2-cp312-cp312-win_amd64.whl (625.4 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

stockwell-1.1.2-cp312-cp312-musllinux_1_2_x86_64.whl (886.1 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

stockwell-1.1.2-cp312-cp312-musllinux_1_2_i686.whl (702.9 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

stockwell-1.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (706.5 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

stockwell-1.1.2-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (684.3 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686

stockwell-1.1.2-cp312-cp312-macosx_11_0_arm64.whl (416.0 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

stockwell-1.1.2-cp312-cp312-macosx_10_9_x86_64.whl (464.9 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

stockwell-1.1.2-cp311-cp311-win_amd64.whl (625.4 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

stockwell-1.1.2-cp311-cp311-musllinux_1_2_x86_64.whl (886.1 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

stockwell-1.1.2-cp311-cp311-musllinux_1_2_i686.whl (702.8 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

stockwell-1.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (706.4 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

stockwell-1.1.2-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (684.3 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686

stockwell-1.1.2-cp311-cp311-macosx_11_0_arm64.whl (416.0 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

stockwell-1.1.2-cp311-cp311-macosx_10_9_x86_64.whl (464.9 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

stockwell-1.1.2-cp310-cp310-win_amd64.whl (625.4 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

stockwell-1.1.2-cp310-cp310-musllinux_1_2_x86_64.whl (886.1 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

stockwell-1.1.2-cp310-cp310-musllinux_1_2_i686.whl (702.8 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

stockwell-1.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (706.4 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

stockwell-1.1.2-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (684.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

stockwell-1.1.2-cp310-cp310-macosx_11_0_arm64.whl (416.0 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

stockwell-1.1.2-cp310-cp310-macosx_10_9_x86_64.whl (464.9 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

stockwell-1.1.2-cp39-cp39-win_amd64.whl (626.1 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

stockwell-1.1.2-cp39-cp39-musllinux_1_2_x86_64.whl (886.1 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

stockwell-1.1.2-cp39-cp39-musllinux_1_2_i686.whl (702.8 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ i686

stockwell-1.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (706.4 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

stockwell-1.1.2-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (684.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

stockwell-1.1.2-cp39-cp39-macosx_11_0_arm64.whl (416.0 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

stockwell-1.1.2-cp39-cp39-macosx_10_9_x86_64.whl (464.8 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

stockwell-1.1.2-cp38-cp38-win_amd64.whl (626.1 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

stockwell-1.1.2-cp38-cp38-musllinux_1_2_x86_64.whl (886.1 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.2+ x86-64

stockwell-1.1.2-cp38-cp38-musllinux_1_2_i686.whl (702.8 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.2+ i686

stockwell-1.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (706.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

stockwell-1.1.2-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl (684.3 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686

stockwell-1.1.2-cp38-cp38-macosx_11_0_arm64.whl (416.0 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

stockwell-1.1.2-cp38-cp38-macosx_10_9_x86_64.whl (464.9 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

Supported by

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