lab 1 code

Dependencies:   CMSIS-DSP_for_STM32F746G BSP_DISCO_F746NG

Revision:
25:5412779376a7
Parent:
24:9ac1187f9012
Child:
27:0d65cfcc9001
--- a/signal_processing.cpp	Wed Jan 01 06:30:01 2020 +0000
+++ b/signal_processing.cpp	Wed Jan 01 06:47:21 2020 +0000
@@ -33,13 +33,30 @@
 ** 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 
 }; 
+*/
+
+/* ---------------------------------------------------------------------- 
+** FIR Coefficients buffer generated using fdatool MATLAB function. 
+** lowpass filter to passband 1 kHz, stopband 2 kHz
+** ------------------------------------------------------------------- */ 
+
+const float32_t firCoeffs32[29] = {
+     0.0106548937,  0.00951616466, 0.008600869216, 0.002842310816,-0.007469337899,
+   -0.01967334561, -0.02897886001,  -0.0296635218, -0.01692939363,  0.01112444047,
+    0.05218170211,  0.09966956824,   0.1441507041,   0.1758090258,   0.1872722059,
+     0.1758090258,   0.1441507041,  0.09966956824,  0.05218170211,  0.01112444047,
+   -0.01692939363,  -0.0296635218, -0.02897886001, -0.01967334561,-0.007469337899,
+   0.002842310816, 0.008600869216,  0.00951616466,   0.0106548937
+};
+
 
 /* ------------------------------------------------------------------- 
  * Declare State buffer of size (numTaps + blockSize - 1) 
@@ -62,7 +79,19 @@
 //uint32_t numBlocks = TEST_LENGTH_SAMPLES/BLOCK_SIZE; 
 uint32_t numBlocks = AUDIO_BLOCK_SAMPLES/BLOCK_SIZE; 
 
+/* Important to have the structure outside of the execution so it can be initialized */
+arm_fir_instance_f32 S; 
 
+/**
+  * @brief  Initialize filter structures to be used in loops later
+  * @retval None
+  */
+void initalize_signal_processing(void) {
+
+  /* Call FIR init function to initialize the instance structure. */
+  arm_fir_init_f32(&S, NUM_TAPS, (float32_t *)&firCoeffs32[0], &firStateF32[0], blockSize); 
+
+}
 
 /**
   * @brief  Process audio channel signals
@@ -81,7 +110,6 @@
     
    
   uint32_t i; 
-  arm_fir_instance_f32 S; 
   arm_status status; 
   float32_t  *inputF32, *outputF32; 
  
@@ -91,8 +119,6 @@
   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