1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#include <math.h>
#include <stddef.h>
#include "ts.h"
bool ts_test_oscillator_cross( void )
{
/* Data that goes down then up, producing a clear crossover */
fp_t const x[] = { 10, 9, 8, 7, 6, 5, 6, 7, 8, 9 };
fp_t const * const inp[1] = { x };
/* fast=2, slow=4 */
fp_t fast_e = 10, slow_e = 10;
fp_t fast_a = 1.0 / 2, slow_a = 1.0 / 4;
fp_t e[6] = { 0 };
for( uint_t i = 1; i < 10; ++i )
{
fp_t pf = fast_e, ps = slow_e;
fast_e = fast_e + fast_a * ( x[i] - fast_e );
slow_e = slow_e + slow_a * ( x[i] - slow_e );
if( i >= 4 )
{
if( fast_e > slow_e && pf <= ps )
e[i - 4] = 1;
else if( fast_e < slow_e && pf >= ps )
e[i - 4] = -1;
else
e[i - 4] = 0;
}
}
fp_t const * const exp[1] = { e };
typedef struct { fp_t fast; fp_t slow; } c_t;
c_t c = { .fast = 2, .slow = 4 };
return ts_test(ts_oscillator_cross, ts_oscillator_cross_offset, inp, exp, sizeof( x ) / sizeof( *x ), (ts_constant_t *)&c, &ts_oscillator_cross_p);
}
|