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.
main.cpp
00001 /****************************************************************************/ 00002 /* FFT d'un signal - Nucleo */ 00003 /****************************************************************************/ 00004 /* LEnsE / Julien VILLEMEJANE / Institut d'Optique Graduate School */ 00005 /****************************************************************************/ 00006 /* Brochage */ 00007 /* TO COMPLETE */ 00008 /****************************************************************************/ 00009 /* Test réalisé sur Nucléo-L476RG */ 00010 /****************************************************************************/ 00011 00012 #include "mbed.h" 00013 #include "arm_math.h" 00014 /* Include mbed-dsp libraries */ 00015 #include "dsp.h" 00016 #include "arm_common_tables.h" 00017 #include "arm_const_structs.h" 00018 00019 #define SAMPLES 512 /* 256 real party and 256 imaginary parts */ 00020 #define FFT_SIZE SAMPLES / 2 /* FFT size is always the same size as we have samples, so 256 in our case */ 00021 00022 float32_t Input[SAMPLES]; 00023 float32_t Output[FFT_SIZE]; 00024 bool trig=0; 00025 int indice = 0; 00026 00027 DigitalOut myled(LED1); 00028 AnalogIn myADC(A0); 00029 AnalogOut myDAC(A2); 00030 Serial pc(USBTX, USBRX); 00031 Ticker timer; 00032 00033 void sample(){ 00034 myled = 1; 00035 if(indice < SAMPLES){ 00036 Input[indice] = myADC.read() - 0.5f; //Real part NB removing DC offset 00037 Input[indice + 1] = 0; //Imaginary Part set to zero 00038 indice += 2; 00039 } 00040 else{ trig = 0; } 00041 myled = 0; 00042 } 00043 00044 int main() { 00045 float maxValue; // Max FFT value is stored here 00046 uint32_t maxIndex; // Index in Output array where max value is 00047 00048 while(1) { 00049 if(trig == 0){ 00050 timer.detach(); 00051 // Init the Complex FFT module, intFlag = 0, doBitReverse = 1 00052 //NB using predefined arm_cfft_sR_f32_lenXXX, in this case XXX is 256 00053 arm_cfft_f32(&arm_cfft_sR_f32_len256, Input, 0, 1); 00054 00055 // Complex Magniture Module put results into Output(Half size of the Input) 00056 arm_cmplx_mag_f32(Input, Output, FFT_SIZE); 00057 Output[0] = 0; 00058 //Calculates maxValue and returns corresponding value 00059 arm_max_f32(Output, FFT_SIZE/2, &maxValue, &maxIndex); 00060 00061 myDAC=1.0; //SYNC Pulse to DAC Output 00062 wait_us(20); //Used on Oscilliscope set trigger level to the highest 00063 myDAC=0.0; //point on this pulse 00064 00065 for(int i=0; i < FFT_SIZE / 2; i++){ 00066 myDAC=(Output[i]) * 0.9; // Scale to Max Value and scale to 90 / 100 00067 wait_us(10); //Each pulse of 10us is 50KHz/256 = 195Hz resolution 00068 } 00069 myDAC=0.0; 00070 pc.printf("MAX = %lf, %d \r\n", maxValue, maxIndex); 00071 wait(0.2); 00072 trig = 1; 00073 indice = 0; 00074 timer.attach_us(&sample,40); //20us 50KHz sampling rate 00075 } 00076 } 00077 }
Generated on Sat Aug 20 2022 17:41:36 by
1.7.2