SigPack - the C++ signal processing library
 
Loading...
Searching...
No Matches
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 21 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 45 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 52 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 489 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::do_adapt.

◆ 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 481 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::do_adapt.

◆ 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 59 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::buf, and sp::FIR_filt< T1, T2, T3 >::cur_p.

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

◆ filter() [1/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 147 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::filter().

Here is the call graph for this function:

◆ filter() [2/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 138 of file filter.h.

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

◆ 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 \)
Examples
adaptive_filter.cpp.

Definition at line 94 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::b.

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 464 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::K.

◆ 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 455 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::P.

◆ 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 446 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::mu.

◆ 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 417 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::b, sp::FIR_filt< T1, T2, T3 >::buf, sp::FIR_filt< T1, T2, T3 >::cur_p, sp::FIR_filt< T1, T2, T3 >::do_adapt, sp::FIR_filt< T1, T2, T3 >::K, sp::FIR_filt< T1, T2, T3 >::M, sp::FIR_filt< T1, T2, T3 >::P, sp::FIR_filt< T1, T2, T3 >::Q, and sp::FIR_filt< T1, T2, T3 >::R.

◆ 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 183 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::b, sp::FIR_filt< T1, T2, T3 >::blk_ctr, sp::FIR_filt< T1, T2, T3 >::buf, sp::FIR_filt< T1, T2, T3 >::cur_p, sp::FIR_filt< T1, T2, T3 >::do_adapt, sp::FIR_filt< T1, T2, T3 >::K, sp::FIR_filt< T1, T2, T3 >::L, sp::FIR_filt< T1, T2, T3 >::M, and sp::FIR_filt< T1, T2, T3 >::mu.

◆ 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 299 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::b, sp::FIR_filt< T1, T2, T3 >::blk_ctr, sp::FIR_filt< T1, T2, T3 >::buf, sp::FIR_filt< T1, T2, T3 >::c, sp::FIR_filt< T1, T2, T3 >::cur_p, sp::FIR_filt< T1, T2, T3 >::do_adapt, sp::FIR_filt< T1, T2, T3 >::K, sp::FIR_filt< T1, T2, T3 >::L, sp::FIR_filt< T1, T2, T3 >::M, sp::FIR_filt< T1, T2, T3 >::mu, and sp::FIR_filt< T1, T2, T3 >::X_tpz.

◆ 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
Examples
adaptive_filter.cpp.

Definition at line 239 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::b, sp::FIR_filt< T1, T2, T3 >::blk_ctr, sp::FIR_filt< T1, T2, T3 >::buf, sp::FIR_filt< T1, T2, T3 >::c, sp::FIR_filt< T1, T2, T3 >::cur_p, sp::FIR_filt< T1, T2, T3 >::do_adapt, sp::FIR_filt< T1, T2, T3 >::K, sp::FIR_filt< T1, T2, T3 >::L, sp::FIR_filt< T1, T2, T3 >::M, and sp::FIR_filt< T1, T2, T3 >::mu.

Referenced by main().

◆ 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 114 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::b, sp::FIR_filt< T1, T2, T3 >::buf, sp::FIR_filt< T1, T2, T3 >::cur_p, and sp::FIR_filt< T1, T2, T3 >::M.

◆ 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 360 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::b, sp::FIR_filt< T1, T2, T3 >::buf, sp::FIR_filt< T1, T2, T3 >::cur_p, sp::FIR_filt< T1, T2, T3 >::do_adapt, sp::FIR_filt< T1, T2, T3 >::K, sp::FIR_filt< T1, T2, T3 >::lmd, sp::FIR_filt< T1, T2, T3 >::M, and sp::FIR_filt< T1, T2, T3 >::P.

◆ set_coeffs() [1/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 84 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::set_coeffs().

Here is the call graph for this function:

◆ set_coeffs() [2/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 \)
Examples
adaptive_filter.cpp, and fir_iir.cpp.

Definition at line 70 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::b, sp::FIR_filt< T1, T2, T3 >::buf, sp::FIR_filt< T1, T2, T3 >::clear(), and sp::FIR_filt< T1, T2, T3 >::M.

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

Here is the call graph for this function:

◆ 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 473 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::mu.

◆ 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 388 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::b, sp::FIR_filt< T1, T2, T3 >::buf, sp::FIR_filt< T1, T2, T3 >::cur_p, sp::FIR_filt< T1, T2, T3 >::do_adapt, sp::FIR_filt< T1, T2, T3 >::K, sp::FIR_filt< T1, T2, T3 >::L, sp::FIR_filt< T1, T2, T3 >::M, sp::FIR_filt< T1, T2, T3 >::P, sp::FIR_filt< T1, T2, T3 >::Q, and sp::FIR_filt< T1, T2, T3 >::R.

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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}] \)
Examples
adaptive_filter.cpp.

Definition at line 104 of file filter.h.

References sp::FIR_filt< T1, T2, T3 >::b.

Referenced by main().

Member Data Documentation

◆ b

◆ blk_ctr

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

◆ buf

◆ c

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

◆ cur_p

◆ do_adapt

◆ K

◆ L

◆ 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 38 of file filter.h.

Referenced by sp::FIR_filt< T1, T2, T3 >::rls_adapt(), and sp::FIR_filt< T1, T2, T3 >::setup_rls().

◆ M

◆ mu

◆ 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 35 of file filter.h.

Referenced by sp::FIR_filt< T1, T2, T3 >::kalman_adapt(), and sp::FIR_filt< T1, T2, T3 >::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 36 of file filter.h.

Referenced by sp::FIR_filt< T1, T2, T3 >::kalman_adapt(), and sp::FIR_filt< T1, T2, T3 >::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 39 of file filter.h.

Referenced by sp::FIR_filt< T1, T2, T3 >::newt_adapt(), and sp::FIR_filt< T1, T2, T3 >::setup_newt().


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