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_fft_bin_example_f32.c 00009 * 00010 * Description: Example code demonstrating calculation of Max energy bin of 00011 * frequency domain of input signal. 00012 * 00013 * Target Processor: Cortex-R4 00014 * 00015 * Version 2.0.0 2011/12/15 00016 * Final release. 00017 * 00018 * ---------------------------------------------------------------------------- */ 00019 00076 #include "arm_math.h" 00077 00078 #define TEST_LENGTH_SAMPLES 2048 00079 00080 /* ------------------------------------------------------------------- 00081 * External Input and Output buffer Declarations for FFT Bin Example 00082 * ------------------------------------------------------------------- */ 00083 extern float32_t testInput_f32_10khz[TEST_LENGTH_SAMPLES]; 00084 static float32_t testOutput[TEST_LENGTH_SAMPLES/2]; 00085 00086 /* ------------------------------------------------------------------ 00087 * Global variables for FFT Bin Example 00088 * ------------------------------------------------------------------- */ 00089 uint32_t fftSize = 1024; 00090 uint32_t ifftFlag = 0; 00091 uint32_t doBitReverse = 1; 00092 00093 /* Reference index at which max energy of bin ocuurs */ 00094 uint32_t refIndex = 213, testIndex = 0; 00095 00096 /* ---------------------------------------------------------------------- 00097 * Max magnitude FFT Bin test 00098 * ------------------------------------------------------------------- */ 00099 00100 int32_t main(void) 00101 { 00102 00103 arm_status status; 00104 arm_cfft_radix4_instance_f32 S; 00105 float32_t maxValue; 00106 00107 status = ARM_MATH_SUCCESS; 00108 00109 /* Initialize the CFFT/CIFFT module */ 00110 status = arm_cfft_radix4_init_f32(&S, fftSize, 00111 ifftFlag, doBitReverse); 00112 00113 /* Process the data through the CFFT/CIFFT module */ 00114 arm_cfft_radix4_f32(&S, testInput_f32_10khz); 00115 00116 00117 /* Process the data through the Complex Magnitude Module for 00118 calculating the magnitude at each bin */ 00119 arm_cmplx_mag_f32(testInput_f32_10khz, testOutput, 00120 fftSize); 00121 00122 /* Calculates maxValue and returns corresponding BIN value */ 00123 arm_max_f32(testOutput, fftSize, &maxValue, &testIndex); 00124 00125 if(testIndex != refIndex) 00126 { 00127 status = ARM_MATH_TEST_FAILURE; 00128 } 00129 00130 /* ---------------------------------------------------------------------- 00131 ** Loop here if the signals fail the PASS check. 00132 ** This denotes a test failure 00133 ** ------------------------------------------------------------------- */ 00134 00135 if( status != ARM_MATH_SUCCESS) 00136 { 00137 while(1); 00138 } 00139 } 00140