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: UIT_FFT_Real_mod mbed
Fork of Demo_FFT_IFFT by
main.cpp
00001 //-------------------------------------------------------------- 00002 /** 00003 * FFT experiment for LPC1114FN28 00004 * 00005 * programed by Takehisa Oneta(ohneta) 00006 * Aug. 2015 00007 */ 00008 //-------------------------------------------------------------- 00009 00010 #include "fftReal.hpp" 00011 #include "mbed.h" 00012 00013 #define SAMPLING_NUM 64 00014 //#define SAMPLING_NUM 32 00015 //-------------------------------------------------------------- 00016 00017 Serial pc(USBTX, USBRX); 00018 AnalogIn ainR(dp9); 00019 AnalogIn ainL(dp10); 00020 Ticker soundInterrupt; 00021 00022 const char *gBarGraf[] = { 00023 " ", 00024 "* ", 00025 "** ", 00026 "*** ", 00027 "**** ", 00028 "***** ", 00029 "****** ", 00030 "******* ", 00031 "******** ", 00032 "********* ", 00033 "********** ", 00034 "*********** ", 00035 "************ ", 00036 "************* ", 00037 "************** ", 00038 "*************** ", 00039 "**************** ", 00040 "***************** ", 00041 "****************** ", 00042 "******************* ", 00043 "******************** ", 00044 "********************* ", 00045 "********************** ", 00046 "*********************** ", 00047 "************************ ", 00048 "************************* ", 00049 "************************** ", 00050 "*************************** ", 00051 "**************************** ", 00052 "***************************** ", 00053 "****************************** ", 00054 "*******************************", 00055 }; 00056 00057 //-------------------------------------------------------------- 00058 00059 00060 uint32_t gSoundIntrFlag = 0; 00061 uint32_t gSoundIntrCount = 0; 00062 00063 float gBufferR[SAMPLING_NUM]; 00064 float gBufferL[SAMPLING_NUM]; 00065 00066 //---------------------------------------------------- 00067 /** 00068 * Ticker handler 00069 */ 00070 void soundInterruptHandle() 00071 { 00072 if (gSoundIntrFlag == 0) { 00073 gSoundIntrFlag = 1; 00074 } 00075 } 00076 00077 //---------------------------------------------------- 00078 00079 int main() 00080 { 00081 pc.baud(115200); 00082 00083 Complex y1[SAMPLING_NUM / 2 + 1]; 00084 Complex y2[SAMPLING_NUM / 2 + 1]; 00085 00086 pc.printf("### START \n"); 00087 00088 gSoundIntrFlag = 0; 00089 gSoundIntrCount = 0; 00090 uint32_t intr_us = 25; // 00091 soundInterrupt.attach_us(&soundInterruptHandle, intr_us); 00092 00093 float dd = 20.0f; 00094 00095 FftReal fft(SAMPLING_NUM); 00096 while (1) { 00097 00098 if (gSoundIntrFlag == 1) { 00099 float r = ainR; 00100 float l = ainL; 00101 00102 //pc.printf("*** [%02d] = %8.4f : %8.4f \n", gSoundIntrCount, r, l); 00103 00104 gBufferR[gSoundIntrCount] = r * dd - 1.0f; 00105 if (gBufferR[gSoundIntrCount] < -1.0f) { 00106 gBufferR[gSoundIntrCount] = -1.0f; 00107 } else if (gBufferR[gSoundIntrCount] > 1.0f) { 00108 gBufferR[gSoundIntrCount] = 1.0f; 00109 } 00110 gBufferL[gSoundIntrCount] = l * dd - 1.0f; 00111 if (gBufferL[gSoundIntrCount] < -1.0f) { 00112 gBufferL[gSoundIntrCount] = -1.0f; 00113 } else if (gBufferL[gSoundIntrCount] > 1.0f) { 00114 gBufferL[gSoundIntrCount] = 1.0f; 00115 } 00116 //pc.printf("*** [%02d] = %2.4f : %2.4f : %2.4f : %2.4f \n", gSoundIntrCount, r, l, gBufferR[gSoundIntrCount], gBufferL[gSoundIntrCount]); 00117 //pc.printf("\n"); 00118 00119 gSoundIntrCount++; 00120 if (gSoundIntrCount >= SAMPLING_NUM) { 00121 gSoundIntrCount = 0; 00122 00123 fft.Execute(gBufferR, y1); 00124 fft.Execute(gBufferL, y2); 00125 00126 //pc.printf("%c[2J%c[;H", 27, 27); 00127 pc.printf("%c[%c;%cH", 27, 0, 0); 00128 //pc.printf("%c[;H", 27); 00129 00130 00131 pc.printf(" [Right] [Left]\r\n"); 00132 for (int n = 0; n <= (SAMPLING_NUM / 2); n++) { 00133 uint32_t dtR = (uint32_t)abs(y1[n]); 00134 if (dtR >= (SAMPLING_NUM / 2)) { 00135 dtR = 15; 00136 } 00137 00138 uint32_t dtL = (uint32_t)abs(y2[n]); 00139 if (dtL >= (SAMPLING_NUM / 2)) { 00140 dtL = 15; 00141 } 00142 00143 pc.printf("%2d: %s : %s\r\n", n, gBarGraf[dtR], gBarGraf[dtL]); 00144 } 00145 00146 } 00147 gSoundIntrFlag = 0; 00148 } 00149 } 00150 00151 } 00152 00153 //----------------------------------------------------
Generated on Sat Jul 23 2022 12:34:24 by
1.7.2
