|
miniDSP
A small C library for audio DSP
|
FIR filtering and convolution: direct time-domain methods and FFT overlap-add fast convolution. More...
Go to the source code of this file.
Functions | |
| static unsigned | next_pow2 (unsigned n) |
| Return the next power-of-two >= n (n must be > 0). | |
| unsigned | MD_convolution_num_samples (unsigned signal_len, unsigned kernel_len) |
| Compute the output length of a full linear convolution. | |
| void | MD_convolution_time (const double *signal, unsigned signal_len, const double *kernel, unsigned kernel_len, double *out) |
| Time-domain full linear convolution (direct sum-of-products). | |
| void | MD_moving_average (const double *signal, unsigned signal_len, unsigned window_len, double *out) |
| Causal moving-average FIR filter with zero-padded startup. | |
| void | MD_fir_filter (const double *signal, unsigned signal_len, const double *coeffs, unsigned num_taps, double *out) |
| Apply a causal FIR filter with arbitrary coefficients. | |
| void | MD_design_lowpass_fir (double *coeffs, unsigned num_taps, double cutoff_freq, double sample_rate, double kaiser_beta) |
| Design a Kaiser-windowed sinc lowpass FIR filter. | |
| void | MD_convolution_fft_ola (const double *signal, unsigned signal_len, const double *kernel, unsigned kernel_len, double *out) |
| Full linear convolution using FFT overlap-add (offline). | |
FIR filtering and convolution: direct time-domain methods and FFT overlap-add fast convolution.
Definition in file minidsp_fir.c.
| void MD_convolution_fft_ola | ( | const double * | signal, |
| unsigned | signal_len, | ||
| const double * | kernel, | ||
| unsigned | kernel_len, | ||
| double * | out ) |
Full linear convolution using FFT overlap-add (offline).
Produces the same output as MD_convolution_time() but is faster for longer kernels by processing blocks in the frequency domain.
| signal | Input signal of length signal_len. |
| signal_len | Number of input samples (must be > 0). |
| kernel | FIR kernel of length kernel_len. |
| kernel_len | Number of FIR taps (must be > 0). |
| out | Output buffer of length signal_len + kernel_len - 1. |
Definition at line 124 of file minidsp_fir.c.
| unsigned MD_convolution_num_samples | ( | unsigned | signal_len, |
| unsigned | kernel_len ) |
Compute the output length of a full linear convolution.
For input length N and kernel length M, full convolution length is N+M-1.
Definition at line 18 of file minidsp_fir.c.
| void MD_convolution_time | ( | const double * | signal, |
| unsigned | signal_len, | ||
| const double * | kernel, | ||
| unsigned | kernel_len, | ||
| double * | out ) |
Time-domain full linear convolution (direct sum-of-products).
Computes: out[n] = sum_{k=0}^{kernel_len-1} signal[n-k] * kernel[k] with out-of-range signal samples treated as zero.
| signal | Input signal of length signal_len. |
| signal_len | Number of input samples (must be > 0). |
| kernel | FIR kernel of length kernel_len. |
| kernel_len | Number of FIR taps (must be > 0). |
| out | Output buffer of length signal_len + kernel_len - 1. |
Definition at line 25 of file minidsp_fir.c.
| void MD_design_lowpass_fir | ( | double * | coeffs, |
| unsigned | num_taps, | ||
| double | cutoff_freq, | ||
| double | sample_rate, | ||
| double | kaiser_beta ) |
Design a Kaiser-windowed sinc lowpass FIR filter.
Generates a linear-phase lowpass filter with the specified cutoff frequency and Kaiser window shape. The coefficients are normalized to unity DC gain (they sum to 1.0).
\[ h[i] = 2\,f_c\;\mathrm{sinc}\!\bigl(2\,f_c\,(i - (N-1)/2)\bigr) \;\cdot\; w_{\mathrm{Kaiser}}[i] \]
where \(f_c = \mathrm{cutoff\_freq} / \mathrm{sample\_rate}\).
| coeffs | Output buffer of length num_taps (caller-allocated). |
| num_taps | Filter length (must be > 0). |
| cutoff_freq | -6 dB cutoff frequency in Hz (must be > 0 and < sample_rate / 2). |
| sample_rate | Sampling rate in Hz (must be > 0). |
| kaiser_beta | Kaiser window \(\beta\) parameter (e.g. 10.0). |
Definition at line 88 of file minidsp_fir.c.
| void MD_fir_filter | ( | const double * | signal, |
| unsigned | signal_len, | ||
| const double * | coeffs, | ||
| unsigned | num_taps, | ||
| double * | out ) |
Apply a causal FIR filter with arbitrary coefficients.
Computes: out[n] = sum_{k=0}^{num_taps-1} coeffs[k] * signal[n-k] with out-of-range signal samples treated as zero.
| signal | Input signal of length signal_len. |
| signal_len | Number of input samples (must be > 0). |
| coeffs | FIR coefficients of length num_taps. |
| num_taps | Number of FIR taps (must be > 0). |
| out | Output buffer of length signal_len. |
Definition at line 68 of file minidsp_fir.c.
| void MD_moving_average | ( | const double * | signal, |
| unsigned | signal_len, | ||
| unsigned | window_len, | ||
| double * | out ) |
Causal moving-average FIR filter with zero-padded startup.
Computes: out[n] = (1/window_len) * sum_{k=0}^{window_len-1} signal[n-k] where out-of-range samples (n-k < 0) are treated as zero.
| signal | Input signal of length signal_len. |
| signal_len | Number of input samples (must be > 0). |
| window_len | Moving-average window length (must be > 0). |
| out | Output buffer of length signal_len. |
Definition at line 48 of file minidsp_fir.c.
|
static |
Return the next power-of-two >= n (n must be > 0).
Definition at line 11 of file minidsp_fir.c.