arm_cfft_q31.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cfft_q31.c
  4. * Description: Combined Radix Decimation in Frequency CFFT fixed point processing function
  5. *
  6. * $Date: 18. March 2019
  7. * $Revision: V1.6.0
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2019 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. #include "arm_math.h"
  29. extern void arm_radix4_butterfly_q31(
  30. q31_t * pSrc,
  31. uint32_t fftLen,
  32. const q31_t * pCoef,
  33. uint32_t twidCoefModifier);
  34. extern void arm_radix4_butterfly_inverse_q31(
  35. q31_t * pSrc,
  36. uint32_t fftLen,
  37. const q31_t * pCoef,
  38. uint32_t twidCoefModifier);
  39. extern void arm_bitreversal_32(
  40. uint32_t * pSrc,
  41. const uint16_t bitRevLen,
  42. const uint16_t * pBitRevTable);
  43. void arm_cfft_radix4by2_q31(
  44. q31_t * pSrc,
  45. uint32_t fftLen,
  46. const q31_t * pCoef);
  47. void arm_cfft_radix4by2_inverse_q31(
  48. q31_t * pSrc,
  49. uint32_t fftLen,
  50. const q31_t * pCoef);
  51. /**
  52. @ingroup groupTransforms
  53. */
  54. /**
  55. @addtogroup ComplexFFT
  56. @{
  57. */
  58. /**
  59. @brief Processing function for the Q31 complex FFT.
  60. @param[in] S points to an instance of the fixed-point CFFT structure
  61. @param[in,out] p1 points to the complex data buffer of size <code>2*fftLen</code>. Processing occurs in-place
  62. @param[in] ifftFlag flag that selects transform direction
  63. - value = 0: forward transform
  64. - value = 1: inverse transform
  65. @param[in] bitReverseFlag flag that enables / disables bit reversal of output
  66. - value = 0: disables bit reversal of output
  67. - value = 1: enables bit reversal of output
  68. @return none
  69. */
  70. void arm_cfft_q31(
  71. const arm_cfft_instance_q31 * S,
  72. q31_t * p1,
  73. uint8_t ifftFlag,
  74. uint8_t bitReverseFlag)
  75. {
  76. uint32_t L = S->fftLen;
  77. if (ifftFlag == 1U)
  78. {
  79. switch (L)
  80. {
  81. case 16:
  82. case 64:
  83. case 256:
  84. case 1024:
  85. case 4096:
  86. arm_radix4_butterfly_inverse_q31 ( p1, L, (q31_t*)S->pTwiddle, 1 );
  87. break;
  88. case 32:
  89. case 128:
  90. case 512:
  91. case 2048:
  92. arm_cfft_radix4by2_inverse_q31 ( p1, L, S->pTwiddle );
  93. break;
  94. }
  95. }
  96. else
  97. {
  98. switch (L)
  99. {
  100. case 16:
  101. case 64:
  102. case 256:
  103. case 1024:
  104. case 4096:
  105. arm_radix4_butterfly_q31 ( p1, L, (q31_t*)S->pTwiddle, 1 );
  106. break;
  107. case 32:
  108. case 128:
  109. case 512:
  110. case 2048:
  111. arm_cfft_radix4by2_q31 ( p1, L, S->pTwiddle );
  112. break;
  113. }
  114. }
  115. if ( bitReverseFlag )
  116. arm_bitreversal_32 ((uint32_t*) p1, S->bitRevLength, S->pBitRevTable);
  117. }
  118. /**
  119. @} end of ComplexFFT group
  120. */
  121. void arm_cfft_radix4by2_q31(
  122. q31_t * pSrc,
  123. uint32_t fftLen,
  124. const q31_t * pCoef)
  125. {
  126. uint32_t i, l;
  127. uint32_t n2;
  128. q31_t xt, yt, cosVal, sinVal;
  129. q31_t p0, p1;
  130. n2 = fftLen >> 1U;
  131. for (i = 0; i < n2; i++)
  132. {
  133. cosVal = pCoef[2 * i];
  134. sinVal = pCoef[2 * i + 1];
  135. l = i + n2;
  136. xt = (pSrc[2 * i] >> 2U) - (pSrc[2 * l] >> 2U);
  137. pSrc[2 * i] = (pSrc[2 * i] >> 2U) + (pSrc[2 * l] >> 2U);
  138. yt = (pSrc[2 * i + 1] >> 2U) - (pSrc[2 * l + 1] >> 2U);
  139. pSrc[2 * i + 1] = (pSrc[2 * l + 1] >> 2U) + (pSrc[2 * i + 1] >> 2U);
  140. mult_32x32_keep32_R(p0, xt, cosVal);
  141. mult_32x32_keep32_R(p1, yt, cosVal);
  142. multAcc_32x32_keep32_R(p0, yt, sinVal);
  143. multSub_32x32_keep32_R(p1, xt, sinVal);
  144. pSrc[2 * l] = p0 << 1;
  145. pSrc[2 * l + 1] = p1 << 1;
  146. }
  147. /* first col */
  148. arm_radix4_butterfly_q31 (pSrc, n2, (q31_t*)pCoef, 2U);
  149. /* second col */
  150. arm_radix4_butterfly_q31 (pSrc + fftLen, n2, (q31_t*)pCoef, 2U);
  151. n2 = fftLen >> 1U;
  152. for (i = 0; i < n2; i++)
  153. {
  154. p0 = pSrc[4 * i + 0];
  155. p1 = pSrc[4 * i + 1];
  156. xt = pSrc[4 * i + 2];
  157. yt = pSrc[4 * i + 3];
  158. p0 <<= 1U;
  159. p1 <<= 1U;
  160. xt <<= 1U;
  161. yt <<= 1U;
  162. pSrc[4 * i + 0] = p0;
  163. pSrc[4 * i + 1] = p1;
  164. pSrc[4 * i + 2] = xt;
  165. pSrc[4 * i + 3] = yt;
  166. }
  167. }
  168. void arm_cfft_radix4by2_inverse_q31(
  169. q31_t * pSrc,
  170. uint32_t fftLen,
  171. const q31_t * pCoef)
  172. {
  173. uint32_t i, l;
  174. uint32_t n2;
  175. q31_t xt, yt, cosVal, sinVal;
  176. q31_t p0, p1;
  177. n2 = fftLen >> 1U;
  178. for (i = 0; i < n2; i++)
  179. {
  180. cosVal = pCoef[2 * i];
  181. sinVal = pCoef[2 * i + 1];
  182. l = i + n2;
  183. xt = (pSrc[2 * i] >> 2U) - (pSrc[2 * l] >> 2U);
  184. pSrc[2 * i] = (pSrc[2 * i] >> 2U) + (pSrc[2 * l] >> 2U);
  185. yt = (pSrc[2 * i + 1] >> 2U) - (pSrc[2 * l + 1] >> 2U);
  186. pSrc[2 * i + 1] = (pSrc[2 * l + 1] >> 2U) + (pSrc[2 * i + 1] >> 2U);
  187. mult_32x32_keep32_R(p0, xt, cosVal);
  188. mult_32x32_keep32_R(p1, yt, cosVal);
  189. multSub_32x32_keep32_R(p0, yt, sinVal);
  190. multAcc_32x32_keep32_R(p1, xt, sinVal);
  191. pSrc[2 * l] = p0 << 1U;
  192. pSrc[2 * l + 1] = p1 << 1U;
  193. }
  194. /* first col */
  195. arm_radix4_butterfly_inverse_q31( pSrc, n2, (q31_t*)pCoef, 2U);
  196. /* second col */
  197. arm_radix4_butterfly_inverse_q31( pSrc + fftLen, n2, (q31_t*)pCoef, 2U);
  198. n2 = fftLen >> 1U;
  199. for (i = 0; i < n2; i++)
  200. {
  201. p0 = pSrc[4 * i + 0];
  202. p1 = pSrc[4 * i + 1];
  203. xt = pSrc[4 * i + 2];
  204. yt = pSrc[4 * i + 3];
  205. p0 <<= 1U;
  206. p1 <<= 1U;
  207. xt <<= 1U;
  208. yt <<= 1U;
  209. pSrc[4 * i + 0] = p0;
  210. pSrc[4 * i + 1] = p1;
  211. pSrc[4 * i + 2] = xt;
  212. pSrc[4 * i + 3] = yt;
  213. }
  214. }