SigPack - the C++ signal processing library
sp::FIR_filt< T1, T2, T3 > Class Template Reference

#include <filter.h>

Collaboration diagram for sp::FIR_filt< T1, T2, T3 >:
Collaboration graph

Public Member Functions

 FIR_filt ()
 
 ~FIR_filt ()
 
void clear (void)
 
void set_coeffs (const arma::Mat< T2 > &_b)
 
void set_coeffs (const arma::Col< T2 > &_b_col)
 
arma::Col< T2 > get_coeffs ()
 
void update_coeffs (const arma::Mat< T2 > &_b)
 
T3 operator() (const T1 &in)
 
arma::Mat< T3 > filter (const arma::Mat< T1 > &in)
 
arma::Col< T3 > filter (const arma::Col< T1 > &in)
 
void setup_lms (const arma::uword _N, const double _mu, const arma::uword _L=1)
 
void lms_adapt (const T3 _err)
 
void setup_nlms (const arma::uword _N, const double _mu, const T2 _c, const arma::uword _L=1)
 
void nlms_adapt (const T3 _err)
 
void setup_newt (const arma::uword _N, const double _mu, const T2 _c, const arma::uword _L=1)
 
void newt_adapt (const T3 _err)
 
void setup_rls (const arma::uword _N, const double _lmd, const double _P0)
 
void rls_adapt (const T3 _err)
 
void setup_kalman (const arma::uword _N, const double _P0, const double _Q0, const double _R0)
 
void kalman_adapt (const T3 _err)
 
double get_step_size (void)
 
arma::Mat< T1 > get_P (void)
 
arma::Mat< T1 > get_K (void)
 
void set_step_size (const double _mu)
 
void adapt_enable (void)
 
void adapt_disble (void)
 

Private Attributes

arma::uword M
 
arma::uword cur_p
 
arma::Mat< T1 > buf
 
arma::Mat< T2 > b
 
double mu
 
arma::uword L
 
arma::uword blk_ctr
 
T2 c
 
arma::Mat< T1 > P
 
arma::Mat< T1 > Q
 
arma::Mat< T1 > R
 
arma::Mat< T1 > K
 
double lmd
 
arma::Mat< T1 > X_tpz
 
arma::uword do_adapt
 

Detailed Description

template<class T1, class T2, class T3>
class sp::FIR_filt< T1, T2, T3 >

Implements FIR/MA filter functions as

\[ y(n) = \sum_{k=0}^{M-1}{b_kx(n-k)}=b_0x(n)+b_1x(n-1)+...+b_{M-1}x(n-(M-1))\]

where M is the number of taps in the FIR filter. The filter order is M-1. Adaptive update of filter is possible with LMS or NLMS algorithms

Examples:
adaptive_filter.cpp, and fir_iir.cpp.

Definition at line 20 of file filter.h.

Constructor & Destructor Documentation

◆ FIR_filt()

template<class T1, class T2, class T3>
sp::FIR_filt< T1, T2, T3 >::FIR_filt ( )
inline

Constructor.

Definition at line 44 of file filter.h.

◆ ~FIR_filt()

template<class T1, class T2, class T3>
sp::FIR_filt< T1, T2, T3 >::~FIR_filt ( )
inline

Destructor.

Definition at line 49 of file filter.h.

Member Function Documentation

◆ adapt_disble()

template<class T1, class T2, class T3>
void sp::FIR_filt< T1, T2, T3 >::adapt_disble ( void  )
inline

Stop adapt.

Definition at line 466 of file filter.h.

◆ adapt_enable()

template<class T1, class T2, class T3>
void sp::FIR_filt< T1, T2, T3 >::adapt_enable ( void  )
inline

Start adapt.

Definition at line 461 of file filter.h.

◆ clear()

template<class T1, class T2, class T3>
void sp::FIR_filt< T1, T2, T3 >::clear ( void  )
inline

Clears the internal states and pointer.

Definition at line 54 of file filter.h.

Referenced by sp::FIR_filt< T1, double, T1 >::set_coeffs(), and sp::IIR_filt< T1, T2, T3 >::set_coeffs().

◆ filter() [1/2]

template<class T1, class T2, class T3>
arma::Mat<T3> sp::FIR_filt< T1, T2, T3 >::filter ( const arma::Mat< T1 > &  in)
inline

Filter function.

Returns
Filtered output
Parameters
inInput vector

Definition at line 127 of file filter.h.

Referenced by sp::FIR_filt< T1, double, T1 >::filter().

◆ filter() [2/2]

template<class T1, class T2, class T3>
arma::Col<T3> sp::FIR_filt< T1, T2, T3 >::filter ( const arma::Col< T1 > &  in)
inline

Definition at line 135 of file filter.h.

◆ get_coeffs()

template<class T1, class T2, class T3>
arma::Col<T2> sp::FIR_filt< T1, T2, T3 >::get_coeffs ( )
inline

Get coefficients from FIR filter.

Returns
b Filter coefficients \( [b_0 ..b_{M-1}]^T \)

Definition at line 89 of file filter.h.

Referenced by main().

◆ get_K()

template<class T1, class T2, class T3>
arma::Mat<T1> sp::FIR_filt< T1, T2, T3 >::get_K ( void  )
inline

Get K.

Returns
K

Definition at line 450 of file filter.h.

◆ get_P()

template<class T1, class T2, class T3>
arma::Mat<T1> sp::FIR_filt< T1, T2, T3 >::get_P ( void  )
inline

Get P.

Returns
P

Definition at line 444 of file filter.h.

◆ get_step_size()

template<class T1, class T2, class T3>
double sp::FIR_filt< T1, T2, T3 >::get_step_size ( void  )
inline

Get step size.

Returns
Step size mu

Definition at line 438 of file filter.h.

◆ kalman_adapt()

template<class T1, class T2, class T3>
void sp::FIR_filt< T1, T2, T3 >::kalman_adapt ( const T3  _err)
inline

Kalman Filter update function.

The Kalman filter is updated as
\( \mathbf{b(n)} = \mathbf{b(n-1)}+\mathbf{Kx(n)}\)
where
\( \mathbf{K} =\frac{\mathbf{Px}}{R+\mathbf{x^TPx}} \)
and
\( \mathbf{P^+} =\mathbf{P^-+xP^-x^T }+Q \)

Parameters
_errFeedback error

Definition at line 409 of file filter.h.

Referenced by main().

◆ lms_adapt()

template<class T1, class T2, class T3>
void sp::FIR_filt< T1, T2, T3 >::lms_adapt ( const T3  _err)
inline

LMS Filter update function.

The LMS filter is updated as
\( \mathbf{b(n)} = \mathbf{b(n-1)}+2\mu\mathbf{x(n)}err(n) \)
where
\( err(n) = d(n)-\mathbf{b(n-1)^Tx(n)} \)

Parameters
_errFeedback error

Definition at line 172 of file filter.h.

◆ newt_adapt()

template<class T1, class T2, class T3>
void sp::FIR_filt< T1, T2, T3 >::newt_adapt ( const T3  _err)
inline

LMS-Newton Filter update function.

The LMS-Newton filter is updated as
\( \mathbf{b(n)} = \mathbf{b(n-1)}+2\mu\frac{\mathbf{x(n)}err(n)}{c+\mathbf{R_{xx}}} \)
where
\( err(n) = d(n)-\mathbf{b(n-1)^Tx(n)} \)
and \( \mathbf{R_{xx}} \) is the correlation matrix

Parameters
_errFeedback error

Definition at line 290 of file filter.h.

◆ nlms_adapt()

template<class T1, class T2, class T3>
void sp::FIR_filt< T1, T2, T3 >::nlms_adapt ( const T3  _err)
inline

NLMS Filter update function.

The NLMS filter is updated as
\( \mathbf{b(n)} = \mathbf{b(n-1)}+2\mu\frac{\mathbf{x(n)}err(n)}{c+\mathbf{x(n)^Tx(n)}} \)
where
\( err(n) = d(n)-\mathbf{b(n-1)^Tx(n)} \)

Parameters
_errFeedback error

Definition at line 229 of file filter.h.

◆ operator()()

template<class T1, class T2, class T3>
T3 sp::FIR_filt< T1, T2, T3 >::operator() ( const T1 &  in)
inline

Filter operator.

Returns
Filtered output
Parameters
inInput sample

Definition at line 103 of file filter.h.

◆ rls_adapt()

template<class T1, class T2, class T3>
void sp::FIR_filt< T1, T2, T3 >::rls_adapt ( const T3  _err)
inline

RLS Filter update function.

The RLS filter is updated as
\( \mathbf{b(n)} = \mathbf{b(n-1)}+\mathbf{Kx(n)}\)
where
\( \mathbf{K} =\frac{\mathbf{Px}}{\lambda+\mathbf{x^TPx}} \)
and
\( \mathbf{P^+} =\frac{\mathbf{P^-+xP^-x^T }}{\lambda} \)

Parameters
_errFeedback error

Definition at line 351 of file filter.h.

◆ set_coeffs() [1/2]

template<class T1, class T2, class T3>
void sp::FIR_filt< T1, T2, T3 >::set_coeffs ( const arma::Mat< T2 > &  _b)
inline

Sets coefficients in FIR filter. The internal state and pointers are cleared.

Parameters
_bFilter coefficients \( [b_0 ..b_{M-1}]^T \)

Definition at line 65 of file filter.h.

Referenced by main(), sp::resampling< T1 >::resampling(), and sp::FIR_filt< T1, double, T1 >::set_coeffs().

◆ set_coeffs() [2/2]

template<class T1, class T2, class T3>
void sp::FIR_filt< T1, T2, T3 >::set_coeffs ( const arma::Col< T2 > &  _b_col)
inline

Sets coefficients in FIR filter (col format) The internal state and pointers are cleared.

Parameters
_b_colFilter coefficients \( [b_0 ..b_{M-1}]^T \)

Definition at line 79 of file filter.h.

◆ set_step_size()

template<class T1, class T2, class T3>
void sp::FIR_filt< T1, T2, T3 >::set_step_size ( const double  _mu)
inline

Set step size.

Parameters
_muStep size mu

Definition at line 456 of file filter.h.

◆ setup_kalman()

template<class T1, class T2, class T3>
void sp::FIR_filt< T1, T2, T3 >::setup_kalman ( const arma::uword  _N,
const double  _P0,
const double  _Q0,
const double  _R0 
)
inline

Kalman Filter function setup.

Parameters
_NNumber of filter taps
_P0Inverse corr matrix initializer
_Q0Process noise matrix initializer
_R0Measurement noise matrix initializer

Definition at line 379 of file filter.h.

Referenced by main().

◆ setup_lms()

template<class T1, class T2, class T3>
void sp::FIR_filt< T1, T2, T3 >::setup_lms ( const arma::uword  _N,
const double  _mu,
const arma::uword  _L = 1 
)
inline

LMS Filter function setup.

Parameters
_NNumber of filter taps
_muStep size
_LBlock length

Definition at line 147 of file filter.h.

◆ setup_newt()

template<class T1, class T2, class T3>
void sp::FIR_filt< T1, T2, T3 >::setup_newt ( const arma::uword  _N,
const double  _mu,
const T2  _c,
const arma::uword  _L = 1 
)
inline

LMS-Newton Filter function setup. (Affine Projection Algorithm)

Parameters
_NNumber of filter taps
_muStep size
_cRegularization factor
_LBlock length

Definition at line 260 of file filter.h.

◆ setup_nlms()

template<class T1, class T2, class T3>
void sp::FIR_filt< T1, T2, T3 >::setup_nlms ( const arma::uword  _N,
const double  _mu,
const T2  _c,
const arma::uword  _L = 1 
)
inline

NLMS Filter function setup.

Parameters
_NNumber of filter taps
_muStep size
_cRegularization factor
_LBlock length

Definition at line 202 of file filter.h.

◆ setup_rls()

template<class T1, class T2, class T3>
void sp::FIR_filt< T1, T2, T3 >::setup_rls ( const arma::uword  _N,
const double  _lmd,
const double  _P0 
)
inline

RLS Filter function setup.

Parameters
_NNumber of filter taps
_lmdLambda
_P0Inverse corr matrix initializer

Definition at line 324 of file filter.h.

◆ update_coeffs()

template<class T1, class T2, class T3>
void sp::FIR_filt< T1, T2, T3 >::update_coeffs ( const arma::Mat< T2 > &  _b)
inline

Updates coefficients in FIR filter without clearing the internal states.

Parameters
_bFilter coefficients \( [b_0 ..b_{M-1}] \)

Definition at line 96 of file filter.h.

Referenced by main().

Member Data Documentation

◆ b

template<class T1, class T2, class T3>
arma::Mat<T2> sp::FIR_filt< T1, T2, T3 >::b
private

Filter coefficients.

Definition at line 27 of file filter.h.

Referenced by sp::fir1(), sp::fir1_bp(), sp::fir1_bs(), sp::fir1_hp(), and sp::freq().

◆ blk_ctr

template<class T1, class T2, class T3>
arma::uword sp::FIR_filt< T1, T2, T3 >::blk_ctr
private

Adaptive filter block length counter.

Definition at line 31 of file filter.h.

◆ buf

◆ c

template<class T1, class T2, class T3>
T2 sp::FIR_filt< T1, T2, T3 >::c
private

Adaptive filter NLMS regulation const.

Definition at line 32 of file filter.h.

◆ cur_p

template<class T1, class T2, class T3>
arma::uword sp::FIR_filt< T1, T2, T3 >::cur_p
private

Pointer to current sample in buffer.

Definition at line 25 of file filter.h.

Referenced by sp::FIR_filt< T1, double, T1 >::operator()().

◆ do_adapt

template<class T1, class T2, class T3>
arma::uword sp::FIR_filt< T1, T2, T3 >::do_adapt
private

Adaptive filter enable flag.

Definition at line 39 of file filter.h.

◆ K

template<class T1, class T2, class T3>
arma::Mat<T1> sp::FIR_filt< T1, T2, T3 >::K
private

Adaptive filter gain vector.

Definition at line 36 of file filter.h.

Referenced by sp::freq(), sp::freqz(), sp::FIR_filt< T1, double, T1 >::get_K(), and sp::phasez().

◆ L

template<class T1, class T2, class T3>
arma::uword sp::FIR_filt< T1, T2, T3 >::L
private

Adaptive filter block length.

Definition at line 30 of file filter.h.

Referenced by sp::FIR_filt< T1, double, T1 >::newt_adapt().

◆ lmd

template<class T1, class T2, class T3>
double sp::FIR_filt< T1, T2, T3 >::lmd
private

Adaptive filter RLS forgetting factor.

Definition at line 37 of file filter.h.

◆ M

◆ mu

template<class T1, class T2, class T3>
double sp::FIR_filt< T1, T2, T3 >::mu
private

Adaptive filter step size.

Definition at line 29 of file filter.h.

Referenced by sp::FIR_filt< T1, double, T1 >::get_step_size().

◆ P

template<class T1, class T2, class T3>
arma::Mat<T1> sp::FIR_filt< T1, T2, T3 >::P
private

◆ Q

template<class T1, class T2, class T3>
arma::Mat<T1> sp::FIR_filt< T1, T2, T3 >::Q
private

Adaptive filter Process noise.

Definition at line 34 of file filter.h.

Referenced by sp::FIR_filt< T1, double, T1 >::kalman_adapt(), and sp::FIR_filt< T1, double, T1 >::setup_kalman().

◆ R

template<class T1, class T2, class T3>
arma::Mat<T1> sp::FIR_filt< T1, T2, T3 >::R
private

Adaptive filter Measurement noise.

Definition at line 35 of file filter.h.

Referenced by sp::FIR_filt< T1, double, T1 >::setup_kalman().

◆ X_tpz

template<class T1, class T2, class T3>
arma::Mat<T1> sp::FIR_filt< T1, T2, T3 >::X_tpz
private

Adaptive filter Toeplitz for Corr matrix calc.

Definition at line 38 of file filter.h.


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