ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
dsps_sfdr_f32.cpp File Reference
#include "dsps_sfdr.h"
#include "dsps_fft2r.h"
#include "dsp_common.h"
#include <math.h>
#include <limits>
#include "esp_log.h"
Include dependency graph for dsps_sfdr_f32.cpp:

Go to the source code of this file.

Functions

float dsps_sfdr_f32 (const float *input, int32_t len, int8_t use_dc)
 SFDR.

Variables

static const char * TAG = "sfdr"

Function Documentation

◆ dsps_sfdr_f32()

float dsps_sfdr_f32 ( const float * input,
int32_t len,
int8_t use_dc )

SFDR.

The function calculates Spurious-Free Dynamic Range. The function makes FFT of the input, then search a spectrum maximum, and then compare maximum value with all others. Result calculated as minimum value. This function have to be used for debug and unit tests only. It's not optimized for real-time processing. The implementation use ANSI C and could be compiled and run on any platform

Parameters
[in]inputinput array.
lenlength of the input signal
use_dcthis parameter define will be DC value used for calculation or not. 0 - SNR will not include DC power 1 - SNR will include DC power
Returns
  • SFDR in DB

Definition at line 24 of file dsps_sfdr_f32.cpp.

25{
26 if (!dsp_is_power_of_two(len)) {
27 return 0;
28 }
29
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;
35 }
37
38 dsps_fft2r_fc32_ansi(temp_array, len);
39 dsps_bit_rev_fc32_ansi(temp_array, len);
40
41 float min = std::numeric_limits<float>::max();
42 float max = std::numeric_limits<float>::min();
43 int max_pos = 0;
44 for (int i = 0 ; i < len / 2 ; i++) {
45 temp_array[i] = 10 * log10f(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) {
47 min = temp_array[i];
48 }
49 if (temp_array[i] > max) {
50 max = temp_array[i];
51 max_pos = i;
52 }
53 ESP_LOGD(TAG, "FFT Data[%i] =%8.4f dB", i, temp_array[i]);
54 }
55 int start_pos = 0;
56 int wind_width = 5;
57 float min_diff = std::numeric_limits<float>::max();
58
59 if (use_dc == 0) {
60 start_pos = wind_width;
61 }
62 for (int i = start_pos ; i < len / 2 ; i++) {
63 if ((i < (max_pos - wind_width)) || (i > (max_pos + wind_width))) {
64 float diff = max - temp_array[i];
65 if (diff < min_diff) {
66 ESP_LOGD(TAG, "FFT Data[%i] =%8.4f dB, maX=%f, max_pos=%i", i, temp_array[i], max, max_pos);
67 min_diff = diff;
68 }
69 }
70 }
71
72 delete[] temp_array;
73 return min_diff;
74}
bool dsp_is_power_of_two(int x)
check power of two The function check if the argument is power of 2. The implementation use ANSI C an...
#define dsps_fft2r_fc32_ansi(data, N)
Definition dsps_fft2r.h:114
#define CONFIG_DSP_MAX_FFT_SIZE
Definition dsps_fft2r.h:24
esp_err_t dsps_fft2r_init_fc32(float *fft_table_buff, int table_size)
init fft tables
esp_err_t dsps_bit_rev_fc32_ansi(float *data, int N)
bit reverse operation for the complex input array
#define M_PI
Definition esp_err.h:26
#define ESP_LOGD
Definition esp_log.h:22
static const char * TAG
Definition main/main.c:31

References CONFIG_DSP_MAX_FFT_SIZE, dsp_is_power_of_two(), dsps_bit_rev_fc32_ansi(), dsps_fft2r_fc32_ansi, dsps_fft2r_init_fc32(), ESP_LOGD, M_PI, and TAG.

Here is the call graph for this function:

Variable Documentation

◆ TAG

const char* TAG = "sfdr"
static

Definition at line 22 of file dsps_sfdr_f32.cpp.