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 timediscrete 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 timevariable 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
Testing
Test with pytest
:
pytest tests/
Tests are run at every commit to GitHub and the results of this, as well as test coverage, can be studied at Azure Pipelines.
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 = 10e3 N = 1e5 amp = 2 * np.sqrt(2) noise_power = 0.001 * fs / 2 time = np.arange(N) / fs freq = np.linspace(1e3, 2e3, N) x = amp * chirp(time, 1e3, 2.0, 6e3, 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.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.1.1  20200928
Added
 Added
CHANGELOG.md
Changed
 Change CI from Azure Devops to Github Actions
1.1.0  20190619
Added
 First PyPIreleased version
[1.0.0]  20160822
Added
 Regarded as a featurecomplete, stable library.
Project details
Release history Release notifications  RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size  File type  Python version  Upload date  Hashes 

Filename, size lspopt1.1.1.tar.gz (9.9 kB)  File type Source  Python version None  Upload date  Hashes View 
Filename, size lspopt1.1.1py2.py3noneany.whl (35.2 kB)  File type Wheel  Python version py2.py3  Upload date  Hashes View 
Hashes for lspopt1.1.1py2.py3noneany.whl
Algorithm  Hash digest  

SHA256  8a3895ea800b63a550afe63d04ad38a6966e468ae027d797c107a4d244083e9e 

MD5  d8d23837dda4db3fa1dd37422a2426a9 

BLAKE2256  29add7eabe3acb6b31930263c0c9622f0f499868196c71c00ee024952027e799 