arm fir example f32 8c source


CMSIS DSP Software Library: arm_fir_example_f32.c Source File Main Page Modules Data Structures Files Examples File List Globals arm_fir_example_f32.c Go to the documentation of this file.00001 /* ---------------------------------------------------------------------- 00002 * Copyright (C) 2010 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 29. November 2010 00005 * $Revision: V1.0.3 00006 * 00007 * Project: CMSIS 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-M4/Cortex-M3 00014 * 00015 * 00016 * Version 1.0.3 2010/11/29 00017 * Re-organized the CMSIS folders and updated documentation. 00018 * 00019 * Version 1.0.1 2010/10/05 KK 00020 * Production release and review comments incorporated. 00021 * 00022 * Version 1.0.0 2010/09/20 KK 00023 * Production release and review comments incorporated. 00024 * ------------------------------------------------------------------- */ 00025 00105 /* ---------------------------------------------------------------------- 00106 ** Include Files 00107 ** ------------------------------------------------------------------- */ 00108 00109 #include "arm_math.h" 00110 #include "math_helper.h" 00111 00112 /* ---------------------------------------------------------------------- 00113 ** Macro Defines 00114 ** ------------------------------------------------------------------- */ 00115 00116 #define TEST_LENGTH_SAMPLES 320 00117 #define SNR_THRESHOLD_F32 140.0f 00118 #define BLOCK_SIZE 32 00119 #define NUM_TAPS 29 00120 00121 /* ------------------------------------------------------------------- 00122 * The input signal and reference output (computed with MATLAB) 00123 * are defined externally in arm_fir_lpf_data.c. 00124 * ------------------------------------------------------------------- */ 00125 00126 extern float32_t testInput_f32_1kHz_15kHz[TEST_LENGTH_SAMPLES]; 00127 extern float32_t refOutput[TEST_LENGTH_SAMPLES]; 00128 00129 /* ------------------------------------------------------------------- 00130 * Declare Test output buffer 00131 * ------------------------------------------------------------------- */ 00132 00133 static float32_t testOutput[TEST_LENGTH_SAMPLES]; 00134 00135 /* ------------------------------------------------------------------- 00136 * Declare State buffer of size (numTaps + blockSize - 1) 00137 * ------------------------------------------------------------------- */ 00138 00139 static float32_t firStateF32[BLOCK_SIZE + NUM_TAPS - 1]; 00140 00141 /* ---------------------------------------------------------------------- 00142 ** FIR Coefficients buffer generated using fir1() MATLAB function. 00143 ** fir1(28, 6/24) 00144 ** ------------------------------------------------------------------- */ 00145 00146 const float32_t firCoeffs32[NUM_TAPS] = { 00147 -0.0018225230f, -0.0015879294f, +0.0000000000f, +0.0036977508f, +0.0080754303f, +0.0085302217f, -0.0000000000f, -0.0173976984f, 00148 -0.0341458607f, -0.0333591565f, +0.0000000000f, +0.0676308395f, +0.1522061835f, +0.2229246956f, +0.2504960933f, +0.2229246956f, 00149 +0.1522061835f, +0.0676308395f, +0.0000000000f, -0.0333591565f, -0.0341458607f, -0.0173976984f, -0.0000000000f, +0.0085302217f, 00150 +0.0080754303f, +0.0036977508f, +0.0000000000f, -0.0015879294f, -0.0018225230f 00151 }; 00152 00153 /* ------------------------------------------------------------------ 00154 * Global variables for FIR LPF Example 00155 * ------------------------------------------------------------------- */ 00156 00157 uint32_t blockSize = BLOCK_SIZE; 00158 uint32_t numBlocks = TEST_LENGTH_SAMPLES/BLOCK_SIZE; 00159 00160 float32_t snr; 00161 00162 /* ---------------------------------------------------------------------- 00163 * FIR LPF Example 00164 * ------------------------------------------------------------------- */ 00165 00166 int32_t main(void) 00167 { 00168 uint32_t i; 00169 arm_fir_instance_f32 S; 00170 arm_status status; 00171 float32_t *inputF32, *outputF32; 00172 00173 /* Initialize input and output buffer pointers */ 00174 inputF32 = &testInput_f32_1kHz_15kHz[0]; 00175 outputF32 = &testOutput[0]; 00176 00177 /* Call FIR init function to initialize the instance structure. */ 00178 arm_fir_init_f32(&S, NUM_TAPS, (float32_t *)&firCoeffs32[0], &firStateF32[0], blockSize); 00179 00180 /* ---------------------------------------------------------------------- 00181 ** Call the FIR process function for every blockSize samples 00182 ** ------------------------------------------------------------------- */ 00183 00184 for(i=0; i < numBlocks; i++) 00185 { 00186 arm_fir_f32(&S, inputF32 + (i * blockSize), outputF32 + (i * blockSize), blockSize); 00187 } 00188 00189 /* ---------------------------------------------------------------------- 00190 ** Compare the generated output against the reference output computed 00191 ** in MATLAB. 00192 ** ------------------------------------------------------------------- */ 00193 00194 snr = arm_snr_f32(&refOutput[0], &testOutput[0], TEST_LENGTH_SAMPLES); 00195 00196 if (snr < SNR_THRESHOLD_F32) 00197 { 00198 status = ARM_MATH_TEST_FAILURE; 00199 } 00200 else 00201 { 00202 status = ARM_MATH_SUCCESS; 00203 } 00204 00205 /* ---------------------------------------------------------------------- 00206 ** Loop here if the signal does not match the reference output. 00207 ** ------------------------------------------------------------------- */ 00208 00209 if( status != ARM_MATH_SUCCESS) 00210 { 00211 while(1); 00212 } 00213 } 00214  All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines Generated on Mon Nov 29 2010 17:19:56 for CMSIS DSP Software Library by  1.7.2

Wyszukiwarka