Added all the F4 libraries to the project
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Examples / arm_fft_bin_example / arm_fft_bin_example_f32.c
1 /* ---------------------------------------------------------------------- 
2 * Copyright (C) 2010 ARM Limited. All rights reserved.   
3 *  
4 * $Date:        29. November 2010  
5 * $Revision:    V1.0.3  
6 *  
7 * Project:          CMSIS DSP Library  
8 * Title:            arm_fft_bin_example_f32.c             
9 *  
10 * Description:  Example code demonstrating calculation of Max energy bin of  
11 *                               frequency domain of input signal. 
12
13 * Target Processor: Cortex-M4/Cortex-M3  
14 *
15 *
16 * Version 1.0.3 2010/11/29 
17 *    Re-organized the CMSIS folders and updated documentation. 
18
19 * Version 1.0.1 2010/10/05 KK 
20 *    Production release and review comments incorporated.  
21 *
22 * Version 1.0.0 2010/09/20 KK
23 *    Production release and review comments incorporated.
24 * ------------------------------------------------------------------- */ 
25  
26 /** 
27  * @ingroup groupExamples 
28  */ 
29  
30 /**    
31  * @defgroup FrequencyBin Frequency Bin Example    
32  * 
33  * \par Description
34  * \par
35  * Demonstrates the calculation of the maximum energy bin in the frequency 
36  * domain of the input signal with the use of Complex FFT, Complex 
37  * Magnitude, and Maximum functions. 
38  * 
39  * \par Algorithm:
40  * \par
41  * The input test signal contains a 10 kHz signal with uniformly distributed white noise.  
42  * Calculating the FFT of the input signal will give us the maximum energy of the 
43  * bin corresponding to the input frequency of 10 kHz.  
44  * 
45  * \par Block Diagram:
46  * \image html FFTBin.gif "Block Diagram"
47  * \par
48  * The figure below shows the time domain signal of 10 kHz signal with 
49  * uniformly distributed white noise, and the next figure shows the input
50  * in the frequency domain. The bin with maximum energy corresponds to 10 kHz signal. 
51  * \par
52  * \image html FFTBinInput.gif "Input signal in Time domain" 
53  * \image html FFTBinOutput.gif "Input signal in Frequency domain"
54  *
55  * \par Variables Description:
56  * \par
57  * \li \c testInput_f32_10khz points to the input data
58  * \li \c testOutput points to the output data
59  * \li \c fftSize length of FFT
60  * \li \c ifftFlag flag for the selection of CFFT/CIFFT
61  * \li \c doBitReverse Flag for selection of normal order or bit reversed order
62  * \li \c refIndex reference index value at which maximum energy of bin ocuurs
63  * \li \c testIndex calculated index value at which maximum energy of bin ocuurs
64  * 
65  * \par CMSIS DSP Software Library Functions Used:
66  * \par
67  * - arm_cfft_radix4_init_f32()
68  * - arm_cfft_radix4_f32()
69  * - arm_cmplx_mag_f32()
70  * - arm_max_f32()
71  *
72  * <b> Refer  </b> 
73  * \link arm_fft_bin_example_f32.c \endlink
74  * 
75  */ 
76  
77  
78 /** \example arm_fft_bin_example_f32.c 
79   */  
80
81      
82 #include "arm_math.h" 
83  
84 #define TEST_LENGTH_SAMPLES 2048 
85  
86 /* ------------------------------------------------------------------- 
87 * External Input and Output buffer Declarations for FFT Bin Example 
88 * ------------------------------------------------------------------- */ 
89 extern float32_t testInput_f32_10khz[TEST_LENGTH_SAMPLES]; 
90 static float32_t testOutput[TEST_LENGTH_SAMPLES/2]; 
91  
92 /* ------------------------------------------------------------------ 
93 * Global variables for FFT Bin Example 
94 * ------------------------------------------------------------------- */ 
95 uint32_t fftSize = 1024; 
96 uint32_t ifftFlag = 0; 
97 uint32_t doBitReverse = 1; 
98  
99 /* Reference index at which max energy of bin ocuurs */ 
100 uint32_t refIndex = 213, testIndex = 0; 
101  
102 /* ---------------------------------------------------------------------- 
103 * Max magnitude FFT Bin test 
104 * ------------------------------------------------------------------- */ 
105  
106 int32_t main(void) 
107
108    
109         arm_status status; 
110         arm_cfft_radix4_instance_f32 S; 
111         float32_t maxValue; 
112          
113         status = ARM_MATH_SUCCESS; 
114          
115         /* Initialize the CFFT/CIFFT module */  
116         status = arm_cfft_radix4_init_f32(&S, fftSize,  
117                                                                         ifftFlag, doBitReverse); 
118          
119         /* Process the data through the CFFT/CIFFT module */ 
120         arm_cfft_radix4_f32(&S, testInput_f32_10khz); 
121          
122          
123         /* Process the data through the Complex Magnitude Module for  
124         calculating the magnitude at each bin */ 
125         arm_cmplx_mag_f32(testInput_f32_10khz, testOutput,  
126                                         fftSize);  
127          
128         /* Calculates maxValue and returns corresponding BIN value */ 
129         arm_max_f32(testOutput, fftSize, &maxValue, &testIndex); 
130          
131         if(testIndex !=  refIndex) 
132         { 
133                 status = ARM_MATH_TEST_FAILURE; 
134         } 
135          
136         /* ---------------------------------------------------------------------- 
137         ** Loop here if the signals fail the PASS check. 
138         ** This denotes a test failure 
139         ** ------------------------------------------------------------------- */ 
140          
141         if( status != ARM_MATH_SUCCESS) 
142         { 
143                 while(1); 
144         } 
145
146     while(1);                             /* main function does not return */
147
148  
149  /** \endlink */ 
150  
151  
152