FIR Filters & Convolution¶
Time-domain and FFT-based convolution, moving-average filters, and general FIR filtering.
- pyminidsp.convolution_num_samples(signal_len, kernel_len)[source]¶
Compute the output length of a full linear convolution.
Compute the output length of a full linear convolution. For input length N and kernel length M, the result is
N + M - 1.
- pyminidsp.convolution_time(signal, kernel)[source]¶
Time-domain full linear convolution.
- Returns:
numpy array of length signal_len + kernel_len - 1.
Time-domain full linear convolution (direct sum-of-products).
\[\text{out}[n] = \sum_{k=0}^{M-1} \text{signal}[n-k] \cdot \text{kernel}[k]\]with out-of-range signal samples treated as zero.
- Parameters:
signal – Input signal.
kernel – FIR kernel.
- Returns:
Array of length
len(signal) + len(kernel) - 1.
- pyminidsp.moving_average(signal, window_len)[source]¶
Causal moving-average FIR filter.
- Returns:
numpy array of the same length as the input.
Causal moving-average FIR filter with zero-padded startup.
\[\text{out}[n] = \frac{1}{W} \sum_{k=0}^{W-1} \text{signal}[n-k]\]where out-of-range samples (
n - k < 0) are treated as zero.- Parameters:
signal – Input signal.
window_len – Moving-average window length (must be > 0).
- Returns:
Array of the same length as the input.
- pyminidsp.fir_filter(signal, coeffs)[source]¶
Apply a causal FIR filter with arbitrary coefficients.
- Returns:
numpy array of the same length as the input.
Apply a causal FIR filter with arbitrary coefficients.
\[\text{out}[n] = \sum_{k=0}^{T-1} \text{coeffs}[k] \cdot \text{signal}[n-k]\]with out-of-range signal samples treated as zero.
- Parameters:
signal – Input signal.
coeffs – FIR coefficients.
- Returns:
Array of the same length as the input.
- pyminidsp.convolution_fft_ola(signal, kernel)[source]¶
Full linear convolution using FFT overlap-add.
- Returns:
numpy array of length signal_len + kernel_len - 1.
Full linear convolution using FFT overlap-add. Produces the same output as
convolution_time()but is faster for longer kernels by processing blocks in the frequency domain.- Parameters:
signal – Input signal.
kernel – FIR kernel.
- Returns:
Array of length
len(signal) + len(kernel) - 1.