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.
- Parameters:
signal (ArrayLike)
kernel (ArrayLike)
- Return type:
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.
- pyminidsp.moving_average(signal, window_len)[source]¶
Causal moving-average FIR filter.
- Returns:
numpy array of the same length as the input.
- Parameters:
signal (ArrayLike)
window_len (int)
- Return type:
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.
- pyminidsp.fir_filter(signal, coeffs)[source]¶
Apply a causal FIR filter with arbitrary coefficients.
- Returns:
numpy array of the same length as the input.
- Parameters:
signal (ArrayLike)
coeffs (ArrayLike)
- Return type:
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.
- pyminidsp.design_lowpass_fir(num_taps, cutoff_freq, sample_rate, kaiser_beta=5.0)[source]¶
Design a Kaiser-windowed sinc lowpass FIR filter.
- Parameters:
- Returns:
numpy array of length num_taps containing the filter coefficients.
- Return type:
Design a Kaiser-windowed sinc lowpass FIR filter.
Returns a set of FIR filter coefficients that can be passed directly to
fir_filter(). The Kaiser window’s beta parameter controls the trade-off between stopband attenuation and transition width.- Parameters:
- Returns:
Array of length num_taps.
- Return type:
coeffs = md.design_lowpass_fir(65, cutoff_freq=4000.0, sample_rate=44100.0, kaiser_beta=8.0) filtered = md.fir_filter(signal, coeffs)
- pyminidsp.convolution_fft_ola(signal, kernel)[source]¶
Full linear convolution using FFT overlap-add.
- Returns:
numpy array of length signal_len + kernel_len - 1.
- Parameters:
signal (ArrayLike)
kernel (ArrayLike)
- Return type:
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.