FFT_BUENA

Dependencies:   FastAnalogIn HSI2RGBW_PWM NVIC_set_all_priorities mbed-dsp mbed

Fork of KL25Z_FFT_Demo by Frank Vannieuwkerke

Revision:
3:f826669fc0a8
Parent:
2:035d551759a5
Child:
4:a6130c61c228
--- a/main.cpp	Sat Mar 08 19:30:20 2014 +0000
+++ b/main.cpp	Tue Nov 25 03:49:15 2014 +0000
@@ -12,7 +12,7 @@
 
 Serial pc(USBTX, USBRX);
 
-FastAnalogIn   Audio(PTC2);
+//FastAnalogIn   Audio(PTC2);
 
 //#define RGBW_ext // Disable this line when you want to use the KL25Z on-board RGB LED.
 
@@ -51,7 +51,7 @@
 float SPECTRUM_MAX_DB = 80.0;           // Audio intensity (in decibels) that maps to high LED brightness.
 int LEDS_ENABLED = 1;                   // Control if the LED's should display the spectrum or not.  1 is true, 0 is false.
                                         // Useful for turning the LED display on and off with commands from the serial port.
-const int FFT_SIZE = 64;                // Size of the FFT.
+const int FFT_SIZE = 4096;                // Size of the FFT.
 const int PIXEL_COUNT = 32;             // Number of pixels.  You should be able to increase this without
                                         // any other changes to the program.
 const int MAX_CHARS = 65;               // Max size of the input command buffer
@@ -173,7 +173,7 @@
                    &intensity,
                    &otherMean);
         // Convert intensity to decibels.
-        intensity = 20.0*log10(intensity);
+        intensity = 20.0*log10(intensity);                                                          //Modificar
         // Scale the intensity and clamp between 0 and 1.0.
         intensity -= SPECTRUM_MIN_DB;
         intensity = intensity < 0.0 ? 0.0 : intensity;
@@ -191,7 +191,7 @@
 void samplingCallback()
 {
     // Read from the ADC and store the sample data
-    samples[sampleCounter] = (1023 * Audio) - 511.0f;
+    samples[sampleCounter] = (sampleCounter+1)/2;
     // Complex FFT functions require a coefficient for the imaginary part of the input.
     // Since we only have real data, set this coefficient to zero.
     samples[sampleCounter+1] = 0.0;
@@ -301,7 +301,7 @@
     NVIC_set_all_irq_priorities(1);
     NVIC_SetPriority(UART0_IRQn, 0);
     // Set up serial port.
-    pc.baud (38400);
+    pc.baud (9600);
     pc.attach(&rxisr);
 #ifndef RGBW_ext
     led.invertpwm(1); //On-board KL25Z RGB LED uses common anode.
@@ -350,11 +350,27 @@
     while(1) {
         // Calculate FFT if a full sample is available.
         if (samplingIsDone()) {
+            
+            pc.printf("%f %f %f %f  %f %f %f %f\t%f %f %f %f  %f %f %f %f\n",
+            samples[0], samples[2], samples[4], samples[6],
+            samples[8], samples[10], samples[12], samples[14],
+            samples[16], samples[18], samples[20], samples[22],
+            samples[24], samples[26], samples[28], samples[30]);
+            
+            
             // Run FFT on sample data.
             // Run FFT on sample data.
             arm_cfft_f32(S, samples, 0, 1);
             // Calculate magnitude of complex numbers output by the FFT.
             arm_cmplx_mag_f32(samples, magnitudes, FFT_SIZE);
+            
+            pc.printf("%f %f %f %f  %f %f %f %f\t%f %f %f %f  %f %f %f %f\n\n\n",
+            magnitudes[0], magnitudes[1], magnitudes[2], magnitudes[3],
+            magnitudes[4], magnitudes[5], magnitudes[6], magnitudes[7],
+            magnitudes[8], magnitudes[9], magnitudes[10], magnitudes[11],
+            magnitudes[12], magnitudes[13], magnitudes[14], magnitudes[15]);
+            
+            
 
             if (LEDS_ENABLED == 1) {
                 spectrumLoop();