Documentation
Tools for embedded systems
Loading...
Searching...
No Matches
smoother.hpp
1
9#ifndef QLIBS_SMOOTHER
10#define QLIBS_SMOOTHER
11
12#include <include/qlibs_types.hpp>
13#include <include/tdl.hpp>
14
18namespace qlibs {
27 class smoother {
28 protected:
30 bool init{ true };
31 static void windowSet( real_t *w,
32 const size_t wsize,
33 const real_t x );
35 public:
36 virtual ~smoother() {}
37
43 bool isInitialized( void ) const;
44
51 virtual real_t smooth( const real_t x ) = 0;
52
57 inline bool reset( void )
58 {
59 init = true;
60 return true;
61 }
62 };
63
67 class smootherLPF1 : public smoother {
68 protected:
70 real_t alpha{ 0.9_re };
71 real_t y1{ 0.0_re };
73 public:
74 virtual ~smootherLPF1() {}
75
82 bool setup( const real_t a = 0.9_re );
83
90 real_t smooth( const real_t x ) override;
91 };
92
96 class smootherLPF2 : public smoother {
97 protected:
99 real_t y1{ 0.0_re };
100 real_t y2{ 0.0_re };
101 real_t x1{ 0.0_re };
102 real_t x2{ 0.0_re };
103 real_t k{ 0.0_re };
104 real_t a1{ 0.0_re };
105 real_t a2{ 0.0_re };
106 real_t b1{ 0.0_re };
108 public:
109 virtual ~smootherLPF2() {}
110
117 bool setup( const real_t a = 0.9_re );
118
125 real_t smooth( const real_t x ) override;
126 };
127
132 class smootherMWM1 : public smoother, private nonCopyable {
133 protected:
135 real_t *w{ nullptr };
136 size_t wsize{ 0U };
138 public:
139 virtual ~smootherMWM1() {}
140
147 bool setup( real_t *window,
148 const size_t w_size );
149
155 template <size_t windowSize>
156 bool setup( real_t (&window)[ windowSize ] )
157 {
158 return setup( window, windowSize );
159 }
160
167 real_t smooth( const real_t x ) override;
168 };
169
174 class smootherMWM2 : public smoother, public tdl {
175 protected:
177 real_t sum{ 0.0_re };
179 public:
180 virtual ~smootherMWM2() {}
181
188 bool setup( real_t *window,
189 const size_t w_size );
190
196 template <size_t windowSize>
197 bool setup( real_t (&window)[ windowSize ] )
198 {
199 return setup( window, windowSize );
200 }
201
208 real_t smooth( const real_t x ) override;
209 };
210
215 class smootherMOR1 : public smoother, private nonCopyable {
216 protected:
218 real_t *w{ nullptr };
219 real_t m{ 0.0_re };
220 real_t alpha{ 0.8_re };
221 size_t wsize{ 0U };
223 public:
224 virtual ~smootherMOR1() {}
225
233 bool setup( real_t *window,
234 const size_t w_size,
235 const real_t a = 0.9_re );
236
243 template <size_t windowSize>
244 bool setup( real_t (&window)[ windowSize ],
245 const real_t a = 0.9_re )
246 {
247 return setup( window, windowSize, a );
248 }
249
256 real_t smooth( const real_t x ) override;
257 };
258
263 class smootherMOR2 : public smoother, public tdl {
264 protected:
266 real_t sum{ 0.0_re };
267 real_t m{ 0.0_re };
268 real_t alpha{ 0.8_re };
270 public:
271 virtual ~smootherMOR2() {}
272
280 bool setup( real_t *window,
281 const size_t w_size,
282 const real_t a = 0.9_re );
283
290 template <size_t windowSize>
291 bool setup( real_t (&window)[ windowSize ],
292 const real_t a = 0.9_re )
293 {
294 return setup( window, windowSize, a );
295 }
296
303 real_t smooth( const real_t x ) override;
304 };
305
309 class smootherGMWF : public smoother, private nonCopyable {
310 protected:
312 real_t *w{ nullptr };
313 real_t *k{ nullptr };
314 size_t wsize;
316 public:
317 virtual ~smootherGMWF() {}
318
329 bool setup( const real_t sg,
330 const real_t c,
331 real_t *window,
332 real_t *kernel,
333 const size_t wk_size );
334
344 template <size_t windowAndKernelSize>
345 bool setup( const real_t sg,
346 const real_t c,
347 real_t (&window)[ windowAndKernelSize ],
348 real_t (&kernel)[ windowAndKernelSize ] )
349 {
350 return setup( sg, c, window, kernel, windowAndKernelSize );
351 }
352
359 real_t smooth( const real_t x ) override;
360 };
361
365 class smootherEXPW : public smoother {
366 protected:
368 real_t lambda{ 0.8_re };
369 real_t m{ 0_re };
370 real_t w{ 1.0_re };
372 public:
373 virtual ~smootherEXPW() {}
374
380 bool setup( const real_t lam = 0.8_re );
381
388 real_t smooth( const real_t x ) override;
389 };
390
394 class smootherKLMN : public smoother {
395 protected:
397 real_t xS{ 0.0_re }; /* state */
398 real_t A{ 1.0_re }; /* x(n)=A*x(n-1)+u(n),u(n)~N(0,q) */
399 real_t H{ 1.0_re }; /* z(n)=H*x(n)+w(n),w(n)~N(0,r) */
400 real_t q{ 100.0_re }; /* process(predict) noise covariance */
401 real_t r{ 0.9_re }; /* measure noise covariance */
402 real_t p{ 100.0_re }; /* estimated error covariance */
403 real_t gain;
405 public:
406 virtual ~smootherKLMN() {}
407
415 bool setup( const real_t processNoiseCov,
416 const real_t measureNoiseCov,
417 const real_t estErrorCov );
418
425 real_t smooth( const real_t x ) override;
426 };
427
431 class smootherDESF : public smoother {
432 protected:
434 real_t alpha;
435 real_t beta;
436 real_t lt;
437 real_t bt;
438 real_t n;
440 public:
441
449 virtual ~smootherDESF() {}
450 bool setup( const real_t a,
451 const real_t b,
452 const size_t nS );
453
460 real_t smooth( const real_t x ) override;
461 };
462
466 class smootherALNF : public smoother, private nonCopyable {
467 protected:
469 real_t alpha;
470 real_t mu;
471 real_t *w{ nullptr };
472 real_t *w_1{ nullptr };
473 real_t *xx{ nullptr };
474 size_t n{ 0U };
476 public:
477 virtual ~smootherALNF() {}
478
490 bool setup( const real_t a,
491 const real_t m,
492 const size_t wsize,
493 real_t *window,
494 real_t *weights,
495 real_t *w1 = nullptr );
496
506 template <size_t windowSize>
507 bool setup( const real_t a,
508 const real_t m,
509 real_t (&window)[ windowSize ],
510 real_t (&weights)[ windowSize ],
511 real_t (&w1)[ windowSize ] )
512 {
513 return setup( a, m, windowSize, window, weights, w1 );
514 }
515
523 template <size_t windowSize>
524 bool setup( const real_t a,
525 real_t (&window)[ windowSize ],
526 real_t (&weights)[ windowSize ] )
527 {
528 return setup( a, 0.0F, windowSize, window, weights, nullptr);
529 }
530
537 real_t smooth( const real_t x ) override;
538 };
539
541}
542
543
544#endif /*QLIBS_SMOOTHER*/
Adaptive Filter LMS.
Definition smoother.hpp:466
bool setup(const real_t a, const real_t m, real_t(&window)[windowSize], real_t(&weights)[windowSize], real_t(&w1)[windowSize])
Setup an initialize the Adaptive Filter LMS.
Definition smoother.hpp:507
bool setup(const real_t a, real_t(&window)[windowSize], real_t(&weights)[windowSize])
Setup an initialize the Adaptive Filter LMS.
Definition smoother.hpp:524
real_t smooth(const real_t x) override
Perform the smooth operation recursively for the input signal x.
Definition smoother.cpp:389
virtual ~smootherALNF()
Definition smoother.hpp:477
bool setup(const real_t a, const real_t m, const size_t wsize, real_t *window, real_t *weights, real_t *w1=nullptr)
Setup an initialize the Adaptive Filter LMS.
Definition smoother.cpp:367
Double exponential smoothing (Holt’s Method)
Definition smoother.hpp:431
virtual ~smootherDESF()
Setup an initialize the Double exponential smoothing instance.
Definition smoother.hpp:449
real_t smooth(const real_t x) override
Perform the smooth operation recursively for the input signal x.
Definition smoother.cpp:351
bool setup(const real_t a, const real_t b, const size_t nS)
Definition smoother.cpp:333
An Exponential weighting filter.
Definition smoother.hpp:365
real_t smooth(const real_t x) override
Perform the smooth operation recursively for the input signal x.
Definition smoother.cpp:279
virtual ~smootherEXPW()
Definition smoother.hpp:373
bool setup(const real_t lam=0.8_re)
Setup an initialize the Exponential weighting filter.
Definition smoother.cpp:265
A Gaussian filter.
Definition smoother.hpp:309
virtual ~smootherGMWF()
Definition smoother.hpp:317
bool setup(const real_t sg, const real_t c, real_t *window, real_t *kernel, const size_t wk_size)
Setup an initialize the Gaussian filter.
Definition smoother.cpp:216
bool setup(const real_t sg, const real_t c, real_t(&window)[windowAndKernelSize], real_t(&kernel)[windowAndKernelSize])
Setup an initialize the Gaussian filter.
Definition smoother.hpp:345
real_t smooth(const real_t x) override
Perform the smooth operation recursively for the input signal x.
Definition smoother.cpp:256
The smoother base abstract class.
Definition smoother.hpp:27
virtual ~smoother()
Definition smoother.hpp:36
bool reset(void)
Reset the the smoother filter.
Definition smoother.hpp:57
bool isInitialized(void) const
Check if the smoother filter is initialized.
virtual real_t smooth(const real_t x)=0
Perform the smooth operation recursively for the input signal x.
A scalar Kalman filter.
Definition smoother.hpp:394
bool setup(const real_t processNoiseCov, const real_t measureNoiseCov, const real_t estErrorCov)
Setup an initialize the scalar Kalman filter.
Definition smoother.cpp:295
real_t smooth(const real_t x) override
Perform the smooth operation recursively for the input signal x.
Definition smoother.cpp:313
virtual ~smootherKLMN()
Definition smoother.hpp:406
A 1st order Low-Pass Filter.
Definition smoother.hpp:67
virtual ~smootherLPF1()
Definition smoother.hpp:74
bool setup(const real_t a=0.9_re)
Setup an initialize the 1st order Low-Pass Filter.
Definition smoother.cpp:18
real_t smooth(const real_t x) override
Perform the smooth operation recursively for the input signal x.
Definition smoother.cpp:30
A 2nd order Low-Pass Filter.
Definition smoother.hpp:96
bool setup(const real_t a=0.9_re)
Setup an initialize the 2nd order Low-Pass Filter.
Definition smoother.cpp:44
real_t smooth(const real_t x) override
Perform the smooth operation recursively for the input signal x.
Definition smoother.cpp:65
virtual ~smootherLPF2()
Definition smoother.hpp:109
A Moving Outlier Removal filter.
Definition smoother.hpp:215
real_t smooth(const real_t x) override
Perform the smooth operation recursively for the input signal x.
Definition smoother.cpp:155
virtual ~smootherMOR1()
Definition smoother.hpp:224
bool setup(real_t *window, const size_t w_size, const real_t a=0.9_re)
Setup an initialize the Moving Outlier Removal filter.
Definition smoother.cpp:139
bool setup(real_t(&window)[windowSize], const real_t a=0.9_re)
Setup an initialize the Moving Outlier Removal filter.
Definition smoother.hpp:244
A Moving Outlier Removal filter.
Definition smoother.hpp:263
real_t smooth(const real_t x) override
Perform the smooth operation recursively for the input signal x.
Definition smoother.cpp:193
bool setup(real_t *window, const size_t w_size, const real_t a=0.9_re)
Setup an initialize the Moving Outlier Removal filter.
Definition smoother.cpp:176
bool setup(real_t(&window)[windowSize], const real_t a=0.9_re)
Setup an initialize the Moving Outlier Removal filter.
Definition smoother.hpp:291
virtual ~smootherMOR2()
Definition smoother.hpp:271
A Moving Window Median filter.
Definition smoother.hpp:132
bool setup(real_t *window, const size_t w_size)
Setup an initialize the Moving Window Median filter.
Definition smoother.cpp:85
virtual ~smootherMWM1()
Definition smoother.hpp:139
real_t smooth(const real_t x) override
Perform the smooth operation recursively for the input signal x.
Definition smoother.cpp:99
bool setup(real_t(&window)[windowSize])
Setup an initialize the Moving Window Median filter.
Definition smoother.hpp:156
A Moving Window Median filter.
Definition smoother.hpp:174
real_t smooth(const real_t x) override
Perform the smooth operation recursively for the input signal x.
Definition smoother.cpp:123
virtual ~smootherMWM2()
Definition smoother.hpp:180
bool setup(real_t *window, const size_t w_size)
Setup an initialize the Moving Window Median filter.
Definition smoother.cpp:110
bool setup(real_t(&window)[windowSize])
Setup an initialize the Moving Window Median filter.
Definition smoother.hpp:197
A Tapped Delay Line (TDL) object.
Definition tdl.hpp:32
The qLibs++ library namespace.
Definition fp16.cpp:4
float real_t
A type to instantiate a real variable double-precision of 64-bits IEEE 754.
Definition qlibs_types.hpp:43