Simplified version of FFT code - drives on-board LED as a "Colour Organ".

Dependencies:   FastAnalogIn NVIC_set_all_priorities mbed-dsp mbed

Fork of KL25Z_FFT_Demo_tony by Tony Abbey

Files at this revision

API Documentation at this revision

Comitter:
luisda130595
Date:
Tue Nov 15 23:04:41 2016 +0000
Parent:
1:7421267b0777
Commit message:
Pa' Chuy

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 7421267b0777 -r 177596541c8d main.cpp
--- a/main.cpp	Tue Nov 15 22:16:24 2016 +0000
+++ b/main.cpp	Tue Nov 15 23:04:41 2016 +0000
@@ -62,10 +62,9 @@
 float magnitudes[FFT_SIZE];
 int sampleCounter = 0;
 
-int arrayPosition;
-int maxFrequencyValue;
+int maxFrequencyValue = 0;
 
-int FFTFrequency;
+int FFTFrequency = 0;
 
 // Convert a frequency to the appropriate FFT bin it will fall within.
 int frequencyToBin(float frequency)
@@ -111,17 +110,20 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 
-void set_ArrayPosition()
+int set_ArrayPosition()
 {
     float maxValue = 0.0;
-    
+    int arrayPosition = 0;  
+      
     for(int counter=0; counter < FFT_SIZE; counter++)
     {
         if(magnitudes[counter] > maxValue){
             maxValue = magnitudes[counter];
-            arrayPosition = counter+1;
+            arrayPosition = counter;
         }
     }
+    
+    return arrayPosition;
 }
 
 int get_FFTFrequency()
@@ -130,7 +132,7 @@
     
     set_ArrayPosition();
     
-    return (maxFrequencyValue*arrayPosition)/FFT_SIZE;
+    return (maxFrequencyValue*sarrayPosition)/(FFT_SIZE-1);
     
 }
 ////////////////////////////////////////////////////////////////////////////////
@@ -187,9 +189,6 @@
             //Obtaining the value of the frequency 
             FFTFrequency = get_FFTFrequency();
             
-            for(int i=0; 
-            pc.printf("Frequency is: ", FFTFrequency);
-            pc.printf("\r\n [");
             
             // Restart audio sampling.
             samplingBegin();