help :(

Dependencies:   FFT

Revision:
3:3dbf078989b1
Parent:
2:a6e81c45ef48
Child:
4:7974ef1b1e07
Child:
6:d311a95f1e9b
--- a/main.cpp	Thu Dec 03 00:33:19 2020 +0000
+++ b/main.cpp	Thu Dec 03 05:07:27 2020 +0000
@@ -17,23 +17,7 @@
 DigitalOut myled(LED1); // mbed LED
 Serial pc (USBTX,USBRX);
 
-#define BUFFER_SIZE 50
-
-// delete later
-/*int sample[12][8] = {
- 34085,32666,29810,29823,27514,24175,24468,32559, 
- 36401,33075,29037,21933,20189,21751,20975,20087, 
- 17530,27723,30891,21128,19982,15446,12413,13597, 
- 15776,14233,15622,16334,15485,17136,16389,17954, 
- 20349,18486,23377,34447,34400,34681,33107,31171, 
- 30007,33640,37007,38136,39187,38169,51831,52041, 
- 47831,48634,44189,43878,44743,46468,43170,47172, 
- 53518,52294,54825,51992,49619,48147,47901,48413, 
- 46049,49090,47590,46154,45423,41223,41782,54695, 
- 57452,51210,52462,59096,56711,52268,49364,42865, 
- 41483,37964,39215,35908,31570,28332,24492,23121, 
- 22874,18154,15541,15263,12463,12198,13301,9951
-};*/
+#define BUFFER_SIZE 64
 
 // states for display output
 const int on[8][8] =
@@ -88,18 +72,24 @@
 
 
 
-void display_fft(int sample[]) {
+void display_fft(float sample[]) {
     
     int state = 0;
-    int freq = 0;
+    float freq = 0;
     matrix.begin(0x70);
     
-        for (int a = 0; a < 50; a++) {
+    int s = sizeof(sample);
+    
+    pc.printf("%d\n", s);
+    
+    for (int a = 0; a < 64; a++) {
             
-            freq = sample[a];
+        freq = sample[a];
+        
+        pc.printf("%d\n",freq);
         
         // determine state based on the FFT output range
-        if (freq >= 0 && freq < 10000) {
+        if (freq < 10000) {
             state = 5; // OFF
         } else if (freq >= 10000 && freq < 25000) {
             state = 4; // LOW
@@ -108,7 +98,7 @@
         } else if (freq >= 40000 && freq < 55000) {
             state = 2; // HIGH
         } else if (freq >= 55000) {
-            state = 1; // ON
+            state = 1; // HIGHEST
         } 
         
         // switch statement based on the state
@@ -183,6 +173,8 @@
         
         
         }
+        
+        pc.printf("done");
     
 }
 
@@ -195,18 +187,19 @@
         return;
     }
     
-    int buffer[BUFFER_SIZE];
+    float buffer[BUFFER_SIZE];
     int buffer_index = 0;
     int value;
-    pc.printf("Thread start\n");
+
     while(fscanf(fp,"%d,",&value) == 1){
-           buffer[buffer_index] = value;
+           buffer[buffer_index] = (float)value;
            buffer_index++;
-           pc.printf("%d\n",value);
-           buffer_index++;
+           //pc.printf("%d\n",value);
+           //buffer_index++;
            if(buffer_index == BUFFER_SIZE)
            {
                //fast fourier tranform function here
+               vRealFFT(buffer, 64);
                display_fft(buffer);
                buffer_index = 0;
                memset(buffer,0,sizeof(buffer));