Spectrum Analysis Tools - contains tools to estimate Power Spectral Densities using methods based on Fourier transform, Parametric methods or eigenvalues analysis
npx @tessl/cli install tessl/pypi-spectrum@0.9.00
# Spectrum
1
2
A comprehensive Python library for spectral analysis providing various methods for power spectral density (PSD) estimation, parametric spectral analysis, and signal processing utilities. The package includes 174+ functions and 35+ classes across 24+ modules, covering parametric methods, eigenvalue-based methods, non-parametric methods, and extensive signal processing tools.
3
4
## Package Information
5
6
- **Package Name**: spectrum
7
- **Package Type**: pypi
8
- **Language**: Python
9
- **Installation**: `pip install spectrum`
10
11
## Core Imports
12
13
```python
14
import spectrum
15
```
16
17
Common patterns for specific functionality:
18
19
```python
20
from spectrum import *
21
# or
22
from spectrum import pburg, pyule, pmusic, speriodogram
23
```
24
25
## Basic Usage
26
27
```python
28
import spectrum
29
import numpy as np
30
31
# Generate test signal
32
N = 1024
33
noise = np.random.randn(N)
34
signal = np.sin(2 * np.pi * 0.1 * np.arange(N)) + 0.1 * noise
35
36
# Parametric PSD estimation using Burg method
37
p = spectrum.pburg(signal, order=15)
38
p.plot()
39
40
# Non-parametric PSD estimation using periodogram
41
psd = spectrum.speriodogram(signal, NFFT=512)
42
43
# Eigenvalue-based method (MUSIC)
44
music = spectrum.pmusic(signal, IP=15, NSIG=2)
45
music.plot()
46
47
# Auto-regressive parameter estimation
48
ar_params, noise_var, _ = spectrum.aryule(signal, order=10)
49
50
# Window function generation
51
window = spectrum.create_window(64, 'hamming')
52
```
53
54
## Architecture
55
56
The spectrum package follows a modular design with several key architectural patterns:
57
58
- **Parametric Spectrum Classes**: Inherit from `ParametricSpectrum` for AR, ARMA, and eigenvalue methods
59
- **Fourier Spectrum Classes**: Inherit from `FourierSpectrum` for periodogram and correlogram methods
60
- **Base Spectrum Class**: Common functionality including plotting, scaling, and frequency range handling
61
- **Estimation Functions**: Standalone functions for parameter estimation (AR coefficients, reflection coefficients)
62
- **Utility Modules**: Signal processing tools, window functions, linear algebra utilities
63
64
This design provides consistent interfaces across different estimation methods while maintaining flexibility for specialized applications in spectral analysis, system identification, and digital signal processing.
65
66
## Capabilities
67
68
### Parametric AR Methods
69
70
Auto-regressive parameter estimation and PSD computation using various algorithms including Yule-Walker, Burg, covariance, and modified covariance methods.
71
72
```python { .api }
73
def aryule(X, order, norm='biased', allow_singularity=True): ...
74
def arburg(X, order, criteria=None): ...
75
def arcovar(x, order): ...
76
def modcovar(x, order): ...
77
78
class pyule(data, order, NFFT=None, sampling=1., scale_by_freq=False): ...
79
class pburg(data, order, criteria=None, NFFT=None, sampling=1., scale_by_freq=False): ...
80
class pcovar(data, order, NFFT=None, sampling=1., scale_by_freq=False): ...
81
class pmodcovar(data, order, NFFT=None, sampling=1., scale_by_freq=False): ...
82
```
83
84
[Parametric AR Methods](./parametric-ar.md)
85
86
### ARMA Methods
87
88
Auto-regressive moving average parameter estimation and PSD computation for combined AR-MA models and pure MA models.
89
90
```python { .api }
91
def arma_estimate(X, P, Q, lag): ...
92
def ma(X, Q, M): ...
93
def arma2psd(A=None, B=None, rho=1., T=1., NFFT=4096, sides='default', norm=False): ...
94
95
class parma(data, P, Q, lag, NFFT=None, sampling=1., scale_by_freq=False): ...
96
class pma(data, Q, M, NFFT=None, sampling=1., scale_by_freq=False): ...
97
```
98
99
[ARMA Methods](./arma-methods.md)
100
101
### Eigenvalue Methods
102
103
High-resolution spectral estimation using eigenvalue decomposition including MUSIC, eigenvector, and minimum variance methods.
104
105
```python { .api }
106
def music(X, IP, NSIG=None, NFFT=4096, threshold=None, criteria='aic', verbose=False): ...
107
def ev(X, IP, NSIG=None, NFFT=4096, threshold=None, criteria='aic', verbose=False): ...
108
def minvar(X, order, sampling=1., NFFT=4096): ...
109
110
class pmusic(data, IP, NSIG=None, NFFT=None, sampling=1., scale_by_freq=False): ...
111
class pev(data, IP, NSIG=None, NFFT=None, sampling=1., scale_by_freq=False): ...
112
class pminvar(data, order, NFFT=None, sampling=1., scale_by_freq=False): ...
113
```
114
115
[Eigenvalue Methods](./eigenvalue-methods.md)
116
117
### Non-parametric Methods
118
119
Classical spectral estimation techniques including periodogram, Welch's method, correlogram, and multi-taper methods.
120
121
```python { .api }
122
def speriodogram(x, NFFT=None, detrend=True, sampling=1., scale_by_freq=True, window='hamming', axis=0): ...
123
def WelchPeriodogram(data, NFFT=None, sampling=1., **kargs): ...
124
def pmtm(x, NW=None, k=None, NFFT=None, e=None, v=None, method="adapt", show=False): ...
125
126
class Periodogram(data, sampling=1., NFFT=None, window='hamming', detrend='mean', scale_by_freq=True): ...
127
class pcorrelogram(data, sampling=1., lag=-1, window='hamming', NFFT=None, scale_by_freq=True, detrend=None): ...
128
class MultiTapering(Spectrum): ...
129
```
130
131
[Non-parametric Methods](./nonparametric-methods.md)
132
133
### Linear Prediction and Conversion
134
135
Linear prediction analysis and conversion between different parameter representations (AR coefficients, reflection coefficients, line spectral frequencies).
136
137
```python { .api }
138
def LEVINSON(r, order=None, allow_singularity=False): ...
139
def lpc(x, N=None): ...
140
def ac2poly(data): ...
141
def poly2ac(poly, efinal): ...
142
def rc2poly(kr, r0=None): ...
143
```
144
145
[Linear Prediction](./linear-prediction.md)
146
147
### Window Functions
148
149
Comprehensive collection of window functions for signal processing applications with visualization and analysis tools.
150
151
```python { .api }
152
def create_window(N, name=None, **kargs): ...
153
def enbw(data): ...
154
155
class Window(N, name=None, **kargs): ...
156
157
def window_hamming(N): ...
158
def window_hanning(N): ...
159
def window_kaiser(N, beta=8.6): ...
160
def window_blackman(N, alpha=0.16): ...
161
def window_gaussian(N, alpha=2.5): ...
162
```
163
164
[Window Functions](./window-functions.md)
165
166
### Correlation and Signal Processing
167
168
Correlation analysis, signal generation, and essential signal processing utilities for spectral analysis applications.
169
170
```python { .api }
171
def CORRELATION(x, y=None, maxlags=None, norm='unbiased'): ...
172
def xcorr(x, y=None, maxlags=None, norm='biased'): ...
173
def chirp(t, f0=0., t1=1., f1=100., form='linear', phase=0): ...
174
def morlet(lb, ub, n): ...
175
176
def pow2db(x): ...
177
def db2pow(xdb): ...
178
def nextpow2(x): ...
179
```
180
181
[Correlation and Signal Processing](./correlation-signal.md)
182
183
### Mathematical Tools and Utilities
184
185
Linear algebra utilities, model selection criteria, transfer function analysis, and mathematical tools supporting spectral analysis.
186
187
```python { .api }
188
def CHOLESKY(A, B, method='scipy'): ...
189
def pascal(n): ...
190
def corrmtx(x_input, m, method='autocorrelation'): ...
191
192
def AIC(N, rho, k): ...
193
def MDL(N, rho, k): ...
194
def FPE(N, rho, k=None): ...
195
196
class Criteria(name, N): ...
197
198
def tf2zp(b, a): ...
199
def zp2tf(z, p, k): ...
200
```
201
202
[Mathematical Tools](./math-tools.md)