#include #include #include #include #include "freq_meas.h" #include "sr_global.h" /* FTT window lookup table defined in generated/fmeas_fft_window.c */ extern const float * const fmeas_fft_window_table; /* jury-rig some definitions for these functions since the ARM headers only export an over-generalized variable bin size * variant. */ extern arm_status arm_rfft_32_fast_init_f32(arm_rfft_fast_instance_f32 * S); extern arm_status arm_rfft_64_fast_init_f32(arm_rfft_fast_instance_f32 * S); extern arm_status arm_rfft_128_fast_init_f32(arm_rfft_fast_instance_f32 * S); extern arm_status arm_rfft_256_fast_init_f32(arm_rfft_fast_instance_f32 * S); extern arm_status arm_rfft_512_fast_init_f32(arm_rfft_fast_instance_f32 * S); extern arm_status arm_rfft_1024_fast_init_f32(arm_rfft_fast_instance_f32 * S); extern arm_status arm_rfft_2048_fast_init_f32(arm_rfft_fast_instance_f32 * S); extern arm_status arm_rfft_4096_fast_init_f32(arm_rfft_fast_instance_f32 * S); #define CONCAT(A, B, C) A ## B ## C #define arm_rfft_init_name(nbits) CONCAT(arm_rfft_, nbits, _fast_init_f32) void func_gauss_grad(float *out, float *params, int x, void *userdata); float func_gauss(float *params, int x, void *userdata); int adc_buf_measure_freq(uint16_t adc_buf[FMEAS_FFT_LEN], float *out) { int rc; float in_buf[FMEAS_FFT_LEN]; float out_buf[FMEAS_FFT_LEN]; for (size_t i=0; i a_max) { a_max = out_buf[i]; i_max = i; } } float par[3] = { a_max, i_max, 1.0f }; if (levmarq(3, par, nbins, out_buf, NULL, func_gauss, func_gauss_grad, NULL, &lmstat)) return -1; *out = (par[1] + first_bin) * binsize_hz; return 0; } float func_gauss(float *params, int x, void *userdata) { UNUSED(userdata); float a = params[0]; float mu = params[1]; float sigma = params[2]; return a*expf(-powf((x-mu), 2.0f/(2.0f*(sigma*sigma)))); } void func_gauss_grad(float *out, float *params, int x, void *userdata) { UNUSED(userdata); float a = params[0]; float mu = params[1]; float sigma = params[2]; *out = -(x-mu) / ( sigma*sigma*sigma * 2.5066282746310002f) * a*expf(-powf((x-mu), 2.0f/(2.0f*(sigma*sigma)))); }