огшор

Dependencies:   CMSIS_DSP_401 mbed

Fork of fir_f32 by Nikolay Sergeev

Revision:
3:1f56b8f439a1
Parent:
2:707eb5bc5dfc
Child:
4:397e8f4699df
--- a/main.cpp	Fri Oct 03 14:52:53 2014 +0000
+++ b/main.cpp	Tue Oct 07 15:20:49 2014 +0000
@@ -8,9 +8,7 @@
    float32_t * p1,
    uint8_t ifftFlag,
    uint8_t bitReverseFlag);
-   
 
- 
 Serial pc(USBTX, USBRX);
  
 AnalogIn   left(A2);
@@ -20,20 +18,21 @@
 const int FFT_SIZE = 16;                // Size of the FFT.
  
 const static arm_cfft_instance_f32 *S;
+//static arm_cfft_radix2_instance_f32 *S;
 Ticker samplingTimer;
 float samples[FFT_SIZE*2];
 float magnitudes[FFT_SIZE];
 int sampleCounter = 0;
  
 void samplingCallback()
-{
-    
+{    
     // Read from the ADC and store the sample data
-    samples[sampleCounter] = (1023 * left.read()) - 511.0;
+    samples[sampleCounter] = 1000*left.read();
     // 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;
     // Update sample buffer position and stop after the buffer is filled
+        
     sampleCounter += 2;
     
     if (sampleCounter >= FFT_SIZE*2) {
@@ -45,7 +44,7 @@
 {
     // Reset sample buffer position and start callback at necessary rate.
     sampleCounter = 0;
-    samplingTimer.attach_us(&samplingCallback, 1000000/SAMPLE_RATE_HZ);
+    samplingTimer.attach_us(&samplingCallback, (float)(1000000/SAMPLE_RATE_HZ));
 }
  
 bool samplingIsDone()
@@ -56,7 +55,7 @@
 int main()
 {
     // Set up serial port.
-    pc.baud (38400);
+    //pc.baud (38400);
  
     // Init arm_ccft_32
     switch (FFT_SIZE)
@@ -99,20 +98,24 @@
     {
         // Calculate FFT if a full sample is available.
         if (samplingIsDone())
-        {
+        {            
             // Run FFT on sample data.
             //arm_cfft_radix2_f32(arm_cfft_radix2_instance_f32*S, samples);
             arm_cfft_f32(S, samples, 0, 1);
+            samples[0] = samples[0]/1000;
+            /* Initialize the CFFT/CIFFT module */
+            //arm_cfft_radix2_init_f32(S, 128, 0, 1);
+            //arm_cfft_radix2_f32(S, samples);
             for(int i = 0;i < FFT_SIZE*2;++i)
-                pc.printf("% 8.2f ",samples[i]);
+                pc.printf("     Samples[%d]: %8.2f ",i,samples[i]);
             pc.printf("\r\n");
             // Calculate magnitude of complex numbers output by the FFT.
             arm_cmplx_mag_f32(samples, magnitudes, FFT_SIZE);
             for(int i = 0;i < FFT_SIZE;++i)
-                pc.printf("% 8.2f ",magnitudes[i]);
-            pc.printf("\r\n");
+                pc.printf("     Magnitude: %d = %8.2f ;", i, magnitudes[i]);
+            pc.printf("       \r\n");
             arm_max_f32(magnitudes, FFT_SIZE, &maxValue, &testIndex);
-            pc.printf("MAX value at magnitudes[%d] : %+ 8.2f\r\n", testIndex, maxValue);
+            pc.printf("     MAX value at magnitudes[%d] : %+8.2f\r\n", testIndex, maxValue);
             // Wait for user confirmation to restart audio sampling.
             //pc.getc();
             wait(1);