The Open Master Hearing Aid (openMHA)  openMHA
Open community platform for hearing aid algorithm research
MHAFilter Namespace Reference

Namespace for IIR and FIR filter classes. More...

Classes

class  complex_bandpass_t
 Complex bandpass filter. More...
 
class  gamma_flt_t
 Class for gammatone filter. More...
 
class  thirdoctave_analyzer_t
 
class  filter_t
 Generic IIR filter class. More...
 
class  diff_t
 Differentiator class (non-normalized) More...
 
class  o1_ar_filter_t
 First order attack-release lowpass filter. More...
 
class  o1flt_lowpass_t
 First order low pass filter. More...
 
class  o1flt_maxtrack_t
 First order maximum tracker. More...
 
class  o1flt_mintrack_t
 First order minimum tracker. More...
 
class  iir_filter_state_t
 
class  iir_filter_t
 IIR filter class wrapper for integration into parser structure. More...
 
class  adapt_filter_state_t
 
class  adapt_filter_param_t
 
class  adapt_filter_t
 Adaptive filter. More...
 
class  fftfilter_t
 FFT based FIR filter implementation. More...
 
class  fftfilterbank_t
 FFT based FIR filterbank implementation. More...
 
struct  transfer_function_t
 a structure containing a source channel number, a target channel number, and an impulse response. More...
 
struct  transfer_matrix_t
 A sparse matrix of transfer function partitionss. More...
 
class  partitioned_convolution_t
 A filter class for partitioned convolution. More...
 
class  smoothspec_t
 Smooth spectral gains, create a windowed impulse response. More...
 
class  resampling_filter_t
 Hann shaped low pass filter for resampling. More...
 
class  polyphase_resampling_t
 A class that performs polyphase resampling. More...
 
class  blockprocessing_polyphase_resampling_t
 A class that does polyphase resampling and takes into account block processing. More...
 
class  iir_ord1_real_t
 First order recursive filter. More...
 

Functions

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, T >::type * = nullptr>
void make_friendly_number (T &x)
 
void o1_lp_coeffs (const mha_real_t tau, const mha_real_t fs, mha_real_t &c1, mha_real_t &c2)
 Set first order filter coefficients from time constant and sampling rate. More...
 
void butter_stop_ord1 (double *A, double *B, double f1, double f2, double fs)
 Setup a first order butterworth band stop filter. More...
 
std::vector< float > fir_lp (float f_pass_, float f_stop_, float fs_, unsigned order_)
 Setup a nth order fir low pass filter. More...
 
MHASignal::waveform_tspec2fir (const mha_spec_t *spec, const unsigned int fftlen, const MHAWindow::base_t &window, const bool minphase)
 Create a windowed impulse response/FIR filter coefficients from a spectrum. More...
 
unsigned gcd (unsigned a, unsigned b)
 greatest common divisor More...
 
double sinc (double x)
 sin(x)/x function, coping with x=0. More...
 
std::pair< unsigned, unsigned > resampling_factors (float source_sampling_rate, float target_sampling_rate, float factor=1.0f)
 Computes rational resampling factor from two sampling rates. More...
 

Detailed Description

Namespace for IIR and FIR filter classes.

Function Documentation

◆ make_friendly_number()

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, T >::type * = nullptr>
void MHAFilter::make_friendly_number ( T &  x)
inline

◆ o1_lp_coeffs()

void MHAFilter::o1_lp_coeffs ( const mha_real_t  tau,
const mha_real_t  fs,
mha_real_t c1,
mha_real_t c2 
)

Set first order filter coefficients from time constant and sampling rate.

Parameters
tauTime constant
fsSampling rate
Return values
c1Recursive filter coefficient
c2Non-recursive filter coefficient

◆ butter_stop_ord1()

void MHAFilter::butter_stop_ord1 ( double *  A,
double *  B,
double  f1,
double  f2,
double  fs 
)

Setup a first order butterworth band stop filter.

This function calculates the filter coefficients of a first order butterworth band stop filter.

Return values
Arecursive filter coefficients
Bnon recursive filter coefficients
Parameters
f1lower frequency
f2upper frequency
fssample frequency

◆ fir_lp()

std::vector< float > MHAFilter::fir_lp ( float  f_pass_,
float  f_stop_,
float  fs_,
unsigned  order_ 
)

Setup a nth order fir low pass filter.

This function calculates the filter coefficients of a nth order fir low pass filter filter. Frequency arguments above the nyquist frequency are accepted but the spectral response is truncated at the nyquist frequency

Returns
vector containing filter coefficients
Precondition
f_pass_ must be smaller or equal to f_stop_.
Parameters
f_pass_Upper passband frequency
f_stop-Lower stopband frequency
fs_sample frequency

◆ spec2fir()

MHASignal::waveform_t * MHAFilter::spec2fir ( const mha_spec_t spec,
const unsigned int  fftlen,
const MHAWindow::base_t window,
const bool  minphase 
)

Create a windowed impulse response/FIR filter coefficients from a spectrum.

Parameters
specInput spectrum
fftlenFFT length of spectrum
windowWindow shape (with length, e.g. initialized with MHAWindow::hanning(54)).
minphaseFlag, true if original phase should be discarded and replaced by a minimal phase function.

◆ gcd()

unsigned MHAFilter::gcd ( unsigned  a,
unsigned  b 
)
inline

greatest common divisor

◆ sinc()

double MHAFilter::sinc ( double  x)

sin(x)/x function, coping with x=0.

This is the historical sinc function, not the normalized sinc function.

◆ resampling_factors()

std::pair< unsigned, unsigned > MHAFilter::resampling_factors ( float  source_sampling_rate,
float  target_sampling_rate,
float  factor = 1.0f 
)

Computes rational resampling factor from two sampling rates.

The function will fail if either sampling_rate * factor is not an integer

Parameters
source_sampling_rateThe original sampling rate
target_sampling_rateThe desired sampling rate
factorA helper factor to use for non-integer sampling rates
Returns
a pair that contains first the upsampling factor and second the downsampling factor required for the specified resampling.
Exceptions
MHA_Errorif no rational resampling factor can be found.