Example FIR filter using the CMSIS DSP API

Dependencies:   mbed mbed-dsp

Files at this revision

API Documentation at this revision

Comitter:
emilmont
Date:
Tue Jan 08 17:00:49 2013 +0000
Parent:
1:9442dff3bfdc
Commit message:
Update example to latest mbed-dsp library

Changed in this revision

data.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-dsp.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 9442dff3bfdc -r 9ccaf6885ced data.cpp
--- a/data.cpp	Mon Mar 12 12:00:25 2012 +0000
+++ b/data.cpp	Tue Jan 08 17:00:49 2013 +0000
@@ -1,7 +1,11 @@
 #include "arm_math.h"
 
-// Test input signal contains 1000Hz + 15000 Hz
-float32_t signal[320] = {
+/* ----------------------------------------------------------------------
+** Test input signal contains 1000Hz + 15000 Hz
+** ------------------------------------------------------------------- */
+
+float32_t testInput_f32_1kHz_15kHz[320] =
+{
 +0.0000000000f, +0.5924659585f, -0.0947343455f, +0.1913417162f, +1.0000000000f, +0.4174197128f, +0.3535533906f, +1.2552931065f, 
 +0.8660254038f, +0.4619397663f, +1.3194792169f, +1.1827865776f, +0.5000000000f, +1.1827865776f, +1.3194792169f, +0.4619397663f, 
 +0.8660254038f, +1.2552931065f, +0.3535533906f, +0.4174197128f, +1.0000000000f, +0.1913417162f, -0.0947343455f, +0.5924659585f, 
@@ -44,7 +48,8 @@
 +0.0000000000f, -0.5924659585f, +0.0947343455f, -0.1913417162f, -1.0000000000f, -0.4174197128f, -0.3535533906f, -1.2552931065f, 
 };
 
-float32_t filtered_signal[320] = {
+float32_t refOutput[320] = 
+{
 +0.0000000000f, -0.0010797829f, -0.0007681386f, -0.0001982932f, +0.0000644313f, +0.0020854271f, +0.0036891871f, +0.0015855941f, 
 -0.0026280805f, -0.0075907658f, -0.0119390538f, -0.0086665968f, +0.0088981202f, +0.0430539279f, +0.0974468742f, +0.1740405600f, 
 +0.2681416601f, +0.3747720089f, +0.4893362230f, +0.6024154672f, +0.7058740791f, +0.7968348987f, +0.8715901940f, +0.9277881093f, 
diff -r 9442dff3bfdc -r 9ccaf6885ced main.cpp
--- a/main.cpp	Mon Mar 12 12:00:25 2012 +0000
+++ b/main.cpp	Tue Jan 08 17:00:49 2013 +0000
@@ -1,23 +1,32 @@
-#include <stdio.h>
 #include "arm_math.h" 
 #include "math_helper.h" 
+#include <stdio.h>
 
 #define BLOCK_SIZE          32
 #define NUM_BLOCKS          10
+
 #define TEST_LENGTH_SAMPLES (BLOCK_SIZE * NUM_BLOCKS)
 
+#define SNR_THRESHOLD_F32   140.0f
 #define NUM_TAPS            29
-#define SNR_THRESHOLD_F32   140.0f
+
+/* -------------------------------------------------------------------
+ * The input signal and reference output (computed with MATLAB)
+ * are defined externally in arm_fir_lpf_data.c.
+ * ------------------------------------------------------------------- */
+extern float32_t testInput_f32_1kHz_15kHz[TEST_LENGTH_SAMPLES]; 
+extern float32_t refOutput[TEST_LENGTH_SAMPLES]; 
 
-// The input signal and reference output
-extern float32_t          signal[TEST_LENGTH_SAMPLES]; 
-extern float32_t filtered_signal[TEST_LENGTH_SAMPLES]; 
+/* ------------------------------------------------------------------- 
+ * Declare State buffer of size (numTaps + blockSize - 1)
+ * ------------------------------------------------------------------- */
+static float32_t firStateF32[BLOCK_SIZE + NUM_TAPS - 1]; 
 
-// Declare FIR State buffer of size (numTaps + blockSize - 1)
-float32_t fir_state[BLOCK_SIZE + NUM_TAPS - 1]; 
-
-// FIR Coefficients
-const float32_t fir_coeff[NUM_TAPS] = { 
+/* ---------------------------------------------------------------------- 
+ * 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,
@@ -26,23 +35,31 @@
     +0.0036977508f, +0.0000000000f, -0.0015879294f, -0.0018225230f
 };
 
+/* ---------------------------------------------------------------------- 
+ * FIR LPF Example 
+ * ------------------------------------------------------------------- */
 int32_t main(void) { 
-    // Call FIR init function to initialize the instance structure.
-    arm_fir_instance_f32 fir;
-    arm_fir_init_f32(&fir, NUM_TAPS, (float32_t *)fir_coeff, fir_state, BLOCK_SIZE); 
+    /* Call FIR init function to initialize the instance structure. */
+    arm_fir_instance_f32 S;
+    arm_fir_init_f32(&S, NUM_TAPS, (float32_t *)&firCoeffs32[0], &firStateF32[0], BLOCK_SIZE); 
     
-    // Call the FIR process function for every BLOCK_SIZE samples  
+    /* ---------------------------------------------------------------------- 
+     * Call the FIR process function for every blockSize samples  
+     * ------------------------------------------------------------------- */ 
     for (uint32_t i=0; i < NUM_BLOCKS; i++) {
-        float32_t* signal_buffer =  signal + (i * BLOCK_SIZE);
-        arm_fir_f32(&fir, signal_buffer, signal_buffer, BLOCK_SIZE);
+        float32_t* signal =  testInput_f32_1kHz_15kHz + (i * BLOCK_SIZE);
+        arm_fir_f32(&S, signal, signal, BLOCK_SIZE);
     } 
     
-    // Compare the generated output against the reference
-    float32_t snr = arm_snr_f32(filtered_signal, signal, TEST_LENGTH_SAMPLES);
+    /* ---------------------------------------------------------------------- 
+     * Compare the generated output against the reference output computed
+     * in MATLAB.
+     * ------------------------------------------------------------------- */
+    float32_t snr = arm_snr_f32(refOutput, testInput_f32_1kHz_15kHz, TEST_LENGTH_SAMPLES);
     printf("snr: %f\n\r", snr);
     if (snr < SNR_THRESHOLD_F32) {
         printf("Failed\n\r");
     } else {
         printf("Success\n\r");
     }
-}
+} 
diff -r 9442dff3bfdc -r 9ccaf6885ced mbed-dsp.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-dsp.lib	Tue Jan 08 17:00:49 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-dsp/#fdd22bb7aa52
diff -r 9442dff3bfdc -r 9ccaf6885ced mbed.bld
--- a/mbed.bld	Mon Mar 12 12:00:25 2012 +0000
+++ b/mbed.bld	Tue Jan 08 17:00:49 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479
+http://mbed.org/users/mbed_official/code/mbed/builds/71b101360fb9
\ No newline at end of file