Audio Spectrum Analyzer (FFT 32 points and LCD 20x4)
Nothing special, an example for using the library of FFT, Audio Spectrum Analyzer with LCD:
Import program
00001 // Nothing special, an example for using the library of FFT, Audio Spectrum Analyzer with LCD 00002 #include "mbed.h" 00003 #include "FFT.h" 00004 #include "LCD_Serial.h" 00005 // ********************************************************************************************** 00006 #define N 32 00007 float Data[N*2]; 00008 unsigned char PowerInt[N/2]; 00009 volatile int kbhit; 00010 float Average; 00011 00012 AnalogIn ChannelR(p16); 00013 AnalogIn ChannelL(p17); 00014 AnalogIn ChannelC(p18); 00015 LCDSerial myLcd(p21,p22,p23,p24); // Data, Clock, Enable, Back 00016 // ********************************************************************************************** 00017 void vUpdateDataAnalogs(float Analogs[]); 00018 void vGraphicDisplay(unsigned char *Data); 00019 // ********************************************************************************************** 00020 int main() { 00021 myLcd.vSetBacklight(1); 00022 myLcd.printf("\f FFT with mbed!!!"); 00023 wait(2.0); 00024 myLcd.printf("\f"); 00025 00026 Average=0; 00027 for(int k=0;k<64;k++){ 00028 Average+=ChannelC.read_u16(); 00029 wait_us(100); 00030 } 00031 Average/=64; 00032 00033 while(1){ 00034 vUpdateDataAnalogs(Data); 00035 vFFT(Data-1,N); 00036 vCalPowerInt(Data,PowerInt,N/2); 00037 vGraphicDisplay(PowerInt); 00038 wait_ms(30); 00039 } 00040 } 00041 // ********************************************************************************************** 00042 void vUpdate(void){ 00043 kbhit=1; 00044 } 00045 void vUpdateDataAnalogs(float Analogs[]){ 00046 unsigned short TempReadR[32],TempReadL[32]; 00047 Ticker Period; 00048 00049 kbhit=0; 00050 Period.attach_us(&vUpdate,25); // 25 us, 40.000 Hz 00051 for(int k=0;k<32;k++){ 00052 while(kbhit==0); 00053 kbhit=0; 00054 TempReadR[k]=ChannelR.read_u16(); 00055 } 00056 for(int k=0;k<32;k++){ 00057 while(kbhit==0); 00058 kbhit=0; 00059 TempReadL[k]=ChannelL.read_u16(); 00060 } 00061 Period.detach(); 00062 for(int k=0,j=0;k<32;k++,j++){ 00063 Analogs[j]=(TempReadR[k]+TempReadL[k])/2; // Promedio (x1[n]+x2[n]=X1[k]+X2[k]) 00064 Analogs[j]=((float)(Analogs[j]-Average)/10); // Desplazo y aplico escala.- 00065 Analogs[++j]=0; 00066 } 00067 return; 00068 } 00069 // ********************************************************************************************** 00070 void vGraphicDisplay(unsigned char *Data){ 00071 unsigned char k; 00072 00073 myLcd.vGotoxy(3,1); 00074 for(k=0;k<16;k++,Data++){ 00075 if(*Data>192){myLcd.vPutc((*Data-193)/8);}else{myLcd.vPutc(' ');} 00076 } 00077 myLcd.vGotoxy(3,2); 00078 Data-=16; 00079 for(k=0;k<16;k++,Data++){ 00080 if((*Data>128)&&(*Data<193)){myLcd.vPutc((*Data-129)/8);}else if(*Data>192){myLcd.vPutc(0x07);}else{myLcd.vPutc(' ');} 00081 } 00082 myLcd.vGotoxy(3,3); 00083 Data-=16; 00084 for(k=0;k<16;k++,Data++){ 00085 if((*Data>64)&&(*Data<129)){myLcd.vPutc((*Data-65)/8);}else if(*Data>128){myLcd.vPutc(0x07);}else{myLcd.vPutc(' ');} 00086 } 00087 myLcd.vGotoxy(3,4); 00088 Data-=16; 00089 for(k=0;k<16;k++,Data++){ 00090 if((*Data>0)&&(*Data<65)){myLcd.vPutc((*Data-1)/8);}else if(*Data>64){myLcd.vPutc(0x07);}else{myLcd.vPutc(' ');} 00091 } 00092 00093 }
Import programFFT_Example
Example Audio Spectrum Analyzer
Import libraryFFT
FFT, Audio, Spectrum, Analyzer
8 comments on Audio Spectrum Analyzer (FFT 32 points and LCD 20x4):
Please log in to post comments.
This is a very great project, thanks for posting it!
I have a question about your analog input stage... doesn't it harm the op-amps when the incoming analog audio signal is constantly dropping below 0V (since it is beyond the "negative" rail, which in your design is 0V?).
Will this circuit perhaps degrade over time? Sorry if this seems like a beginner question, I just thought that normally the signal should be rectified first... (I am a beginner in analog design)
Thanks again!