/* * afsk_demodulator.c * * Created on: Sep 10, 2019 * Author: curiousmuch */ #include "stdio.h" #include "stdint.h" #include "math.h" #include "afsk_demodulator.h" /* Public Variables */ int8_t window[WINDOW_SIZE]; // sliding window float coeff0 = 0, coeff1 = 0; // goerztel coefficients float lpf_coef0[5], lpf_coef1[5]; // lpf coefficients float lpf_delay0[2], lpf_delay1[2]; // lpf delay line int raw_bit = 0; // afsk demodulator result /* Private Functions */ void goertzel_init(float freq0, float freq1, float *coeff0, float *coeff1) { float normalizedfreq; // calculate coeff0 normalizedfreq = freq0 / SAMPLEFREQUENCY; *coeff0 = (float) 2*cos(2*M_PI*normalizedfreq); // calculate coeff1 normalizedfreq = freq1 / SAMPLEFREQUENCY; *coeff1 = (float) 2*cos(2*M_PI*normalizedfreq); } float goertzel_filter(int8_t samples[], float coeff, unsigned int N) { float s_prev = 0.0; float s_prev2 = 0.0; float power, s; unsigned int i; for (i=0; i THRESHOLD) { raw_bit = 1; //enable_debug_IO(DEBUG_2); } else if (lpf_output < THRESHOLD) { raw_bit = 0; //disable_debug_IO(DEBUG_2); } return raw_bit; // if not above threshold keep old state. }