Subversion Repositories dashGPS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /* ----------------------------------------------------------------------
  2. * Copyright (C) 2010-2012 ARM Limited. All rights reserved.
  3. *
  4. * $Date:         17. January 2013
  5. * $Revision:     V1.4.0
  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. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions
  17. * are met:
  18. *   - Redistributions of source code must retain the above copyright
  19. *     notice, this list of conditions and the following disclaimer.
  20. *   - Redistributions in binary form must reproduce the above copyright
  21. *     notice, this list of conditions and the following disclaimer in
  22. *     the documentation and/or other materials provided with the
  23. *     distribution.
  24. *   - Neither the name of ARM LIMITED nor the names of its contributors
  25. *     may be used to endorse or promote products derived from this
  26. *     software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  29. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  30. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  31. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  32. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  33. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  34. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  35. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  36. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  37. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  38. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  39. * POSSIBILITY OF SUCH DAMAGE.
  40.  * -------------------------------------------------------------------- */
  41.  
  42. /**
  43.  * @ingroup groupExamples
  44.  */
  45.  
  46. /**
  47.  * @defgroup FrequencyBin Frequency Bin Example
  48.  *
  49.  * \par Description
  50.  * \par
  51.  * Demonstrates the calculation of the maximum energy bin in the frequency
  52.  * domain of the input signal with the use of Complex FFT, Complex
  53.  * Magnitude, and Maximum functions.
  54.  *
  55.  * \par Algorithm:
  56.  * \par
  57.  * The input test signal contains a 10 kHz signal with uniformly distributed white noise.
  58.  * Calculating the FFT of the input signal will give us the maximum energy of the
  59.  * bin corresponding to the input frequency of 10 kHz.
  60.  *
  61.  * \par Block Diagram:
  62.  * \image html FFTBin.gif "Block Diagram"
  63.  * \par
  64.  * The figure below shows the time domain signal of 10 kHz signal with
  65.  * uniformly distributed white noise, and the next figure shows the input
  66.  * in the frequency domain. The bin with maximum energy corresponds to 10 kHz signal.
  67.  * \par
  68.  * \image html FFTBinInput.gif "Input signal in Time domain"
  69.  * \image html FFTBinOutput.gif "Input signal in Frequency domain"
  70.  *
  71.  * \par Variables Description:
  72.  * \par
  73.  * \li \c testInput_f32_10khz points to the input data
  74.  * \li \c testOutput points to the output data
  75.  * \li \c fftSize length of FFT
  76.  * \li \c ifftFlag flag for the selection of CFFT/CIFFT
  77.  * \li \c doBitReverse Flag for selection of normal order or bit reversed order
  78.  * \li \c refIndex reference index value at which maximum energy of bin ocuurs
  79.  * \li \c testIndex calculated index value at which maximum energy of bin ocuurs
  80.  *
  81.  * \par CMSIS DSP Software Library Functions Used:
  82.  * \par
  83.  * - arm_cfft_f32()
  84.  * - arm_cmplx_mag_f32()
  85.  * - arm_max_f32()
  86.  *
  87.  * <b> Refer  </b>
  88.  * \link arm_fft_bin_example_f32.c \endlink
  89.  *
  90.  */
  91.  
  92.  
  93. /** \example arm_fft_bin_example_f32.c
  94.   */
  95.  
  96.  
  97. #include "arm_math.h"
  98. #include "arm_const_structs.h"
  99.  
  100. #define TEST_LENGTH_SAMPLES 2048
  101.  
  102. /* -------------------------------------------------------------------
  103. * External Input and Output buffer Declarations for FFT Bin Example
  104. * ------------------------------------------------------------------- */
  105. extern float32_t testInput_f32_10khz[TEST_LENGTH_SAMPLES];
  106. static float32_t testOutput[TEST_LENGTH_SAMPLES/2];
  107.  
  108. /* ------------------------------------------------------------------
  109. * Global variables for FFT Bin Example
  110. * ------------------------------------------------------------------- */
  111. uint32_t fftSize = 1024;
  112. uint32_t ifftFlag = 0;
  113. uint32_t doBitReverse = 1;
  114.  
  115. /* Reference index at which max energy of bin ocuurs */
  116. uint32_t refIndex = 213, testIndex = 0;
  117.  
  118. /* ----------------------------------------------------------------------
  119. * Max magnitude FFT Bin test
  120. * ------------------------------------------------------------------- */
  121.  
  122. int32_t main(void)
  123. {
  124.  
  125.   arm_status status;
  126.   float32_t maxValue;
  127.  
  128.   status = ARM_MATH_SUCCESS;
  129.  
  130.   /* Process the data through the CFFT/CIFFT module */
  131.   arm_cfft_f32(&arm_cfft_sR_f32_len1024, testInput_f32_10khz, ifftFlag, doBitReverse);
  132.  
  133.   /* Process the data through the Complex Magnitude Module for
  134.   calculating the magnitude at each bin */
  135.   arm_cmplx_mag_f32(testInput_f32_10khz, testOutput, fftSize);
  136.  
  137.   /* Calculates maxValue and returns corresponding BIN value */
  138.   arm_max_f32(testOutput, fftSize, &maxValue, &testIndex);
  139.  
  140.   if (testIndex !=  refIndex)
  141.   {
  142.     status = ARM_MATH_TEST_FAILURE;
  143.   }
  144.  
  145.   /* ----------------------------------------------------------------------
  146.   ** Loop here if the signals fail the PASS check.
  147.   ** This denotes a test failure
  148.   ** ------------------------------------------------------------------- */
  149.  
  150.   if ( status != ARM_MATH_SUCCESS)
  151.   {
  152.     while (1);
  153.   }
  154.  
  155.   while (1);                             /* main function does not return */
  156. }
  157.  
  158.  /** \endlink */
  159.