Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: platform_drivers LTC26X6 AD77681
cn0540_adi_fft.h
00001 /****************************************************************************** 00002 *Copyright (c)2020 Analog Devices, Inc. 00003 * 00004 * Licensed under the 2020-04-27-CN0540EC License(the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * 00007 ****************************************************************************/ 00008 00009 #ifndef CN0540_ADI_FFT_H_ 00010 #define CN0540_ADI_FFT_H_ 00011 00012 #include "stdint.h" 00013 #include "arm_math.h" 00014 #include "stdbool.h" 00015 00016 /** 00017 ****************************************************************************************************************************************************************** 00018 ****************************************************************************************************************************************************************** 00019 * 00020 * MACROS AND CONSTANT DEFINITIONS 00021 */ 00022 00023 #define N_BITS 24 // Define resolution of the ADC 00024 00025 00026 #define SQRT_2 sqrt(2) 00027 #define ADC_FULL_SCALE (1 << N_BITS) // Full scale of the ADC depends on the N_BITS macro, for 24-bit ADC, ADC_FULL_SCALE = 16777216 00028 #define ADC_ZERO_SCALE (1 << (N_BITS - 1)) // Zero scale of the ADC depends on the N_BITS macro, for 24-bit ADC, ADC_ZERO_SCALE = 8388608 00029 00030 #define DC_BINS 10 // Ignoring certain amount of DC bins for for noise and other calculations 00031 #define FUND_BINS 10 // Power spread of the fundamental, 10 bins from either side of the fundamental 00032 #define HARM_BINS 3 // Power spread of the harmonic, 10 bins from either side of the harmonic 00033 00034 00035 /** 00036 ****************************************************************************************************************************************************************** 00037 ****************************************************************************************************************************************************************** 00038 * 00039 * TYPES DECLARATIONS 00040 */ 00041 00042 enum fft_windowing_type 00043 { 00044 BLACKMAN_HARRIS_7TERM, 00045 RECTANGULAR 00046 }; 00047 00048 struct fft_entry // Structure carying all the necessary data, the FFT work with 00049 { 00050 float vref; 00051 uint16_t mclk; 00052 float bin_width; 00053 uint32_t sample_rate; // Sample rate based on MCLK, MCLK_DIV and Digital filter settings 00054 uint16_t fft_length; // Length of fft = sample_count / 2 00055 int32_t codes[4096]; // Codes in range 0 +/- ZERO SCALE 00056 int32_t zero_scale_codes[4096]; // Codes shifted up by ZERO SCALE - range ZERO SCALE +/- ZERO SCALE 00057 float voltage[4096]; // Voltage before windowing 00058 float fft_magnitude[2048]; // Maximum length of FFT magnitude supported by the on-chip DSP = 4096 samples 00059 float fft_magnitude_corrected[2048]; // Maginute with windowing correction 00060 float fft_dB[2048]; // dB fro plot 00061 float fft_input[8192]; // Maximum length of FFT input array supporred by the on-chip DSP = 4096 Real + 4096 Imaginary samples 00062 float noise_bins[2048]; // FFT bins excluding DC, fundamental and Harmonics 00063 enum fft_windowing_type window; // WIndow type 00064 bool fft_done; 00065 }; 00066 00067 struct fft_measurements // Structure carying all the FFT measurements 00068 { 00069 float harmonics_power[6]; // Harmonics, including their power leakage 00070 float harmonics_mag_dbfs[6]; // Harmonic magnitudes for THD 00071 uint16_t harmonics_freq[6]; // Harmonic frequencies for THD 00072 float fundamental; // Fundamental in volts 00073 float pk_spurious_noise; // Peak spurious noise (amplitude) 00074 uint16_t pk_spurious_freq; // Peak Spurious Frequency 00075 float THD; // Total Harmonic Distortion 00076 float SNR; // Signal to Noise Ratio 00077 float DR; // Dynamic Range 00078 float SINAD; // Signal to Noise And Distortion ratio 00079 float SFDR_dbc; // Spurious Free Dynamic Range, dBc 00080 float SFDR_dbfs; // Spurious Free Dynamic Range, dbFS 00081 float ENOB; // ENOB - Effective Number Of Bits 00082 float RMS_noise; // same as transition noise 00083 float average_bin_noise; 00084 float max_amplitude; 00085 float min_amplitude; 00086 float pk_pk_amplitude; 00087 float DC; 00088 float transition_noise; 00089 uint32_t max_amplitude_LSB; 00090 uint32_t min_amplitude_LSB; 00091 uint32_t pk_pk_amplitude_LSB; 00092 int32_t DC_LSB; 00093 float transition_noise_LSB; 00094 }; 00095 00096 /** 00097 ****************************************************************************************************************************************************************** 00098 ****************************************************************************************************************************************************************** 00099 * 00100 * FUNCTION DECLARATIONS 00101 */ 00102 00103 int32_t FFT_init_params(struct fft_entry **fft_entry_init, struct fft_measurements **fft_meas); 00104 void perform_FFT(uint32_t *data, struct fft_entry *fft_data, struct fft_measurements *fft_meas, uint32_t sample_rate); 00105 void FFT_init(uint16_t sample_count, struct fft_entry *fft_data); 00106 void update_FFT_enviroment(uint16_t reference, uint16_t master_clock, uint16_t sampling_rate, struct fft_entry *fft_data); 00107 void static FFT_maginutde_do_dB(struct fft_entry *fft_data, double sum); 00108 void static FFT_calculate_THD(struct fft_entry *fft_data, struct fft_measurements *fft_meas); 00109 void static FFT_calculate_noise(struct fft_entry *fft_data, struct fft_measurements *fft_meas); 00110 float static dbfs_to_volts(float vref, float value); 00111 void static FFT_windowing(struct fft_entry *fft_data, double *sum); 00112 void static FFT_waveform_stat(struct fft_entry *fft_data, struct fft_measurements *fft_meas); 00113 #endif // !ADI_FFT_H_ 00114
Generated on Sun Jul 17 2022 08:53:29 by
1.7.2