DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
dspark::FIRDesign< T > Class Template Reference

Static methods for designing FIR filter coefficients. More...

#include <FIRFilter.h>

Static Public Member Functions

static std::vector< T > lowPass (double sampleRate, double cutoffHz, int numTaps, T beta=T(5)) noexcept
 Designs a low-pass FIR filter.
 
static std::vector< T > highPass (double sampleRate, double cutoffHz, int numTaps, T beta=T(5)) noexcept
 Designs a high-pass FIR filter.
 
static std::vector< T > bandPass (double sampleRate, double lowCutoffHz, double highCutoffHz, int numTaps, T beta=T(5)) noexcept
 Designs a band-pass FIR filter.
 
static std::vector< T > bandStop (double sampleRate, double lowCutoffHz, double highCutoffHz, int numTaps, T beta=T(5)) noexcept
 Designs a band-stop (notch) FIR filter.
 
static int estimateTaps (double sampleRate, double transitionHz, double attenuationDb) noexcept
 Estimates the required number of taps for a given specification.
 
static T estimateKaiserBeta (double attenuationDb) noexcept
 Estimates the Kaiser beta parameter for a desired attenuation.
 

Detailed Description

template<typename T>
class dspark::FIRDesign< T >

Static methods for designing FIR filter coefficients.

Uses the windowed-sinc method: an ideal (sinc) impulse response is multiplied by a window function to produce a realisable FIR filter.

All methods return a vector of filter coefficients (taps). The number of taps determines the filter's steepness and stopband attenuation. More taps = steeper transition but more latency and computation.

Rule of thumb for number of taps:

  • N ~ 4 / (transitionWidth / sampleRate) for a Kaiser window
  • For a 1 kHz transition band at 48 kHz: N ~ 4 / (1000/48000) ~ 192 taps
  • Always use an odd number for symmetric (Type I) FIR filters
Template Parameters
TCoefficient type (float or double).

Definition at line 74 of file FIRFilter.h.

Member Function Documentation

◆ bandPass()

template<typename T >
static std::vector< T > dspark::FIRDesign< T >::bandPass ( double  sampleRate,
double  lowCutoffHz,
double  highCutoffHz,
int  numTaps,
beta = T(5) 
)
inlinestaticnoexcept

Designs a band-pass FIR filter.

Created by subtracting a low-pass at lowCutoff from a low-pass at highCutoff.

Parameters
sampleRateSample rate in Hz.
lowCutoffHzLower cutoff frequency in Hz.
highCutoffHzUpper cutoff frequency in Hz.
numTapsNumber of filter taps (must be odd, >= 3).
betaKaiser window beta.
Returns
Vector of filter coefficients.

Definition at line 125 of file FIRFilter.h.

◆ bandStop()

template<typename T >
static std::vector< T > dspark::FIRDesign< T >::bandStop ( double  sampleRate,
double  lowCutoffHz,
double  highCutoffHz,
int  numTaps,
beta = T(5) 
)
inlinestaticnoexcept

Designs a band-stop (notch) FIR filter.

Parameters
sampleRateSample rate in Hz.
lowCutoffHzLower cutoff frequency in Hz.
highCutoffHzUpper cutoff frequency in Hz.
numTapsNumber of filter taps (must be odd, >= 3).
betaKaiser window beta.
Returns
Vector of filter coefficients.

Definition at line 152 of file FIRFilter.h.

◆ estimateKaiserBeta()

template<typename T >
static T dspark::FIRDesign< T >::estimateKaiserBeta ( double  attenuationDb)
inlinestaticnoexcept

Estimates the Kaiser beta parameter for a desired attenuation.

Parameters
attenuationDbDesired stopband attenuation in dB (positive).
Returns
Kaiser beta parameter.

Definition at line 204 of file FIRFilter.h.

◆ estimateTaps()

template<typename T >
static int dspark::FIRDesign< T >::estimateTaps ( double  sampleRate,
double  transitionHz,
double  attenuationDb 
)
inlinestaticnoexcept

Estimates the required number of taps for a given specification.

Uses the Kaiser formula to estimate the minimum number of odd taps needed to achieve the desired stopband attenuation with a given transition bandwidth.

Parameters
sampleRateSample rate in Hz.
transitionHzWidth of the transition band in Hz. Must be > 0.
attenuationDbDesired stopband attenuation in dB (positive value, e.g., 60).
Returns
Estimated number of taps (always odd).

Definition at line 185 of file FIRFilter.h.

◆ highPass()

template<typename T >
static std::vector< T > dspark::FIRDesign< T >::highPass ( double  sampleRate,
double  cutoffHz,
int  numTaps,
beta = T(5) 
)
inlinestaticnoexcept

Designs a high-pass FIR filter.

Created by spectrally inverting a low-pass filter.

Parameters
sampleRateSample rate in Hz.
cutoffHzCutoff frequency in Hz.
numTapsNumber of filter taps (must be odd, >= 3).
betaKaiser window beta.
Returns
Vector of filter coefficients.

Definition at line 105 of file FIRFilter.h.

◆ lowPass()

template<typename T >
static std::vector< T > dspark::FIRDesign< T >::lowPass ( double  sampleRate,
double  cutoffHz,
int  numTaps,
beta = T(5) 
)
inlinestaticnoexcept

Designs a low-pass FIR filter.

Parameters
sampleRateSample rate in Hz.
cutoffHzCutoff frequency in Hz (-6 dB point).
numTapsNumber of filter taps (must be odd, >= 3).
betaKaiser window beta (default: 5.0). Higher = more attenuation.
Returns
Vector of filter coefficients.

Definition at line 86 of file FIRFilter.h.


The documentation for this class was generated from the following file: