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_signal_converge_example_f32.c 00009 * 00010 * Description: Example code demonstrating convergence of an adaptive 00011 * filter. 00012 * 00013 * Target Processor: Cortex-R4 00014 * 00015 * Version 2.0.0 2011/12/15 00016 * Final release. 00017 * 00018 * ---------------------------------------------------------------------------- */ 00019 00087 #include "arm_math.h" 00088 #include "math_helper.h" 00089 00090 /* ---------------------------------------------------------------------- 00091 ** Global defines for the simulation 00092 * ------------------------------------------------------------------- */ 00093 00094 #define TEST_LENGTH_SAMPLES 1536 00095 #define NUMTAPS 32 00096 #define BLOCKSIZE 32 00097 #define DELTA_ERROR 0.000001f 00098 #define DELTA_COEFF 0.0001f 00099 #define MU 0.5f 00100 00101 #define NUMFRAMES (TEST_LENGTH_SAMPLES / BLOCKSIZE) 00102 00103 /* ---------------------------------------------------------------------- 00104 * Declare FIR state buffers and structure 00105 * ------------------------------------------------------------------- */ 00106 00107 float32_t firStateF32[NUMTAPS + BLOCKSIZE]; 00108 arm_fir_instance_f32 LPF_instance; 00109 00110 /* ---------------------------------------------------------------------- 00111 * Declare LMSNorm state buffers and structure 00112 * ------------------------------------------------------------------- */ 00113 00114 float32_t lmsStateF32[NUMTAPS + BLOCKSIZE]; 00115 float32_t errOutput[TEST_LENGTH_SAMPLES]; 00116 arm_lms_norm_instance_f32 lmsNorm_instance; 00117 00118 00119 /* ---------------------------------------------------------------------- 00120 * Function Declarations for Signal Convergence Example 00121 * ------------------------------------------------------------------- */ 00122 00123 arm_status test_signal_converge_example( void ); 00124 00125 00126 /* ---------------------------------------------------------------------- 00127 * Internal functions 00128 * ------------------------------------------------------------------- */ 00129 arm_status test_signal_converge(float32_t* err_signal, 00130 uint32_t blockSize); 00131 00132 void getinput(float32_t* input, 00133 uint32_t fr_cnt, 00134 uint32_t blockSize); 00135 00136 /* ---------------------------------------------------------------------- 00137 * External Declarations for FIR F32 module Test 00138 * ------------------------------------------------------------------- */ 00139 extern float32_t testInput_f32[TEST_LENGTH_SAMPLES]; 00140 extern float32_t lmsNormCoeff_f32[32]; 00141 extern const float32_t FIRCoeff_f32[32]; 00142 extern arm_lms_norm_instance_f32 lmsNorm_instance; 00143 00144 /* ---------------------------------------------------------------------- 00145 * Declare I/O buffers 00146 * ------------------------------------------------------------------- */ 00147 00148 float32_t wire1[BLOCKSIZE]; 00149 float32_t wire2[BLOCKSIZE]; 00150 float32_t wire3[BLOCKSIZE]; 00151 float32_t err_signal[BLOCKSIZE]; 00152 00153 /* ---------------------------------------------------------------------- 00154 * Signal converge test 00155 * ------------------------------------------------------------------- */ 00156 00157 int32_t main(void) 00158 { 00159 uint32_t i; 00160 arm_status status; 00161 uint32_t index; 00162 float32_t minValue; 00163 00164 /* Initialize the LMSNorm data structure */ 00165 arm_lms_norm_init_f32(&lmsNorm_instance, NUMTAPS, lmsNormCoeff_f32, lmsStateF32, MU, BLOCKSIZE); 00166 00167 /* Initialize the FIR data structure */ 00168 arm_fir_init_f32(&LPF_instance, NUMTAPS, (float32_t *)FIRCoeff_f32, firStateF32, BLOCKSIZE); 00169 00170 /* ---------------------------------------------------------------------- 00171 * Loop over the frames of data and execute each of the processing 00172 * functions in the system. 00173 * ------------------------------------------------------------------- */ 00174 00175 for(i=0; i < NUMFRAMES; i++) 00176 { 00177 /* Read the input data - uniformly distributed random noise - into wire1 */ 00178 arm_copy_f32(testInput_f32 + (i * BLOCKSIZE), wire1, BLOCKSIZE); 00179 00180 /* Execute the FIR processing function. Input wire1 and output wire2 */ 00181 arm_fir_f32(&LPF_instance, wire1, wire2, BLOCKSIZE); 00182 00183 /* Execute the LMS Norm processing function*/ 00184 00185 arm_lms_norm_f32(&lmsNorm_instance, /* LMSNorm instance */ 00186 wire1, /* Input signal */ 00187 wire2, /* Reference Signal */ 00188 wire3, /* Converged Signal */ 00189 err_signal, /* Error Signal, this will become small as the signal converges */ 00190 BLOCKSIZE); /* BlockSize */ 00191 00192 /* apply overall gain */ 00193 arm_scale_f32(wire3, 5, wire3, BLOCKSIZE); /* in-place buffer */ 00194 } 00195 00196 status = ARM_MATH_SUCCESS; 00197 00198 /* ------------------------------------------------------------------------------- 00199 * Test whether the error signal has reached towards 0. 00200 * ----------------------------------------------------------------------------- */ 00201 00202 arm_abs_f32(err_signal, err_signal, BLOCKSIZE); 00203 arm_min_f32(err_signal, BLOCKSIZE, &minValue, &index); 00204 00205 if (minValue > DELTA_ERROR) 00206 { 00207 status = ARM_MATH_TEST_FAILURE; 00208 } 00209 00210 /* ---------------------------------------------------------------------- 00211 * Test whether the filter coefficients have converged. 00212 * ------------------------------------------------------------------- */ 00213 00214 arm_sub_f32((float32_t *)FIRCoeff_f32, lmsNormCoeff_f32, lmsNormCoeff_f32, NUMTAPS); 00215 00216 arm_abs_f32(lmsNormCoeff_f32, lmsNormCoeff_f32, NUMTAPS); 00217 arm_min_f32(lmsNormCoeff_f32, NUMTAPS, &minValue, &index); 00218 00219 if (minValue > DELTA_COEFF) 00220 { 00221 status = ARM_MATH_TEST_FAILURE; 00222 } 00223 00224 /* ---------------------------------------------------------------------- 00225 * Loop here if the signals did not pass the convergence check. 00226 * This denotes a test failure 00227 * ------------------------------------------------------------------- */ 00228 00229 if( status != ARM_MATH_SUCCESS) 00230 { 00231 while(1); 00232 } 00233 } 00234