Subversion Repositories dashGPS

Rev

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

  1. /* ----------------------------------------------------------------------
  2.  * Project:      CMSIS DSP Library
  3.  * Title:        arm_rfft_init_q31.c
  4.  * Description:  RFFT & RIFFT Q31 initialisation function
  5.  *
  6.  * $Date:        27. January 2017
  7.  * $Revision:    V.1.5.1
  8.  *
  9.  * Target Processor: Cortex-M cores
  10.  * -------------------------------------------------------------------- */
  11. /*
  12.  * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
  13.  *
  14.  * SPDX-License-Identifier: Apache-2.0
  15.  *
  16.  * Licensed under the Apache License, Version 2.0 (the License); you may
  17.  * not use this file except in compliance with the License.
  18.  * You may obtain a copy of the License at
  19.  *
  20.  * www.apache.org/licenses/LICENSE-2.0
  21.  *
  22.  * Unless required by applicable law or agreed to in writing, software
  23.  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24.  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25.  * See the License for the specific language governing permissions and
  26.  * limitations under the License.
  27.  */
  28.  
  29. #include "arm_math.h"
  30. #include "arm_common_tables.h"
  31. #include "arm_const_structs.h"
  32.  
  33. /**
  34. * @ingroup RealFFT
  35. */
  36.  
  37. /**
  38.  * @addtogroup RealFFT_Table Real FFT Tables
  39. * @{
  40. */
  41.  
  42. /**
  43. * \par
  44. * Generation fixed-point realCoefAQ31 array in Q31 format:
  45. * \par
  46. * n = 4096
  47. * <pre>for (i = 0; i < n; i++)
  48. * {
  49. *    pATable[2 * i] = 0.5 * (1.0 - sin (2 * PI / (double) (2 * n) * (double) i));
  50. *    pATable[2 * i + 1] = 0.5 * (-1.0 * cos (2 * PI / (double) (2 * n) * (double) i));
  51. * }</pre>
  52. * \par
  53. * Convert to fixed point Q31 format
  54. *     round(pATable[i] * pow(2, 31))
  55. *//**
  56. * \par
  57. * Generation of realCoefBQ31 array:
  58. * \par
  59. *  n = 4096
  60. * <pre>for (i = 0; i < n; i++)
  61. * {
  62. *    pBTable[2 * i] = 0.5 * (1.0 + sin (2 * PI / (double) (2 * n) * (double) i));
  63. *    pBTable[2 * i + 1] = 0.5 * (1.0 * cos (2 * PI / (double) (2 * n) * (double) i));
  64. * } </pre>
  65. * \par
  66. * Convert to fixed point Q31 format
  67. *     round(pBTable[i] * pow(2, 31))
  68. *
  69. *//**
  70. * @} end of RealFFT_Table group
  71. */
  72.  
  73. /**
  74. * @addtogroup RealFFT
  75. * @{
  76. */
  77.  
  78. /**
  79. * @brief  Initialization function for the Q31 RFFT/RIFFT.
  80. * @param[in, out] *S             points to an instance of the Q31 RFFT/RIFFT structure.
  81. * @param[in]      fftLenReal     length of the FFT.
  82. * @param[in]      ifftFlagR      flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform.
  83. * @param[in]      bitReverseFlag flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output.
  84. * @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.
  85. *
  86. * \par Description:
  87. * \par
  88. * The parameter <code>fftLenReal</code> Specifies length of RFFT/RIFFT Process. Supported FFT Lengths are 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192.
  89. * \par
  90. * The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
  91. * Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
  92. * \par
  93. * The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
  94. * Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
  95. * \par    7
  96. * This function also initializes Twiddle factor table.
  97. */
  98.  
  99. arm_status arm_rfft_init_q31(
  100.     arm_rfft_instance_q31 * S,
  101.     uint32_t fftLenReal,
  102.     uint32_t ifftFlagR,
  103.     uint32_t bitReverseFlag)
  104. {
  105.     /*  Initialise the default arm status */
  106.     arm_status status = ARM_MATH_SUCCESS;
  107.  
  108.     /*  Initialize the Real FFT length */
  109.     S->fftLenReal = (uint16_t) fftLenReal;
  110.  
  111.     /*  Initialize the Twiddle coefficientA pointer */
  112.     S->pTwiddleAReal = (q31_t *) realCoefAQ31;
  113.  
  114.     /*  Initialize the Twiddle coefficientB pointer */
  115.     S->pTwiddleBReal = (q31_t *) realCoefBQ31;
  116.  
  117.     /*  Initialize the Flag for selection of RFFT or RIFFT */
  118.     S->ifftFlagR = (uint8_t) ifftFlagR;
  119.  
  120.     /*  Initialize the Flag for calculation Bit reversal or not */
  121.     S->bitReverseFlagR = (uint8_t) bitReverseFlag;
  122.  
  123.     /*  Initialization of coef modifier depending on the FFT length */
  124.     switch (S->fftLenReal)
  125.     {
  126.     case 8192U:
  127.         S->twidCoefRModifier = 1U;
  128.         S->pCfft = &arm_cfft_sR_q31_len4096;
  129.         break;
  130.     case 4096U:
  131.         S->twidCoefRModifier = 2U;
  132.         S->pCfft = &arm_cfft_sR_q31_len2048;
  133.         break;
  134.     case 2048U:
  135.         S->twidCoefRModifier = 4U;
  136.         S->pCfft = &arm_cfft_sR_q31_len1024;
  137.         break;
  138.     case 1024U:
  139.         S->twidCoefRModifier = 8U;
  140.         S->pCfft = &arm_cfft_sR_q31_len512;
  141.         break;
  142.     case 512U:
  143.         S->twidCoefRModifier = 16U;
  144.         S->pCfft = &arm_cfft_sR_q31_len256;
  145.         break;
  146.     case 256U:
  147.         S->twidCoefRModifier = 32U;
  148.         S->pCfft = &arm_cfft_sR_q31_len128;
  149.         break;
  150.     case 128U:
  151.         S->twidCoefRModifier = 64U;
  152.         S->pCfft = &arm_cfft_sR_q31_len64;
  153.         break;
  154.     case 64U:
  155.         S->twidCoefRModifier = 128U;
  156.         S->pCfft = &arm_cfft_sR_q31_len32;
  157.         break;
  158.     case 32U:
  159.         S->twidCoefRModifier = 256U;
  160.         S->pCfft = &arm_cfft_sR_q31_len16;
  161.         break;
  162.     default:
  163.         /*  Reporting argument error if rfftSize is not valid value */
  164.         status = ARM_MATH_ARGUMENT_ERROR;
  165.         break;
  166.     }
  167.  
  168.     /* return the status of RFFT Init function */
  169.     return (status);
  170. }
  171.  
  172. /**
  173. * @} end of RealFFT group
  174. */
  175.