diff options
Diffstat (limited to 'test/t3.c')
| -rw-r--r-- | test/t3.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/t3.c b/test/t3.c new file mode 100644 index 0000000..7ef7e8e --- /dev/null +++ b/test/t3.c @@ -0,0 +1,29 @@ +#include <stddef.h> +#include "ts.h" + +bool ts_test_t3( void ) +{ + fp_t const x0[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + uint_t n = sizeof( x0 ) / sizeof( *x0 ); + + // T3 uses hardcoded k=5, b=0.7 + fp_t alpha = 2.0 / 6.0; + fp_t c3 = 0.7, c3m1 = -0.3, c3m2 = -1.3, c3m3 = -2.3; + fp_t w3 = c3, w2 = -3.0 * c3m1, w1 = 3.0 * c3m1 * c3m2, w0 = -c3m1 * c3m2 * c3m3; + + fp_t e0[10]; + fp_t ema1 = x0[0], ema2 = x0[0], ema3 = x0[0]; + e0[0] = x0[0]; + for ( uint_t i = 1; i < n; ++i ) + { + ema1 = ema1 + alpha * ( x0[i] - ema1 ); + ema2 = ema2 + alpha * ( ema1 - ema2 ); + ema3 = ema3 + alpha * ( ema2 - ema3 ); + e0[i] = w3 * ema3 + w2 * ema2 + w1 * ema1 + w0 * x0[i]; + } + + fp_t const * const x[] = { x0 }; + fp_t const * const e[] = { e0 }; + + return ts_test(ts_t3, ts_t3_offset, x, e, n, (ts_constant_t *)NULL, &ts_t3_p); +} |