Subversion Repositories DashDisplay

Rev

Rev 49 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /* ----------------------------------------------------------------------    
  2. * Copyright (C) 2010-2014 ARM Limited. All rights reserved.    
  3. *    
  4. * $Date:        19. March 2015
  5. * $Revision:    V.1.4.5  
  6. *    
  7. * Project:          CMSIS DSP Library    
  8. * Title:            arm_rfft_init_q31.c    
  9. *    
  10. * Description:  RFFT & RIFFT Q31 initialisation function    
  11. *    
  12. * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
  13. *  
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. *   - Redistributions of source code must retain the above copyright
  18. *     notice, this list of conditions and the following disclaimer.
  19. *   - Redistributions in binary form must reproduce the above copyright
  20. *     notice, this list of conditions and the following disclaimer in
  21. *     the documentation and/or other materials provided with the
  22. *     distribution.
  23. *   - Neither the name of ARM LIMITED nor the names of its contributors
  24. *     may be used to endorse or promote products derived from this
  25. *     software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  30. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  31. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  32. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  33. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  35. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.  
  39. * -------------------------------------------------------------------- */
  40.  
  41. #include "arm_math.h"
  42. #include "arm_common_tables.h"
  43. #include "arm_const_structs.h"
  44.  
  45. /**    
  46. * @ingroup groupTransforms    
  47. */
  48.  
  49. /**    
  50. * @addtogroup RealFFT    
  51. * @{    
  52. */
  53.  
  54. /**    
  55. * \par    
  56. * Generation fixed-point realCoefAQ31 array in Q31 format:    
  57. * \par    
  58. * n = 4096    
  59. * <pre>for (i = 0; i < n; i++)    
  60. * {    
  61. *    pATable[2 * i] = 0.5 * (1.0 - sin (2 * PI / (double) (2 * n) * (double) i));    
  62. *    pATable[2 * i + 1] = 0.5 * (-1.0 * cos (2 * PI / (double) (2 * n) * (double) i));    
  63. * }</pre>    
  64. * \par    
  65. * Convert to fixed point Q31 format    
  66. *     round(pATable[i] * pow(2, 31))    
  67. *//**    
  68. * \par  
  69. * Generation of realCoefBQ31 array:    
  70. * \par    
  71. *  n = 4096        
  72. * <pre>for (i = 0; i < n; i++)    
  73. * {    
  74. *    pBTable[2 * i] = 0.5 * (1.0 + sin (2 * PI / (double) (2 * n) * (double) i));    
  75. *    pBTable[2 * i + 1] = 0.5 * (1.0 * cos (2 * PI / (double) (2 * n) * (double) i));    
  76. * } </pre>    
  77. * \par    
  78. * Convert to fixed point Q31 format    
  79. *     round(pBTable[i] * pow(2, 31))    
  80. *    
  81. *//**    
  82. * @brief  Initialization function for the Q31 RFFT/RIFFT.  
  83. * @param[in, out] *S             points to an instance of the Q31 RFFT/RIFFT structure.  
  84. * @param[in]      fftLenReal     length of the FFT.  
  85. * @param[in]      ifftFlagR      flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform.  
  86. * @param[in]      bitReverseFlag flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output.  
  87. * @return               The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>fftLenReal</code> is not a supported value.  
  88. *    
  89. * \par Description:  
  90. * \par  
  91. * The parameter <code>fftLenReal</code> Specifies length of RFFT/RIFFT Process. Supported FFT Lengths are 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192.    
  92. * \par    
  93. * The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.    
  94. * Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.    
  95. * \par    
  96. * The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.    
  97. * Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.  
  98. * \par    7
  99. * This function also initializes Twiddle factor table.    
  100. */
  101.  
  102. arm_status arm_rfft_init_q31(
  103.     arm_rfft_instance_q31 * S,
  104.     uint32_t fftLenReal,
  105.     uint32_t ifftFlagR,
  106.     uint32_t bitReverseFlag)
  107. {
  108.     /*  Initialise the default arm status */
  109.     arm_status status = ARM_MATH_SUCCESS;
  110.  
  111.     /*  Initialize the Real FFT length */
  112.     S->fftLenReal = (uint16_t) fftLenReal;
  113.  
  114.     /*  Initialize the Twiddle coefficientA pointer */
  115.     S->pTwiddleAReal = (q31_t *) realCoefAQ31;
  116.  
  117.     /*  Initialize the Twiddle coefficientB pointer */
  118.     S->pTwiddleBReal = (q31_t *) realCoefBQ31;
  119.  
  120.     /*  Initialize the Flag for selection of RFFT or RIFFT */
  121.     S->ifftFlagR = (uint8_t) ifftFlagR;
  122.  
  123.     /*  Initialize the Flag for calculation Bit reversal or not */
  124.     S->bitReverseFlagR = (uint8_t) bitReverseFlag;
  125.  
  126.     /*  Initialization of coef modifier depending on the FFT length */
  127.     switch (S->fftLenReal)
  128.     {
  129.     case 8192u:
  130.         S->twidCoefRModifier = 1u;
  131.         S->pCfft = &arm_cfft_sR_q31_len4096;
  132.         break;
  133.     case 4096u:
  134.         S->twidCoefRModifier = 2u;
  135.         S->pCfft = &arm_cfft_sR_q31_len2048;
  136.         break;
  137.     case 2048u:
  138.         S->twidCoefRModifier = 4u;
  139.         S->pCfft = &arm_cfft_sR_q31_len1024;
  140.         break;
  141.     case 1024u:
  142.         S->twidCoefRModifier = 8u;
  143.         S->pCfft = &arm_cfft_sR_q31_len512;
  144.         break;
  145.     case 512u:
  146.         S->twidCoefRModifier = 16u;
  147.         S->pCfft = &arm_cfft_sR_q31_len256;
  148.         break;
  149.     case 256u:
  150.         S->twidCoefRModifier = 32u;
  151.         S->pCfft = &arm_cfft_sR_q31_len128;
  152.         break;
  153.     case 128u:
  154.         S->twidCoefRModifier = 64u;
  155.         S->pCfft = &arm_cfft_sR_q31_len64;
  156.         break;
  157.     case 64u:
  158.         S->twidCoefRModifier = 128u;
  159.         S->pCfft = &arm_cfft_sR_q31_len32;
  160.         break;
  161.     case 32u:
  162.         S->twidCoefRModifier = 256u;
  163.         S->pCfft = &arm_cfft_sR_q31_len16;
  164.         break;
  165.     default:
  166.         /*  Reporting argument error if rfftSize is not valid value */
  167.         status = ARM_MATH_ARGUMENT_ERROR;
  168.         break;
  169.     }
  170.  
  171.     /* return the status of RFFT Init function */
  172.     return (status);
  173. }
  174.  
  175. /**    
  176. * @} end of RealFFT group    
  177. */
  178.