miniDSP
A small C library for audio DSP
Loading...
Searching...
No Matches
minidsp_fir.c File Reference

FIR filtering and convolution: direct time-domain methods and FFT overlap-add fast convolution. More...

#include "minidsp.h"
Include dependency graph for minidsp_fir.c:

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_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).
 

Detailed Description

FIR filtering and convolution: direct time-domain methods and FFT overlap-add fast convolution.

Definition in file minidsp_fir.c.

Function Documentation

◆ MD_convolution_fft_ola()

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.

Parameters
signalInput signal of length signal_len.
signal_lenNumber of input samples (must be > 0).
kernelFIR kernel of length kernel_len.
kernel_lenNumber of FIR taps (must be > 0).
outOutput buffer of length signal_len + kernel_len - 1.

Definition at line 87 of file minidsp_fir.c.

◆ MD_convolution_num_samples()

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 17 of file minidsp_fir.c.

◆ MD_convolution_time()

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.

Parameters
signalInput signal of length signal_len.
signal_lenNumber of input samples (must be > 0).
kernelFIR kernel of length kernel_len.
kernel_lenNumber of FIR taps (must be > 0).
outOutput buffer of length signal_len + kernel_len - 1.

Definition at line 24 of file minidsp_fir.c.

◆ MD_fir_filter()

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.

Parameters
signalInput signal of length signal_len.
signal_lenNumber of input samples (must be > 0).
coeffsFIR coefficients of length num_taps.
num_tapsNumber of FIR taps (must be > 0).
outOutput buffer of length signal_len.

Definition at line 67 of file minidsp_fir.c.

◆ MD_moving_average()

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.

Parameters
signalInput signal of length signal_len.
signal_lenNumber of input samples (must be > 0).
window_lenMoving-average window length (must be > 0).
outOutput buffer of length signal_len.

Definition at line 47 of file minidsp_fir.c.

◆ next_pow2()

static unsigned next_pow2 ( unsigned  n)
static

Return the next power-of-two >= n (n must be > 0).

Definition at line 10 of file minidsp_fir.c.