Filter sampled signals
Apply a finite impulse response or infinite impulse response operation to sampled data.
SciPy · Module
scipy.signal is SciPy’s signal-processing module. It provides convolution, correlation, filtering, spectral-analysis, waveform-generation, and related signal-processing functions.
The module groups algorithms for filtering, convolution, spectral analysis, waveform generation, and continuous- and discrete-time signal processing. Its functions operate mainly on NumPy arrays and include direct, FFT-based, and overlap-add convolution options.
import scipy.signal| Name | Type | Description |
|---|---|---|
in1 | array_like | First input array for convolution, correlation, or another selected signal-processing operation. |
in2 | array_like | Second input array for convolution, correlation, or another selected signal-processing operation. |
mode | str, optional | Controls the requested convolution output region. |
method | str, optional | Selects the convolution algorithm when supported. |
The module's functions return results specific to the selected operation; convolution functions return an array containing the computed convolution.
import numpy as np
from scipy import signal
x = np.array([1.0, 2.0, 3.0])
h = np.array([1.0, 1.0])
y = signal.convolve(x, h, mode="full")
print(y)Convolves two one-dimensional NumPy arrays and prints every output sample.
Apply a finite impulse response or infinite impulse response operation to sampled data.
Combine a signal with an impulse response or detect similarity between arrays.
Estimate frequency content or generate frequency-swept test signals.
Model or analyze continuous- and discrete-time systems.
scipy.signal is SciPy's signal-processing module. It exposes tools for convolution, correlation, filtering, spectral analysis, waveform generation, and system analysis.
Follow-up: How would you choose a convolution strategy? Compare direct convolution with FFT-based and overlap-add implementations, considering input sizes and performance.
signal.convolve computes the convolution of two N-dimensional arrays. Its documented interface accepts the input arrays plus optional mode and method arguments.
Follow-up: What does the mode argument control? Explain how full, same, and valid output regions differ.
The module provides several convolution implementations, including convolve, fftconvolve, and oaconvolve. It also provides choose_conv_method to find a fast convolution or correlation method.
Follow-up: When might overlap-add be useful? It is suited to efficiently processing long signals, especially when one input can be treated as a filter.
convolvecorrelatefftconvolveoaconvolveconvolve2dcorrelate2dsepfir2dchoose_conv_method