A Python implementation of a multitaper window method for estimating Wigner spectra for certain locally stationary processes
Project description
LSPOpt
This module is a Python implementation of the multitaper window method described in [1] for estimating Wigner spectra for certain locally stationary processes.
Abstract from [1]:
This paper investigates the time-discrete multitapers that give a mean square error optimal Wigner spectrum estimate for a class of locally stationary processes (LSPs). The accuracy in the estimation of the time-variable Wigner spectrum of the LSP is evaluated and compared with other frequently used methods. The optimal multitapers are also approximated by Hermite functions, which is computationally more efficient, and the errors introduced by this approximation are studied. Additionally, the number of windows included in a multitaper spectrum estimate is often crucial and an investigation of the error caused by limiting this number is made. Finally, the same optimal set of weights can be stored and utilized for different window lengths. As a result, the optimal multitapers are shown to be well approximated by Hermite functions, and a limited number of windows can be used for a mean square error optimal spectrogram estimate.
Installation
Install via pip:
pip install lspopt
If you prefer to use conda, see instructions in this repo.
Testing
Test with pytest:
pytest tests/
See test badge at the top of this README for link to test coverage and reports.
Usage
To generate the taper windows only, use the lspopt method:
from lspopt import lspopt
H, w = lspopt(n=256, c_parameter=20.0)
There is also a convenience method for using the SciPy spectrogram method
with the lspopt multitaper windows:
from lspopt import spectrogram_lspopt
f, t, Sxx = spectrogram_lspopt(x, fs, c_parameter=20.0)
This can then be plotted with e.g. matplotlib.
Example
One can generate a chirp process realisation and run spectrogram methods on this.
import numpy as np
from scipy.signal import chirp, spectrogram
import matplotlib.pyplot as plt
from lspopt.lsp import spectrogram_lspopt
fs = 10000
N = 100000
amp = 2 * np.sqrt(2)
noise_power = 0.001 * fs / 2
time = np.arange(N) / fs
freq = np.linspace(1000, 2000, N)
x = amp * chirp(time, 1000, 2.0, 6000, method='quadratic') + \
np.random.normal(scale=np.sqrt(noise_power), size=time.shape)
f, t, Sxx = spectrogram(x, fs)
ax = plt.subplot(211)
ax.pcolormesh(t, f, Sxx)
ax.set_ylabel('Frequency [Hz]')
ax.set_xlabel('Time [sec]')
f, t, Sxx = spectrogram_lspopt(x, fs, c_parameter=20.0)
ax = plt.subplot(212)
ax.pcolormesh(t, f, Sxx)
ax.set_ylabel('Frequency [Hz]')
ax.set_xlabel('Time [sec]')
plt.tight_layout()
plt.show()
Top: Using SciPy's spectrogram method. Bottom: Using LSPOpt's spectrogram solution.
References
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
[1.4.0] - 2025-01-07
Added
- Support for Python 3.12
- Support for
pip>=25 - Support for
numpy>=2 - Support for Windows and macOS
- Converted
setup.pytosetup.cfg
Removed
- Support for Python 3.7 and 3.8
- Unused imports
1.3.0 - 2023-01-24
Changed
- Modified test matrix in CI
Removed
- Support for Python 2.7 and 3.6.
- Dependency on
six.
1.2.0 - 2022-06-08
Added
- New plot file
Fixed
- Source distribution was broken on PyPI. Modified
MANIFEST.into correct that (#5 and #6) - Url to missing plot file
- Fixed some incorrect int declarations using
1e3notation
Removed
- Removed Pipfile
1.1.1 - 2020-09-28
Added
- Added
CHANGELOG.md
Changed
- Change CI from Azure Devops to Github Actions
1.1.0 - 2019-06-19
Added
- First PyPI-released version
[1.0.0] - 2016-08-22
Added
- Regarded as a feature-complete, stable library.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lspopt-1.4.0.tar.gz.
File metadata
- Download URL: lspopt-1.4.0.tar.gz
- Upload date:
- Size: 39.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ea32d90cc2e6536e7c6ea559889e529bdae6d0d3795956432c9ad7d0844131e
|
|
| MD5 |
b6d1428aba7ca8ac5b58316321d76820
|
|
| BLAKE2b-256 |
870a3de9f71251d6d62ab29265fb68b270bfdfe629584fbb8db7d025c429a532
|
Provenance
The following attestation bundles were made for lspopt-1.4.0.tar.gz:
Publisher:
python-publish.yml on hbldh/lspopt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lspopt-1.4.0.tar.gz -
Subject digest:
6ea32d90cc2e6536e7c6ea559889e529bdae6d0d3795956432c9ad7d0844131e - Sigstore transparency entry: 160375126
- Sigstore integration time:
-
Permalink:
hbldh/lspopt@413245e4558cdee3cfbadfbc0f3f6cc22bfe66dd -
Branch / Tag:
refs/tags/v1.4.0 - Owner: https://github.com/hbldh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@413245e4558cdee3cfbadfbc0f3f6cc22bfe66dd -
Trigger Event:
release
-
Statement type:
File details
Details for the file lspopt-1.4.0-py3-none-any.whl.
File metadata
- Download URL: lspopt-1.4.0-py3-none-any.whl
- Upload date:
- Size: 35.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c1bc134126a5168248e444760468fa75df70e59d8de98184571ea150f4b494d
|
|
| MD5 |
95b2e36f37c6e7491dc16596a5bff329
|
|
| BLAKE2b-256 |
39913a1959aa91eb7d50f2aaf4d8a1a49cd4a3db7315be7bdec742d16eba2810
|
Provenance
The following attestation bundles were made for lspopt-1.4.0-py3-none-any.whl:
Publisher:
python-publish.yml on hbldh/lspopt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lspopt-1.4.0-py3-none-any.whl -
Subject digest:
2c1bc134126a5168248e444760468fa75df70e59d8de98184571ea150f4b494d - Sigstore transparency entry: 160375128
- Sigstore integration time:
-
Permalink:
hbldh/lspopt@413245e4558cdee3cfbadfbc0f3f6cc22bfe66dd -
Branch / Tag:
refs/tags/v1.4.0 - Owner: https://github.com/hbldh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@413245e4558cdee3cfbadfbc0f3f6cc22bfe66dd -
Trigger Event:
release
-
Statement type: