#include "stm32f10x.h"

/**
 * Size of the FFT output spectrum (unsymetrized). Note that the 
 * allocated buffers have twice the size because the spectrum is
 * symetrized (-fs/2 to fs/2).
 */
#define FFT_LENGTH 1024

/**
 * Length of the moving average to filter frequencies.
 */
#define AVERAGE_LENGTH 2

/**
 * Timeout after number of inconsistent frequency values average
 * goes to zero.
 */
#define OUTBAND_TIMEOUT 4

/**
 * Valid band lower limit (Hz).
 */
#define LOWBAND_LIMIT 10

/**
 * Valid band upper limit (Hz).
 */
#define HIGHBAND_LIMIT 10000


u32* compute_fft(u32* samples);
u16 fundamental_frequency(u32* sprectrum, u16 sampling_rate);
bool is_valid(u16 frequency);
void init_average();
u16 moving_average(u16 value);