Overview
SciPy 1.7, released on June 21, 2021, adds new window functions and improves the signal processing module.
Main Features
Window functions
The scipy.signal.windows module gains new window functions such as Kaiser-Bessel and Taylor, useful for spectral analysis and digital filtering.
python
from scipy.signal import windows
import numpy as np
# Kaiser-Bessel window
n = 256
kb_window = windows.kaiser(n, beta=14)
# Taylor window for reduced sidelobes
taylor_window = windows.taylor(n, nbar=5, sll=30)
# Apply to a signal
sig = np.sin(2 * np.pi * 10 * np.linspace(0, 1, n))
windowed = sig * kb_window
print(f'Original energy: {np.sum(sig**2):.1f}')
print(f'Windowed energy: {np.sum(windowed**2):.1f}')
Signal improvements
The scipy.signal module improves filtering functions with new filter design algorithms and better IIR filter handling.
python
from scipy import signal
import numpy as np
# Design a Butterworth low-pass filter
fs = 1000 # sampling frequency
fc = 50 # cutoff frequency
b, a = signal.butter(N=4, Wn=fc, fs=fs, btype='low')
# Apply to noisy signal
t = np.linspace(0, 1, fs)
x = np.sin(2 * np.pi * 10 * t) + 0.5 * np.random.randn(fs)
y = signal.filtfilt(b, a, x)
print(f'Noise before: {np.std(x - np.sin(2*np.pi*10*t)):.3f}')
print(f'Noise after: {np.std(y - np.sin(2*np.pi*10*t)):.3f}')
