@@ -86,7 +86,8 @@ namespace qlibs {
8686 const real_t sn_2 = 0 .0_re ) noexcept ;
8787
8888 /* *
89- * @brief Perform a numerical integration step.
89+ * @brief Perform a numerical integration step by using the specified
90+ * integration method.
9091 * @param[in] s The input signal
9192 * @param[in] dt The time-step given in seconds.
9293 * @param[in] bUpdate Flag to update the states ( @c true by default).
@@ -97,7 +98,8 @@ namespace qlibs {
9798 const bool bUpdate = true ) noexcept ;
9899
99100 /* *
100- * @brief Perform a numerical derivation step by using the delta rule.
101+ * @brief Perform a numerical derivation step by using the specified
102+ * derivation method.
101103 * @param[in] s The input signal
102104 * @param[in] dt The time-step given in seconds.
103105 * @param[in] bUpdate Flag to update the states ( @c true by default).
@@ -108,8 +110,11 @@ namespace qlibs {
108110 const bool bUpdate = true ) noexcept ;
109111
110112 /* *
111- * @brief Set integration method .
112- * @param[in] m The desired integration method. Use one of the following:
113+ * @brief Sets the numerical integration method.
114+ * @details Configures the method used to approximate the integral of
115+ * input values. This allows the user to select from several common
116+ * numerical integration techniques.
117+ * @param[in] m The desired integration method. Supported options:
113118 *
114119 * @c ::INTEGRATION_RECTANGULAR : Integrate using the Rectangular rule.
115120 *
@@ -119,24 +124,35 @@ namespace qlibs {
119124 *
120125 * @c ::INTEGRATION_QUADRATIC : Integrate using a parabola fit to three points.
121126 *
122- * @return @c true on success, otherwise return @c false.
127+ * @note The effectiveness and accuracy of each method depend on the
128+ * signal characteristics and time step.
129+ *
130+ * @return @c true if the method was successfully set; @c false otherwise.
123131 */
124132 inline void setIntegrationMethod ( integrationMethod m ) noexcept
125133 {
126134 iMethod = m;
127135 }
128136
129137 /* *
130- * @brief Set derivation method.
131- * @param[in] m The desired derivation method. Use one of the following:
138+ * @brief Sets the numerical derivation method.
139+ * @details Configures the method used to compute the numerical
140+ * derivative of input values. Different methods offer varying accuracy
141+ * and responsiveness depending on signal characteristics.
142+ *
143+ * @param[in] m The desired derivation method. Supported options:
132144 *
133- * @c ::DERIVATION_2POINTS : (default) Derivative using two points.
145+ * @c ::DERIVATION_2POINTS : (default) Uses a simple two-point
146+ * (first-order backward) difference.
134147 *
135148 * @c ::DERIVATION_BACKWARD : Derivative using the three-point backward-difference.
136149 *
137150 * @c ::DERIVATION_FORWARD : Derivative using the three-point forward-difference.
138151 *
139- * @return @c true on success, otherwise return @c false.
152+ * @note Choose the method based on the required balance between
153+ * accuracy and latency.
154+ *
155+ * @return @c true if the method was successfully set; @c false otherwise.
140156 */
141157 inline void setDerivationMethod ( derivationMethod m ) noexcept
142158 {
@@ -203,6 +219,88 @@ namespace qlibs {
203219 }
204220 /* ! @endcond */
205221
222+ /* *
223+ * @brief A numerical integration class.
224+ * @details A numerical integration class that can be used to compute
225+ * in real-time the numerical approximation of an integral for data values
226+ * sampled periodically. It supports optional output saturation limits.
227+ */
228+ class integrator : public nState , private nonCopyable {
229+ private:
230+ real_t dt;
231+ real_t min{ -REAL_MAX };
232+ real_t max{ +REAL_MAX };
233+ public:
234+ virtual ~integrator () {}
235+
236+ /* *
237+ * @brief Constructs an integrator block with a given @a timeStep time
238+ * and optional initial condition.
239+ * @param[in] timeStep The fixed time step (dt) used to compute the
240+ * integration.
241+ * @param[in] initialCondition The initial output value of the
242+ * integrator. Default is 0.0.
243+ * @note It is assumed that input samples will be provided at regular
244+ * intervals of timeStep.
245+ */
246+ integrator ( const real_t timeStep,
247+ const real_t initialCondition = 0 .0_re );
248+
249+ /* *
250+ * @brief Sets the saturation limits for the integrator output.
251+ * @param[in] minV The minimum value the output can reach.
252+ * @param[in] maxV The maximum value the output can reach.
253+ * @return @c true if the limits are valid and applied; @c false
254+ * otherwise (e.g., minV > maxV).
255+ * @note If not set, the output is unbounded.
256+ */
257+ bool setSaturation ( const real_t minV, const real_t maxV ) noexcept ;
258+
259+ /* *
260+ * @brief Performs one step of numerical integration.
261+ * @param[in] xDot The input value to be integrated
262+ * @return The integrated value (i.e., the output of the integrator)
263+ * after applying saturation.
264+ * @note This should be called at intervals equal to the time step provided in the constructor.
265+ */
266+ real_t operator ()( const real_t xDot );
267+ };
268+
269+ /* *
270+ * @brief A numerical derivative class.
271+ * @details A numerical derivative class that can be used to compute
272+ * in real-time the numerical approximations of derivatives for data values
273+ * sampled periodically.
274+ */
275+ class derivative : public nState , private nonCopyable {
276+ private:
277+ real_t dt;
278+ public:
279+ virtual ~derivative () {}
280+
281+ /* *
282+ * @brief Constructs a derivative block with a given @a timeStep and
283+ * optional initial condition.
284+ * @param[in] timeStep The fixed time step (dt) used to compute the
285+ * derivative.
286+ * @param[in] initialCondition The initial input value. Default is @c 0.0
287+ * @note It is assumed that input samples will be provided at regular
288+ * intervals of timeStep.
289+ */
290+ derivative ( const real_t timeStep,
291+ const real_t initialCondition = 0 .0_re );
292+
293+ /* *
294+ * @brief Computes the numerical derivative based on the current
295+ * input value.
296+ * @param[in] xt The current input value.
297+ * @return The estimated derivative of the input signal.
298+ * @note This should be called at intervals equal to the time step
299+ * provided in the constructor.
300+ */
301+ real_t operator ()( const real_t xt );
302+ };
303+
206304 /* * @}*/
207305}
208306
0 commit comments