1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010 ARM Limited. All rights reserved.
4 * $Date: 29. November 2010
7 * Project: CMSIS DSP Library
8 * Title: arm_fft_bin_example_f32.c
10 * Description: Example code demonstrating calculation of Max energy bin of
11 * frequency domain of input signal.
13 * Target Processor: Cortex-M4/Cortex-M3
16 * Version 1.0.3 2010/11/29
17 * Re-organized the CMSIS folders and updated documentation.
19 * Version 1.0.1 2010/10/05 KK
20 * Production release and review comments incorporated.
22 * Version 1.0.0 2010/09/20 KK
23 * Production release and review comments incorporated.
24 * ------------------------------------------------------------------- */
27 * @ingroup groupExamples
31 * @defgroup FrequencyBin Frequency Bin Example
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.
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.
46 * \image html FFTBin.gif "Block Diagram"
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.
52 * \image html FFTBinInput.gif "Input signal in Time domain"
53 * \image html FFTBinOutput.gif "Input signal in Frequency domain"
55 * \par Variables Description:
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
65 * \par CMSIS DSP Software Library Functions Used:
67 * - arm_cfft_radix4_init_f32()
68 * - arm_cfft_radix4_f32()
69 * - arm_cmplx_mag_f32()
73 * \link arm_fft_bin_example_f32.c \endlink
78 /** \example arm_fft_bin_example_f32.c
84 #define TEST_LENGTH_SAMPLES 2048
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];
92 /* ------------------------------------------------------------------
93 * Global variables for FFT Bin Example
94 * ------------------------------------------------------------------- */
95 uint32_t fftSize = 1024;
96 uint32_t ifftFlag = 0;
97 uint32_t doBitReverse = 1;
99 /* Reference index at which max energy of bin ocuurs */
100 uint32_t refIndex = 213, testIndex = 0;
102 /* ----------------------------------------------------------------------
103 * Max magnitude FFT Bin test
104 * ------------------------------------------------------------------- */
110 arm_cfft_radix4_instance_f32 S;
113 status = ARM_MATH_SUCCESS;
115 /* Initialize the CFFT/CIFFT module */
116 status = arm_cfft_radix4_init_f32(&S, fftSize,
117 ifftFlag, doBitReverse);
119 /* Process the data through the CFFT/CIFFT module */
120 arm_cfft_radix4_f32(&S, testInput_f32_10khz);
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,
128 /* Calculates maxValue and returns corresponding BIN value */
129 arm_max_f32(testOutput, fftSize, &maxValue, &testIndex);
131 if(testIndex != refIndex)
133 status = ARM_MATH_TEST_FAILURE;
136 /* ----------------------------------------------------------------------
137 ** Loop here if the signals fail the PASS check.
138 ** This denotes a test failure
139 ** ------------------------------------------------------------------- */
141 if( status != ARM_MATH_SUCCESS)
146 while(1); /* main function does not return */