00001 /* ---------------------------------------------------------------------- 00002 * Copyright (C) 2011 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 15. December 2011 00005 * $Revision: V2.0.0 00006 * 00007 * Project: Cortex-R4 DSP Library 00008 * Title: arm_fir_example_f32.c 00009 * 00010 * Description: Example code demonstrating how an FIR filter can be used 00011 * as a low pass filter. 00012 * 00013 * Target Processor: Cortex-R4 00014 * 00015 * Version 2.0.0 2011/12/15 00016 * Final release. 00017 * 00018 * ---------------------------------------------------------------------------- */ 00019 00099 /* ---------------------------------------------------------------------- 00100 ** Include Files 00101 ** ------------------------------------------------------------------- */ 00102 00103 #include "arm_math.h" 00104 #include "math_helper.h" 00105 00106 /* ---------------------------------------------------------------------- 00107 ** Macro Defines 00108 ** ------------------------------------------------------------------- */ 00109 00110 #define TEST_LENGTH_SAMPLES 320 00111 #define SNR_THRESHOLD_F32 140.0f 00112 #define BLOCK_SIZE 32 00113 #define NUM_TAPS 29 00114 00115 /* ------------------------------------------------------------------- 00116 * The input signal and reference output (computed with MATLAB) 00117 * are defined externally in arm_fir_lpf_data.c. 00118 * ------------------------------------------------------------------- */ 00119 00120 extern float32_t testInput_f32_1kHz_15kHz[TEST_LENGTH_SAMPLES]; 00121 extern float32_t refOutput[TEST_LENGTH_SAMPLES]; 00122 00123 /* ------------------------------------------------------------------- 00124 * Declare Test output buffer 00125 * ------------------------------------------------------------------- */ 00126 00127 static float32_t testOutput[TEST_LENGTH_SAMPLES]; 00128 00129 /* ------------------------------------------------------------------- 00130 * Declare State buffer of size (numTaps + blockSize - 1) 00131 * ------------------------------------------------------------------- */ 00132 00133 static float32_t firStateF32[BLOCK_SIZE + NUM_TAPS - 1]; 00134 00135 /* ---------------------------------------------------------------------- 00136 ** FIR Coefficients buffer generated using fir1() MATLAB function. 00137 ** fir1(28, 6/24) 00138 ** ------------------------------------------------------------------- */ 00139 00140 const float32_t firCoeffs32[NUM_TAPS] = { 00141 -0.0018225230f, -0.0015879294f, +0.0000000000f, +0.0036977508f, +0.0080754303f, +0.0085302217f, -0.0000000000f, -0.0173976984f, 00142 -0.0341458607f, -0.0333591565f, +0.0000000000f, +0.0676308395f, +0.1522061835f, +0.2229246956f, +0.2504960933f, +0.2229246956f, 00143 +0.1522061835f, +0.0676308395f, +0.0000000000f, -0.0333591565f, -0.0341458607f, -0.0173976984f, -0.0000000000f, +0.0085302217f, 00144 +0.0080754303f, +0.0036977508f, +0.0000000000f, -0.0015879294f, -0.0018225230f 00145 }; 00146 00147 /* ------------------------------------------------------------------ 00148 * Global variables for FIR LPF Example 00149 * ------------------------------------------------------------------- */ 00150 00151 uint32_t blockSize = BLOCK_SIZE; 00152 uint32_t numBlocks = TEST_LENGTH_SAMPLES/BLOCK_SIZE; 00153 00154 float32_t snr; 00155 00156 /* ---------------------------------------------------------------------- 00157 * FIR LPF Example 00158 * ------------------------------------------------------------------- */ 00159 00160 int32_t main(void) 00161 { 00162 uint32_t i; 00163 arm_fir_instance_f32 S; 00164 arm_status status; 00165 float32_t *inputF32, *outputF32; 00166 00167 /* Initialize input and output buffer pointers */ 00168 inputF32 = &testInput_f32_1kHz_15kHz[0]; 00169 outputF32 = &testOutput[0]; 00170 00171 /* Call FIR init function to initialize the instance structure. */ 00172 arm_fir_init_f32(&S, NUM_TAPS, (float32_t *)&firCoeffs32[0], &firStateF32[0], blockSize); 00173 00174 /* ---------------------------------------------------------------------- 00175 ** Call the FIR process function for every blockSize samples 00176 ** ------------------------------------------------------------------- */ 00177 00178 for(i=0; i < numBlocks; i++) 00179 { 00180 arm_fir_f32(&S, inputF32 + (i * blockSize), outputF32 + (i * blockSize), blockSize); 00181 } 00182 00183 /* ---------------------------------------------------------------------- 00184 ** Compare the generated output against the reference output computed 00185 ** in MATLAB. 00186 ** ------------------------------------------------------------------- */ 00187 00188 snr = arm_snr_f32(&refOutput[0], &testOutput[0], TEST_LENGTH_SAMPLES); 00189 00190 if (snr < SNR_THRESHOLD_F32) 00191 { 00192 status = ARM_MATH_TEST_FAILURE; 00193 } 00194 else 00195 { 00196 status = ARM_MATH_SUCCESS; 00197 } 00198 00199 /* ---------------------------------------------------------------------- 00200 ** Loop here if the signal does not match the reference output. 00201 ** ------------------------------------------------------------------- */ 00202 00203 if( status != ARM_MATH_SUCCESS) 00204 { 00205 while(1); 00206 } 00207 } 00208