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

A numerical state object. More...

#include <numa.hpp>

Inheritance diagram for qlibs::nState:
qlibs::derivative qlibs::integrator qlibs::pidController

Public Member Functions

virtual ~nState ()
 
 nState (const real_t x0=0.0_re, const real_t sn_1=0.0_re, const real_t sn_2=0.0_re) noexcept
 Constructor for the state object.
 
void init (const real_t x0=0.0_re, const real_t sn_1=0.0_re, const real_t sn_2=0.0_re) noexcept
 Initialize the state object.
 
real_t integrate (const real_t s, const real_t dt, const bool bUpdate=true) noexcept
 Perform a numerical integration step by using the specified integration method.
 
real_t derive (const real_t s, const real_t dt, const bool bUpdate=true) noexcept
 Perform a numerical derivation step by using the specified derivation method.
 
void setIntegrationMethod (integrationMethod m) noexcept
 Sets the numerical integration method.
 
void setDerivationMethod (derivationMethod m) noexcept
 Sets the numerical derivation method.
 
real_t operator() (void) const noexcept
 Get the value of the state.
 

Detailed Description

A numerical state object.

A numerical state object can be used to compute in real-time the numerical approximations of integral and derivative operations for data values sampled periodically.

Constructor & Destructor Documentation

◆ ~nState()

virtual qlibs::nState::~nState ( )
inlinevirtual

◆ nState()

qlibs::nState::nState ( const real_t x0 = 0.0_re,
const real_t sn_1 = 0.0_re,
const real_t sn_2 = 0.0_re )
inlinenoexcept

Constructor for the state object.

Parameters
[in]x0initial condition at time t(0)
[in]sn_1initial condition at time (t-1)
[in]sn_2initial condition at time (t-2)

Member Function Documentation

◆ derive()

real_t nState::derive ( const real_t s,
const real_t dt,
const bool bUpdate = true )
noexcept

Perform a numerical derivation step by using the specified derivation method.

Parameters
[in]sThe input signal
[in]dtThe time-step given in seconds.
[in]bUpdateFlag to update the states ( true by default).
Returns
The current value of the derivation step.

◆ init()

void nState::init ( const real_t x0 = 0.0_re,
const real_t sn_1 = 0.0_re,
const real_t sn_2 = 0.0_re )
noexcept

Initialize the state object.

Parameters
[in]x0initial condition at time t(0)
[in]sn_1initial condition at time (t-1)
[in]sn_2initial condition at time (t-2)

◆ integrate()

real_t nState::integrate ( const real_t s,
const real_t dt,
const bool bUpdate = true )
noexcept

Perform a numerical integration step by using the specified integration method.

Parameters
[in]sThe input signal
[in]dtThe time-step given in seconds.
[in]bUpdateFlag to update the states ( true by default).
Returns
The current value of the integration step.

◆ operator()()

real_t qlibs::nState::operator() ( void ) const
inlinenoexcept

Get the value of the state.

Returns
The current value of the state.

◆ setDerivationMethod()

void qlibs::nState::setDerivationMethod ( derivationMethod m)
inlinenoexcept

Sets the numerical derivation method.

Configures the method used to compute the numerical derivative of input values. Different methods offer varying accuracy and responsiveness depending on signal characteristics.

Parameters
[in]mThe desired derivation method. Supported options:

DERIVATION_2POINTS : (default) Uses a simple two-point (first-order backward) difference.

DERIVATION_BACKWARD : Derivative using the three-point backward-difference.

DERIVATION_FORWARD : Derivative using the three-point forward-difference.

Note
Choose the method based on the required balance between accuracy and latency.

◆ setIntegrationMethod()

void qlibs::nState::setIntegrationMethod ( integrationMethod m)
inlinenoexcept

Sets the numerical integration method.

Configures the method used to approximate the integral of input values. This allows the user to select from several common numerical integration techniques.

Parameters
[in]mThe desired integration method. Supported options:

INTEGRATION_RECTANGULAR : Integrate using the Rectangular rule.

INTEGRATION_TRAPEZOIDAL : (default) Integrate using the Trapezoidal rule.

INTEGRATION_SIMPSON : Integrate using the Simpson's 1/3 rule.

INTEGRATION_QUADRATIC : Integrate using a parabola fit to three points.

Note
The effectiveness and accuracy of each method depend on the signal characteristics and time step.