Skip to main content

Module signal_tools

Module signal_tools 

Source
Expand description

Signal-processing utilities following scipy.signal: filter analysis (group_delay, minimum_phase), least-squares FIR design (firls), rate changes (decimate and the FFT resample), medfilt, the amplitude envelope, and cross-spectral analysis (csd, coherence).

See the book entry Signal-processing utilities.

Structs§

CrossSpectrum
A one-sided cross spectral density estimate.

Functions§

coherence
The magnitude-squared coherence |P_xy|² / (P_xx P_yy) (SciPy’s coherence): 1 where y is a noise-free linear filtering of x, near 0 where they are unrelated.
csd
The cross spectral density P_xy(f) by Welch’s method (SciPy’s csd): segments of window.len() samples overlapping by overlap, detrended and windowed; the average of conj(X) Y, scaled as welch and doubled except at DC and an even-length Nyquist bin.
decimate
Downsampling by an integer factor q after anti-alias filtering (SciPy’s decimate with ftype='iir'): an order-8 Chebyshev type I lowpass with 0.05 dB ripple and cutoff 0.8/q of Nyquist, applied forwards and backwards (zero_phase) or forwards only, then every q-th sample.
envelope
The amplitude envelope |x + i H{x}|, the magnitude of the analytic signal (equal to SciPy’s abs(hilbert(x))).
firls
A linear-phase FIR filter of odd length numtaps minimising the weighted integrated squared error to a piecewise-linear desired response (SciPy’s firls). bands holds band edges in pairs and desired the gains at those edges, as fractions of the Nyquist frequency when fs is None.
group_delay
The group delay −dφ/dω of the filter b(z)/a(z) in samples at the normalised angular frequencies w (radians per sample) (SciPy’s group_delay). With c = b ∗ reverse(conj(a)), τ(ω) = Re(Σ k cₖ e^{−iωk} / Σ cₖ e^{−iωk}) − (len(a) − 1); at frequencies where the denominator vanishes the delay is set to 0, as in SciPy.
medfilt
A median filter with an odd kernel_size, the signal extended by zeros (SciPy’s medfilt).
minimum_phase
A minimum-phase FIR filter from a linear-phase one by the homomorphic method (SciPy’s minimum_phase(h, 'homomorphic')): the real cepstrum of |H| (or of |H|^{1/2} with half, which preserves the magnitude of a filter that is the square of a minimum-phase one), folded onto positive quefrencies and exponentiated back. Returns len(h)/2 + len(h) mod 2 coefficients with half, otherwise len(h).
resample
Resamples the real signal x to num samples by the FFT (SciPy’s resample): the spectrum is truncated or zero-padded, with the unpaired Nyquist bin of an even length united when downsampling and split when upsampling. Exact for band-limited periodic signals.
zoom_fft
The DFT of x at m equally spaced frequencies from f1 towards f2 (SciPy’s zoom_fft, with the sample rate fs): the chirp z-transform on an arc of the unit circle starting at a = e^{2πi f1/fs} with ratio w = e^{−2πi (f2 − f1)/(fs m)} ((m − 1) in place of m with endpoint), computed by Bluestein’s algorithm in O((n + m) log(n + m)).