si jala

Dependencies:   FastAnalogIn NVIC_set_all_priorities mbed-dsp mbed

Fork of KL25Z_FFT_Demo_tony by Luis Daniel Castillo

Files at this revision

API Documentation at this revision

Comitter:
hermes_3673
Date:
Wed Nov 16 19:48:10 2016 +0000
Parent:
2:177596541c8d
Commit message:
se la come;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 177596541c8d -r 1c6625b2d363 main.cpp
--- a/main.cpp	Tue Nov 15 23:04:41 2016 +0000
+++ b/main.cpp	Wed Nov 16 19:48:10 2016 +0000
@@ -48,7 +48,7 @@
                                         // A value >= 1000 and <= 1000 + PIXEL_COUNT fixes the output to a single frequency
                                         // window = a single color.
 int SAMPLE_RATE_HZ = 1000;             // Sample rate of the audio in hertz.
-
+float freq=0;
                                         // Useful for turning the LED display on and off with commands from the serial port.
 const int FFT_SIZE = 256;                // Size of the FFT.
 
@@ -61,9 +61,10 @@
 float samples[FFT_SIZE*2];
 float magnitudes[FFT_SIZE];
 int sampleCounter = 0;
-
 int maxFrequencyValue = 0;
-
+float maxValue=0.0;
+int posicion=0;
+int counter=0;
 int FFTFrequency = 0;
 
 // Convert a frequency to the appropriate FFT bin it will fall within.
@@ -108,33 +109,6 @@
 ////////////////////////////////////////////////////////////////////////////////
 // FREQUENCY 
 ////////////////////////////////////////////////////////////////////////////////
-
-
-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;
-        }
-    }
-    
-    return arrayPosition;
-}
-
-int get_FFTFrequency()
-{
-    maxFrequencyValue = SAMPLE_RATE_HZ/2;
-    
-    set_ArrayPosition();
-    
-    return (maxFrequencyValue*sarrayPosition)/(FFT_SIZE-1);
-    
-}
 ////////////////////////////////////////////////////////////////////////////////
 // MAIN FUNCTION
 ////////////////////////////////////////////////////////////////////////////////
@@ -187,12 +161,62 @@
             // Calculate magnitude of complex numbers output by the FFT.
             arm_cmplx_mag_f32(samples, magnitudes, FFT_SIZE);
             //Obtaining the value of the frequency 
-            FFTFrequency = get_FFTFrequency();
-            
+            posicion=0;
+            counter=0;
+            maxValue=0.0;
+            do{
+                counter++;
+                if(magnitudes[counter]>maxValue){
+                    maxValue=magnitudes[counter];
+                    posicion=counter;
+                    }
+
+                }while(counter<256);
             
             // Restart audio sampling.
             samplingBegin();
-        } 
+        }
+        freq=(float) posicion;
+        freq=freq*3.906;
+        if(78<freq )
+        {
+            if(freq<85){
+                printf("cuerda 6 freq : %f \n\r",freq);
+                }
+        }
+        if(107<freq )
+        {
+            if(freq<113){
+                printf("cuerda 5 freq  :%f  \n\r",freq);
+                }
+        }
+        if(142<freq )
+        {
+            if(freq<150){
+                printf("cuerda 4 freq  :%f  \n\r",freq);
+                }
+        }
+        if(192<freq )
+        {
+            if(freq<198){
+                printf("cuerda 3 freq  :%f  \n\r",freq);
+                }
+        }
+        if(243<freq )
+        {
+            if(freq<250){
+                printf("cuerda 2 freq  :%f  \n\r",freq);
+                }
+        }
+        if(327<freq )
+        {
+            if(freq<335){
+                printf("cuerda 1 freq  :%f  \n\r",freq);
+                }
+        }
+        
+
+        
     }
     
 }