30 float *temp_array =
new float[len * 2];
31 for (
int i = 0 ; i < len ; i++) {
32 float wind = 0.5 * (1 - cosf(i * 2 *
M_PI / (
float)len));
33 temp_array[i * 2 + 0] = input[i] * wind;
34 temp_array[i * 2 + 1] = 0;
41 float min = std::numeric_limits<float>::max();
42 float max = std::numeric_limits<float>::min();
44 for (
int i = 0 ; i < len / 2 ; i++) {
45 temp_array[i] = temp_array[i * 2 + 0] * temp_array[i * 2 + 0] + temp_array[i * 2 + 1] * temp_array[i * 2 + 1];
46 if (temp_array[i] < min) {
49 if (temp_array[i] > max) {
53 ESP_LOGD(
TAG,
"FFT Data[%i] =%8.4f dB", i, temp_array[i]);
59 start_pos = wind_width;
61 float noise_power = 0;
62 for (
int i = start_pos ; i < len / 2 ; i++) {
63 if ((i < (max_pos - wind_width)) || (i > (max_pos + wind_width))) {
64 noise_power += temp_array[i];
65 ESP_LOGD(
TAG,
"FFT Data[%i] =%8.4f dB, maX=%f, max_pos=%i, noise_power=%f", i, temp_array[i], max, max_pos, noise_power);
70 noise_power += std::numeric_limits<float>::min();
71 if (noise_power < max * 0.00000000001) {
74 float snr = max / noise_power;
75 float result = 10 * log10(max / noise_power) - 2;
76 ESP_LOGI(
TAG,
"SNR = %f, result=%f dB", snr, result);