Documentation
Tools for embedded systems
Loading...
Searching...
No Matches
qlibs::discreteSystem Class Reference

A LTI discrete system object. More...

#include <ltisys.hpp>

Inheritance diagram for qlibs::discreteSystem:
qlibs::ltisys qlibs::tdl

Public Member Functions

virtual ~discreteSystem ()
 
 discreteSystem (real_t *num, real_t *den, real_t *x, const size_t n_b, const size_t n_a) noexcept
 Constructor for a the discrete LTI system.
 
template<size_t NB, size_t NA>
 discreteSystem (real_t(&num)[NB], real_t(&den)[NA], real_t *x) noexcept
 Constructor for a the discrete LTI system.
 
template<size_t NB, size_t NA>
 discreteSystem (discreteTF< NB, NA > &dtf) noexcept
 Constructor for a the discrete LTI system from a transfer function definition.
 
bool setup (real_t *num, real_t *den, real_t *x, const size_t n_b, const size_t n_a) noexcept
 Setup and initialize an instance of the discrete LTI system.
 
template<size_t NB, size_t NA>
bool setup (real_t(&num)[NB], real_t(&den)[NA], real_t *x)
 Setup and initialize an instance of the discrete LTI system.
 
template<size_t NB, size_t NA>
bool setup (discreteTF< NB, NA > &dtf) noexcept
 Setup and initialize an instance of the discrete LTI system from a transfer function definition.
 
bool isInitialized (void) const noexcept override
 Check if the LTI discrete system is initialized.
 
 operator bool () const noexcept
 Check if the LTI discrete system is initialized.
 
bool setInitStates (const real_t *xi=nullptr) override
 Set the initial states for the discrete system.
 
- Public Member Functions inherited from qlibs::ltisys
virtual ~ltisys ()
 
 ltisys ()=default
 
real_t excite (real_t u) noexcept
 Drives the LTI system recursively using the provided input sample.
 
real_t operator() (const real_t u)
 Drives the LTI system recursively using the provided input sample.
 
 operator bool () const noexcept
 Check if the LTI system is initialized.
 
ltisysType getType (void) const
 Get the LTI system type.
 
bool setDelay (real_t *const w, const size_t nD, const real_t initVal=0.0_re) noexcept
 Set the input delay for LTI system.
 
bool setSaturation (const real_t minV, const real_t maxV) noexcept
 Setup the output saturation for the LTI system.
 
- Public Member Functions inherited from qlibs::tdl
virtual ~tdl () noexcept=default
 
 tdl ()=default
 
 tdl (real_t *const area, const size_t n, const real_t initVal=0.0_re) noexcept
 Constructor for the Tapped Delay Line (TDL) instance.
 
template<size_t numberOfDelays>
 tdl (real_t(&area)[numberOfDelays], const real_t initVal=0.0_re) noexcept
 Constructor for the Tapped Delay Line (TDL) instance.
 
void setup (real_t *const area, const size_t n, const real_t initVal=0.0_re) noexcept
 Setup and initialize a Tapped Delay Line (TDL) instance by setting the default optimal parameters.
 
template<size_t numberOfDelays>
void setup (real_t(&area)[numberOfDelays], const real_t initVal=0.0_re) noexcept
 Setup and initialize a Tapped Delay Line (TDL) instance by setting the default optimal parameters.
 
void flush (const real_t initVal=0.0_re) noexcept
 Clears all delays from the TDL and sets them to the specified value.
 
real_t getOldest (void) const noexcept
 Get the oldest sample from the TDL x(k-n)
 
real_t getRecent (void) const noexcept
 Get the most recent sample from the TDL x(k)
 
real_t getAtIndex (const size_t i) const noexcept
 Get the specified delayed sample from the TDL x(k-i)
 
void insertSample (const real_t sample) noexcept
 Insert a new sample to the TDL removing the oldest sample.
 
real_t operator[] (int index) noexcept
 Get the specified delayed sample from the TDL x(k-i)
 
void operator() (const real_t sample) noexcept
 Insert a new sample to the TDL removing the oldest sample.
 
bool isInitialized (void) const noexcept
 Check if the TDL has been initialized.
 
 operator bool () const noexcept
 Check if the TDL has been initialized.
 

Static Public Member Functions

static real_t updateFIR (real_t *w, const size_t wsize, const real_t x, const real_t *const c=nullptr)
 Evaluate the discrete FIR filter by updating the delay lines of x inside the window w of size wsize with the coefficients given in c. If c it's not supplied, this function just perform the window update.
 

Detailed Description

A LTI discrete system object.

The instance should be initialized using the discreteSystem::setup() method.

Constructor & Destructor Documentation

◆ ~discreteSystem()

virtual qlibs::discreteSystem::~discreteSystem ( )
inlinevirtual

◆ discreteSystem() [1/3]

qlibs::discreteSystem::discreteSystem ( real_t * num,
real_t * den,
real_t * x,
const size_t n_b,
const size_t n_a )
inlinenoexcept

Constructor for a the discrete LTI system.

Parameters
[in,out]num: An array of nb elements with the numerator coefficients of the transfer function. Coefficients should be given in descending powers of the n or nb-degree polynomial. Coefficients will be normalized internally.
[in,out]denAn array of or na elements with the denominator coefficients of the transfer function. Coefficients should be given in descending powers of the n or nb-degree polynomial. Coefficients will be normalized internally.
[in,out]xInitial conditions of the system. Should be an, an array of type discreteStates with max(na,nb) elements The supplied array will be updated on every invocation of discreteSystem::excite().
[in]n_bNumber of elements in num

example: \( b_{0}+b_{1}z^{-1}+b_{2}z^{-2}+b_{3}z^{-3}, nb = 4 \)

Parameters
[in]n_aNumber of elements in den.

example 1: \( a_{0}+a_{1}z^{-1}+a_{2}z^{-2}+a_{3}z^{-3}, na = 4 \)

Note
By default, initial conditions are set to zero. To change the initial conditions to the desired values, use the discreteSystem::setInitStates() method.

◆ discreteSystem() [2/3]

template<size_t NB, size_t NA>
qlibs::discreteSystem::discreteSystem ( real_t(&) num[NB],
real_t(&) den[NA],
real_t * x )
inlinenoexcept

Constructor for a the discrete LTI system.

Parameters
[in,out]num: An array of nb elements with the numerator coefficients of the transfer function. Coefficients should be given in descending powers of the n or nb-degree polynomial. Coefficients will be normalized internally.
[in,out]denAn array of or na elements with the denominator coefficients of the transfer function. Coefficients should be given in descending powers of the n or nb-degree polynomial. Coefficients will be normalized internally.
[in,out]xInitial conditions of the system. Should be an, an array of type discreteStates with max(na,nb) elements The supplied array will be updated on every invocation of discreteSystem::excite().
Note
By default, initial conditions are set to zero. To change the initial conditions to the desired values, use the discreteSystem::setInitStates() method.

◆ discreteSystem() [3/3]

template<size_t NB, size_t NA>
qlibs::discreteSystem::discreteSystem ( discreteTF< NB, NA > & dtf)
inlinenoexcept

Constructor for a the discrete LTI system from a transfer function definition.

Parameters
[in,out]dtf: The transfer function definition

Member Function Documentation

◆ isInitialized()

bool qlibs::discreteSystem::isInitialized ( void ) const
inlineoverridevirtualnoexcept

Check if the LTI discrete system is initialized.

Returns
true if the system has been initialized, otherwise return false.

Implements qlibs::ltisys.

◆ operator bool()

qlibs::discreteSystem::operator bool ( ) const
inlineexplicitnoexcept

Check if the LTI discrete system is initialized.

Returns
true if the system has been initialized, otherwise return false.

◆ setInitStates()

bool discreteSystem::setInitStates ( const real_t * xi = nullptr)
overridevirtual

Set the initial states for the discrete system.

Precondition
System should be previously initialized by using the discreteSystem::setup() method
Parameters
[in]xiAn array of n-elements with the initial state values. User can pass nullptr as argument to set initial conditions equal to zero.
Returns
true on success, otherwise return false.

Implements qlibs::ltisys.

◆ setup() [1/3]

template<size_t NB, size_t NA>
bool qlibs::discreteSystem::setup ( discreteTF< NB, NA > & dtf)
inlinenoexcept

Setup and initialize an instance of the discrete LTI system from a transfer function definition.

Parameters
[in,out]dtf: The transfer function definition
Returns
true on success, otherwise return false.

◆ setup() [2/3]

bool discreteSystem::setup ( real_t * num,
real_t * den,
real_t * x,
const size_t n_b,
const size_t n_a )
noexcept

Setup and initialize an instance of the discrete LTI system.

Parameters
[in,out]num: An array of nb elements with the numerator coefficients of the transfer function. Coefficients should be given in descending powers of the n or nb-degree polynomial. Coefficients will be normalized internally.
[in,out]denAn array of or na elements with the denominator coefficients of the transfer function. Coefficients should be given in descending powers of the n or nb-degree polynomial. Coefficients will be normalized internally.
[in,out]xInitial conditions of the system. Should be an, an array of type discreteStates with max(na,nb) elements The supplied array will be updated on every invocation of discreteSystem::excite().
[in]n_bNumber of elements in num

example: \( b_{0}+b_{1}z^{-1}+b_{2}z^{-2}+b_{3}z^{-3}, nb = 4 \)

Parameters
[in]n_aNumber of elements in den.

example 1: \( a_{0}+a_{1}z^{-1}+a_{2}z^{-2}+a_{3}z^{-3}, na = 4 \)

Returns
true on success, otherwise return false.
Note
By default, initial conditions are set to zero. To change the initial conditions to the desired values, use the discreteSystem::setInitStates() method.

◆ setup() [3/3]

template<size_t NB, size_t NA>
bool qlibs::discreteSystem::setup ( real_t(&) num[NB],
real_t(&) den[NA],
real_t * x )
inline

Setup and initialize an instance of the discrete LTI system.

Parameters
[in,out]num: An array of nb elements with the numerator coefficients of the transfer function. Coefficients should be given in descending powers of the n or nb-degree polynomial. Coefficients will be normalized internally.
[in,out]denAn array of or na elements with the denominator coefficients of the transfer function. Coefficients should be given in descending powers of the n or nb-degree polynomial. Coefficients will be normalized internally.
[in,out]xInitial conditions of the system. Should be an, an array of type discreteStates with max(na,nb) elements The supplied array will be updated on every invocation of discreteSystem::excite().
Returns
true on success, otherwise return false.
Note
By default, initial conditions are set to zero. To change the initial conditions to the desired values, use the discreteSystem::setInitStates() method.

◆ updateFIR()

real_t discreteSystem::updateFIR ( real_t * w,
const size_t wsize,
const real_t x,
const real_t *const c = nullptr )
static

Evaluate the discrete FIR filter by updating the delay lines of x inside the window w of size wsize with the coefficients given in c. If c it's not supplied, this function just perform the window update.

Parameters
[in,out]wAn array of wsize elements that holds the window with the delay lines of x.
[in]wsizeThe number of elements of w.
[in]xA sample of the input signal.
[in]cAn array of wsize elements with the coefficients of the FIR filter. Coefficients should be given in descending powers of the nth-degree polynomial. To ignore pass nullptr.
Returns
If c is provided, returns the evaluation of the FIR filter. otherwise return the sum of the updated window w.