precision-converters-firmware
adi_fft.h
Go to the documentation of this file.
1 /*************************************************************************/
13 #ifndef _ADI_FFT_H_
14 #define _ADI_FFT_H_
15 
16 /******************************************************************************/
17 /***************************** Include Files **********************************/
18 /******************************************************************************/
19 
20 #include <stdint.h>
21 #include <stdbool.h>
22 #include "adi_fft_windowing.h"
23 
24 /******************************************************************************/
25 /************************ Macros/Constants ************************************/
26 /******************************************************************************/
27 
28 /* Maximum number of default samples used for FFT analysis (must be <=2048)
29  * FFT length = FFT samples. FFT length(samples) are supported only as power of 2
30  * e.g. 512, 1024, 2048
31  * */
32 #if !defined(ADI_FFT_MAX_SAMPLES)
33 #define ADI_FFT_MAX_SAMPLES 2048
34 #endif
35 
36 /******************************************************************************/
37 /************************ Public Declarations *********************************/
38 /******************************************************************************/
39 
40 typedef float(*adi_fft_data_to_volt_conv)(int32_t, uint8_t);
41 typedef int32_t(*adi_fft_code_to_straight_bin_conv)(uint32_t, uint8_t);
42 
43 /* FFT windowing type */
47 };
48 
49 /* FFT init parameters specific to device */
51  /* Device reference voltage */
52  float vref;
53  /* Device sample rate */
54  uint32_t sample_rate;
55  /* Samples count */
56  uint16_t samples_count;
57  /* Input data full scale value */
59  /* Input data zero scale value */
61  /* Convert input data to voltage without respect to vref */
63  /* Convert input data to voltage with respect to vref */
65  /* Convert code to straight binary data */
67 };
68 
69 /* FFT processing parameters */
71  /* Device reference voltage */
72  float vref;
73  /* Device sample rate */
74  uint32_t sample_rate;
75  /* Input data full scale value */
77  /* Input data zero scale value */
79  /* Convert input data to voltage without respect to vref */
81  /* Convert input data to voltage with respect to vref */
83  /* Convert code to straight binary data */
85  /* FFT length */
86  uint16_t fft_length;
87  /* FFT bin width */
88  float bin_width;
89  /* Input data (unformatted/straight binary for ADCs) */
91  /* Maximum length of FFT magnitude */
93  /* Magnitude with windowing correction */
95  /* FFT effective gain */
97  /* Maximum length of FFT input array supporred - Real + Imaginary components */
99  /* FFT bins excluding DC, fundamental and Harmonics */
101  /* FFT window type */
103  /* FFT done status */
104  bool fft_done;
105 };
106 
107 /* FFT meausurement parameters */
109  /* Harmonics, including their power leakage */
111  /* Harmonic magnitudes for THD */
113  /* Harmonic frequencies for THD */
115  /* Fundamental in volts */
116  float fundamental;
117  /* Peak spurious noise (amplitude) */
119  /* Peak Spurious Frequency */
121  /* Total Harmonic Distortion */
122  float THD;
123  /* Signal to Noise Ratio */
124  float SNR;
125  /* Dynamic Range */
126  float DR;
127  /* Signal to Noise And Distortion ratio */
128  float SINAD;
129  /* Spurious Free Dynamic Range, dBc */
130  float SFDR_dbc;
131  /* Spurious Free Dynamic Range, dbFS */
132  float SFDR_dbfs;
133  /* ENOB - Effective Number Of Bits */
134  float ENOB;
135  /* RMS noise */
136  float RMS_noise;
138  /* Maximum amplitude in volts */
140  /* Minimum amplitude in volts */
142  /* Peak to Peak amplitude in volts */
144  /* DC bias in volts */
145  float DC;
146  /* Transition noise */
148  /* Maximum amplitude in LSB */
150  /* Minimum amplitude in LSB */
152  /* Peak to Peak amplitude in LSB */
154  /* DC bias in LSB */
155  int32_t DC_LSB;
156  /* Transition noise in LSB */
158 };
159 
160 int adi_fft_init(struct adi_fft_init_params *param,
161  struct adi_fft_processing *fft_proc,
162  struct adi_fft_measurements *fft_meas);
164  struct adi_fft_processing *fft_proc);
165 int adi_fft_perform(struct adi_fft_processing *fft_proc,
166  struct adi_fft_measurements *fft_meas);
167 
168 #endif // !_ADI_FFT_H_
adi_fft_windowing_type
Definition: adi_fft.h:44
@ RECTANGULAR
Definition: adi_fft.h:46
@ BLACKMAN_HARRIS_7TERM
Definition: adi_fft.h:45
float(* adi_fft_data_to_volt_conv)(int32_t, uint8_t)
Definition: adi_fft.h:40
int adi_fft_init(struct adi_fft_init_params *param, struct adi_fft_processing *fft_proc, struct adi_fft_measurements *fft_meas)
Initialize the FFT structure.
Definition: adi_fft.c:54
#define ADI_FFT_MAX_SAMPLES
Definition: adi_fft.h:33
int32_t(* adi_fft_code_to_straight_bin_conv)(uint32_t, uint8_t)
Definition: adi_fft.h:41
int adi_fft_perform(struct adi_fft_processing *fft_proc, struct adi_fft_measurements *fft_meas)
Perform the FFT.
Definition: adi_fft.c:558
int adi_fft_update_params(struct adi_fft_init_params *param, struct adi_fft_processing *fft_proc)
Update the FFT parameters.
Definition: adi_fft.c:115
FFT windowing functionality headers.
#define ADI_FFT_NUM_OF_TERMS
Definition: adi_fft_windowing.h:26
Definition: adi_fft.h:50
float vref
Definition: adi_fft.h:52
adi_fft_data_to_volt_conv convert_data_to_volt_without_vref
Definition: adi_fft.h:62
int32_t input_data_full_scale
Definition: adi_fft.h:58
uint16_t samples_count
Definition: adi_fft.h:56
adi_fft_data_to_volt_conv convert_data_to_volt_wrt_vref
Definition: adi_fft.h:64
uint32_t sample_rate
Definition: adi_fft.h:54
adi_fft_code_to_straight_bin_conv convert_code_to_straight_binary
Definition: adi_fft.h:66
int32_t input_data_zero_scale
Definition: adi_fft.h:60
Definition: adi_fft.h:108
uint16_t harmonics_freq[ADI_FFT_NUM_OF_TERMS]
Definition: adi_fft.h:114
uint32_t max_amplitude_LSB
Definition: adi_fft.h:149
float DC
Definition: adi_fft.h:145
float average_bin_noise
Definition: adi_fft.h:137
float max_amplitude
Definition: adi_fft.h:139
int32_t DC_LSB
Definition: adi_fft.h:155
float SFDR_dbc
Definition: adi_fft.h:130
float SNR
Definition: adi_fft.h:124
uint32_t min_amplitude_LSB
Definition: adi_fft.h:151
float pk_spurious_noise
Definition: adi_fft.h:118
float transition_noise_LSB
Definition: adi_fft.h:157
float pk_pk_amplitude
Definition: adi_fft.h:143
float THD
Definition: adi_fft.h:122
uint32_t pk_pk_amplitude_LSB
Definition: adi_fft.h:153
float min_amplitude
Definition: adi_fft.h:141
float SFDR_dbfs
Definition: adi_fft.h:132
float SINAD
Definition: adi_fft.h:128
float fundamental
Definition: adi_fft.h:116
float ENOB
Definition: adi_fft.h:134
float RMS_noise
Definition: adi_fft.h:136
float DR
Definition: adi_fft.h:126
float harmonics_power[ADI_FFT_NUM_OF_TERMS]
Definition: adi_fft.h:110
float transition_noise
Definition: adi_fft.h:147
uint16_t pk_spurious_freq
Definition: adi_fft.h:120
float harmonics_mag_dbfs[ADI_FFT_NUM_OF_TERMS]
Definition: adi_fft.h:112
Definition: adi_fft.h:70
enum adi_fft_windowing_type window
Definition: adi_fft.h:102
float bin_width
Definition: adi_fft.h:88
adi_fft_data_to_volt_conv cnv_data_to_volt_without_vref
Definition: adi_fft.h:80
int32_t input_data_zero_scale
Definition: adi_fft.h:78
float fft_magnitude[ADI_FFT_MAX_SAMPLES/2]
Definition: adi_fft.h:92
float fft_magnitude_corrected[ADI_FFT_MAX_SAMPLES/2]
Definition: adi_fft.h:94
float vref
Definition: adi_fft.h:72
float noise_bins[ADI_FFT_MAX_SAMPLES/2]
Definition: adi_fft.h:100
adi_fft_code_to_straight_bin_conv cnv_code_to_straight_binary
Definition: adi_fft.h:84
bool fft_done
Definition: adi_fft.h:104
int32_t input_data[ADI_FFT_MAX_SAMPLES]
Definition: adi_fft.h:90
float fft_dB[ADI_FFT_MAX_SAMPLES/2]
Definition: adi_fft.h:96
uint16_t fft_length
Definition: adi_fft.h:86
float fft_input[ADI_FFT_MAX_SAMPLES *2]
Definition: adi_fft.h:98
uint32_t sample_rate
Definition: adi_fft.h:74
int32_t input_data_full_scale
Definition: adi_fft.h:76
adi_fft_data_to_volt_conv cnv_data_to_volt_wrt_vref
Definition: adi_fft.h:82