lab 1 code

Dependencies:   CMSIS-DSP_for_STM32F746G BSP_DISCO_F746NG

Revision:
24:9ac1187f9012
Parent:
23:d938f87dd1ee
Child:
25:5412779376a7
--- a/signal_processing.cpp	Tue Dec 31 22:45:31 2019 +0000
+++ b/signal_processing.cpp	Wed Jan 01 06:30:01 2020 +0000
@@ -16,6 +16,52 @@
 
 #include "mbed.h"
 #include "stm32746g_discovery_lcd.h"
+#include "arm_math.h"
+
+
+/* ---------------------------------------------------------------------- 
+** Macro Defines  
+** ------------------------------------------------------------------- */ 
+
+#define AUDIO_BLOCK_SAMPLES             ((uint32_t)128)         // Number of samples (L and R) in audio block (each samples is 16 bits)
+#define TEST_LENGTH_SAMPLES 320 
+#define SNR_THRESHOLD_F32       140.0f 
+#define BLOCK_SIZE                      32 
+#define NUM_TAPS                        29 
+
+/* ---------------------------------------------------------------------- 
+** FIR Coefficients buffer generated using fir1() MATLAB function. 
+** fir1(28, 6/24)
+** ------------------------------------------------------------------- */ 
+ 
+const float32_t firCoeffs32[NUM_TAPS] = { 
+-0.0018225230f, -0.0015879294f, +0.0000000000f, +0.0036977508f, +0.0080754303f, +0.0085302217f, -0.0000000000f, -0.0173976984f, 
+-0.0341458607f, -0.0333591565f, +0.0000000000f, +0.0676308395f, +0.1522061835f, +0.2229246956f, +0.2504960933f, +0.2229246956f, 
++0.1522061835f, +0.0676308395f, +0.0000000000f, -0.0333591565f, -0.0341458607f, -0.0173976984f, -0.0000000000f, +0.0085302217f, 
++0.0080754303f, +0.0036977508f, +0.0000000000f, -0.0015879294f, -0.0018225230f 
+}; 
+
+/* ------------------------------------------------------------------- 
+ * Declare State buffer of size (numTaps + blockSize - 1) 
+ * ------------------------------------------------------------------- */ 
+
+static float32_t firStateF32[BLOCK_SIZE + NUM_TAPS - 1]; 
+
+/* ------------------------------------------------------------------- 
+ * Declare Test output buffer 
+ * ------------------------------------------------------------------- */ 
+
+static float32_t testOutput[BLOCK_SIZE]; 
+static float32_t output_array_F32[AUDIO_BLOCK_SAMPLES];
+
+/* ------------------------------------------------------------------ 
+ * Global variables for FIR LPF Example 
+ * ------------------------------------------------------------------- */ 
+
+uint32_t blockSize = BLOCK_SIZE; 
+//uint32_t numBlocks = TEST_LENGTH_SAMPLES/BLOCK_SIZE; 
+uint32_t numBlocks = AUDIO_BLOCK_SAMPLES/BLOCK_SIZE; 
+
 
 
 /**
@@ -33,23 +79,49 @@
     sprintf(buf, "Processing Signals" );
     BSP_LCD_DisplayStringAt(0, 150, (uint8_t *) buf, LEFT_MODE);
     
-    uint16_t i;
-    float* L_chan_mem_address;
-    float* R_chan_mem_address;
-    float L_audio_value;
-    float R_audio_value;
+   
+  uint32_t i; 
+  arm_fir_instance_f32 S; 
+  arm_status status; 
+  float32_t  *inputF32, *outputF32; 
+ 
+  /* Initialize input and output buffer pointers */ 
+  //inputF32 = &testInput_f32_1kHz_15kHz[0];       
+  //outputF32 = &testOutput[0]; 
+  inputF32 = L_channel;
+  outputF32 = &output_array_F32[0];
+
+  /* Call FIR init function to initialize the instance structure. */
+  arm_fir_init_f32(&S, NUM_TAPS, (float32_t *)&firCoeffs32[0], &firStateF32[0], blockSize); 
+ 
+  /* ---------------------------------------------------------------------- 
+  ** Call the FIR process function for every blockSize samples  
+  ** ------------------------------------------------------------------- */ 
+
+  for(i=0; i < numBlocks; i++)  
+    {    
+      arm_fir_f32(&S, inputF32 + (i * blockSize), outputF32 + (i * blockSize), blockSize);  
+    } 
+
+    /* The following just passes things from the input to the output */
+    //uint16_t i;
+    float32_t* L_chan_mem_address;
+    float32_t* R_chan_mem_address;
+    float32_t L_audio_value;
+    float32_t R_audio_value;
         
     L_chan_mem_address = L_channel;
     R_chan_mem_address = R_channel;
     
     for (i=0; i<Signal_Length; i++)
    {
-        L_audio_value = *L_chan_mem_address;
-        *L_chan_mem_address = L_audio_value * 2;
+        //L_audio_value = *L_chan_mem_address;
+        L_audio_value = output_array_F32[i];
+        *L_chan_mem_address = L_audio_value;
         L_chan_mem_address++;
         
         R_audio_value = *R_chan_mem_address;
-        *R_chan_mem_address = R_audio_value / 2;
+        *R_chan_mem_address = R_audio_value;
         R_chan_mem_address++;
    }