// Pretty Good Oscillator // // pretty_good_oscillator // // Pretty Good Oscillator // // // // Inputs: 1 // Outputs: 1 // Constants: 0 #include "ts.h" ts_parameter_t const ts_pretty_good_oscillator_p = { .n_inputs = 1, .n_outputs = 1, .n_constants = 0, .params_size = 0 }; uint_t ts_pretty_good_oscillator_offset( ts_constant_t const *c ) { ( void )c; return ( 0 ); } int ts_pretty_good_oscillator( fp_t * const *y, uint_t y_n, fp_t const * const *x, uint_t x_n, uint_t n, ts_constant_t const *c ) { TS_PROLOGUE( ts_pretty_good_oscillator_p ); (void)c; fp_t ema14 = x[0][0]; fp_t ema30 = x[0][0]; fp_t ema90 = x[0][0]; fp_t a14 = 15.0 / (19.0 * 14); fp_t a30 = 15.0 / (19.0 * 30); fp_t a90 = 15.0 / (19.0 * 90); for( uint_t i = 0; i < n; ++i ) { if( i > 0 ) { ema14 = ema14 + a14 * (x[0][i] - ema14); ema30 = ema30 + a30 * (x[0][i] - ema30); ema90 = ema90 + a90 * (x[0][i] - ema90); } fp_t arr[3] = {ema14, ema30, ema90}; for( uint_t a = 0; a < 2; ++a ) for( uint_t b = a + 1; b < 3; ++b ) if( arr[a] > arr[b] ) { fp_t t = arr[a]; arr[a] = arr[b]; arr[b] = t; } fp_t median = arr[1]; if( median == 0 ) y[0][i] = 0; else y[0][i] = (x[0][i] / median - 1.0); } return 0; }