Package: lspopt
LSPOptThis 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.InstallationInstall via pip:pip install lspoptIf you prefer to useconda, seeinstructions in this repo.TestingTest withpytest:pytest tests/See test badge at the top of this README for link to test coverage and reports.UsageTo generate the taper windows only, use thelspoptmethod:fromlspoptimportlspoptH,w=lspopt(N=256,c_parameter=20.0)There is also a convenience method for using theSciPy spectrogram methodwith thelspoptmultitaper windows:fromlspoptimportspectrogram_lspoptf,t,Sxx=spectrogram_lspopt(x,fs,c_parameter=20.0)This can then be plotted with e.g.matplotlib.ExampleOne can generate achirpprocess realisation and run spectrogram methods on this.importnumpyasnpfromscipy.signalimportchirp,spectrogramimportmatplotlib.pyplotaspltfromlspopt.lspimportspectrogram_lspoptfs=10000N=100000amp=2*np.sqrt(2)noise_power=0.001*fs/2time=np.arange(N)/fsfreq=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[1]Hansson-Sandsten, M. (2011). Optimal multitaper Wigner spectrum
estimation of a class of locally stationary processes using Hermite functions.
EURASIP Journal on Advances in Signal Processing, 2011, 10.ChangelogAll notable changes to this project will be documented in this file.The format is based onKeep a Changelog,
and this project adheres toSemantic Versioning.[1.3.0] - 2023-01-24ChangedModified test matrix in CIRemovedSupport for Python 2.7 and 3.6.Dependency onsix.1.2.0- 2022-06-08AddedNew plot fileFixedSource distribution was broken on PyPI. ModifiedMANIFEST.into correct that (#5 and #6)Url to missing plot fileFixed some incorrect int declarations using1e3notationRemovedRemoved Pipfile1.1.1- 2020-09-28AddedAddedCHANGELOG.mdChangedChange CI from Azure Devops to Github Actions1.1.0- 2019-06-19AddedFirst PyPI-released version[1.0.0] - 2016-08-22AddedRegarded as a feature-complete, stable library.