TransformQ31.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #include "TransformQ31.h"
  2. #include "Error.h"
  3. #include "arm_const_structs.h"
  4. #define CFFT_INIT(typ, suffix, S, fftLen) \
  5. \
  6. { \
  7. \
  8. /* Initialise the default arm status */ \
  9. arm_status status = ARM_MATH_SUCCESS; \
  10. \
  11. /* Initialise the FFT length */ \
  12. S->fftLen = fftLen; \
  13. \
  14. /* Initialise the Twiddle coefficient pointer */ \
  15. S->pTwiddle = (typ *)twiddleCoef_4096_##suffix; \
  16. \
  17. \
  18. /* Initializations of Instance structure depending on the FFT length */\
  19. switch (S->fftLen) { \
  20. \
  21. /* Initializations of structure parameters for 2048 point FFT */ \
  22. case 2048U: \
  23. /* Initialise the bit reversal table modifier */ \
  24. S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH; \
  25. S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_2048; \
  26. S->pTwiddle = (typ *)twiddleCoef_2048_##suffix; \
  27. break; \
  28. \
  29. /* Initializations of structure parameters for 1024 point FFT */ \
  30. case 1024U: \
  31. /* Initialise the bit reversal table modifier */ \
  32. S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH; \
  33. S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_1024; \
  34. S->pTwiddle = (typ *)twiddleCoef_1024_##suffix; \
  35. break; \
  36. \
  37. /* Initializations of structure parameters for 512 point FFT */ \
  38. case 512U: \
  39. /* Initialise the bit reversal table modifier */ \
  40. S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_512_TABLE_LENGTH; \
  41. S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_512; \
  42. S->pTwiddle = (typ *)twiddleCoef_512_##suffix; \
  43. break; \
  44. \
  45. case 256U: \
  46. S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_256_TABLE_LENGTH; \
  47. S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_256; \
  48. S->pTwiddle = (typ *)twiddleCoef_256_##suffix; \
  49. \
  50. break; \
  51. \
  52. case 128U: \
  53. S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_128_TABLE_LENGTH; \
  54. S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_128; \
  55. S->pTwiddle = (typ *)twiddleCoef_128_##suffix; \
  56. \
  57. break; \
  58. \
  59. case 64U: \
  60. S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_64_TABLE_LENGTH; \
  61. S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_64; \
  62. S->pTwiddle = (typ *)twiddleCoef_64_##suffix; \
  63. break; \
  64. \
  65. case 32U: \
  66. S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_32_TABLE_LENGTH; \
  67. S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_32; \
  68. S->pTwiddle = (typ *)twiddleCoef_32_##suffix; \
  69. break; \
  70. \
  71. case 16U: \
  72. /* Initializations of structure parameters for 16 point FFT */ \
  73. S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_16_TABLE_LENGTH; \
  74. S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_16; \
  75. S->pTwiddle = (typ *)twiddleCoef_16_##suffix; \
  76. break; \
  77. \
  78. \
  79. default: \
  80. /* Reporting argument error if fftSize is not valid value */ \
  81. status = ARM_MATH_ARGUMENT_ERROR; \
  82. break; \
  83. } \
  84. \
  85. \
  86. return (status); \
  87. \
  88. }
  89. arm_status arm_cfft_init_q31(arm_cfft_instance_q31 *S, uint16_t fftLen)
  90. {
  91. CFFT_INIT(q31_t, q31, S, fftLen);
  92. }
  93. void TransformQ31::test_cfft_q31()
  94. {
  95. arm_cfft_q31(&this->cfftInstance, this->pDst, this->ifft,this->bitRev);
  96. }
  97. void TransformQ31::test_rfft_q31()
  98. {
  99. arm_rfft_q31(&this->rfftInstance, this->pSrc, this->pDst);
  100. }
  101. void TransformQ31::test_dct4_q31()
  102. {
  103. arm_dct4_q31(
  104. &this->dct4Instance,
  105. this->pState,
  106. this->pDst);
  107. }
  108. void TransformQ31::test_cfft_radix4_q31()
  109. {
  110. arm_cfft_radix4_q31(&this->cfftRadix4Instance,this->pDst);
  111. }
  112. void TransformQ31::test_cfft_radix2_q31()
  113. {
  114. arm_cfft_radix2_q31(&this->cfftRadix2Instance,this->pDst);
  115. }
  116. void TransformQ31::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
  117. {
  118. float32_t normalize;
  119. std::vector<Testing::param_t>::iterator it = params.begin();
  120. this->nbSamples = *it++;
  121. this->ifft = *it++;
  122. this->bitRev = *it;
  123. switch(id)
  124. {
  125. case TEST_CFFT_Q31_1:
  126. samples.reload(TransformQ31::INPUTC_Q31_ID,mgr,2*this->nbSamples);
  127. output.create(2*this->nbSamples,TransformQ31::OUT_Q31_ID,mgr);
  128. this->pSrc=samples.ptr();
  129. this->pDst=output.ptr();
  130. arm_cfft_init_q31(&this->cfftInstance,this->nbSamples);
  131. memcpy(this->pDst,this->pSrc,2*sizeof(q31_t)*this->nbSamples);
  132. break;
  133. case TEST_RFFT_Q31_2:
  134. samples.reload(TransformQ31::INPUTR_Q31_ID,mgr,this->nbSamples);
  135. output.create(this->nbSamples,TransformQ31::OUT_Q31_ID,mgr);
  136. this->pSrc=samples.ptr();
  137. this->pDst=output.ptr();
  138. arm_rfft_init_q31(&this->rfftInstance, this->nbSamples,this->ifft,this->bitRev);
  139. break;
  140. case TEST_DCT4_Q31_3:
  141. samples.reload(TransformQ31::INPUTR_Q31_ID,mgr,this->nbSamples);
  142. output.create(this->nbSamples,TransformQ31::OUT_Q31_ID,mgr);
  143. state.create(2*this->nbSamples,TransformQ31::STATE_Q31_ID,mgr);
  144. this->pSrc=samples.ptr();
  145. this->pDst=output.ptr();
  146. this->pState=state.ptr();
  147. normalize = sqrt((2.0f/(float32_t)this->nbSamples));
  148. memcpy(this->pDst,this->pSrc,sizeof(q31_t)*this->nbSamples);
  149. arm_dct4_init_q31(
  150. &this->dct4Instance,
  151. &this->rfftInstance,
  152. &this->cfftRadix4Instance,
  153. this->nbSamples,
  154. this->nbSamples/2,
  155. normalize);
  156. break;
  157. case TEST_CFFT_RADIX4_Q31_4:
  158. samples.reload(TransformQ31::INPUTC_Q31_ID,mgr,2*this->nbSamples);
  159. output.create(2*this->nbSamples,TransformQ31::OUT_Q31_ID,mgr);
  160. this->pSrc=samples.ptr();
  161. this->pDst=output.ptr();
  162. memcpy(this->pDst,this->pSrc,2*sizeof(q31_t)*this->nbSamples);
  163. arm_cfft_radix4_init_q31(&this->cfftRadix4Instance,
  164. this->nbSamples,
  165. this->ifft,
  166. this->bitRev);
  167. break;
  168. case TEST_CFFT_RADIX2_Q31_5:
  169. samples.reload(TransformQ31::INPUTC_Q31_ID,mgr,2*this->nbSamples);
  170. output.create(2*this->nbSamples,TransformQ31::OUT_Q31_ID,mgr);
  171. this->pSrc=samples.ptr();
  172. this->pDst=output.ptr();
  173. memcpy(this->pDst,this->pSrc,2*sizeof(q31_t)*this->nbSamples);
  174. arm_cfft_radix2_init_q31(&this->cfftRadix2Instance,
  175. this->nbSamples,
  176. this->ifft,
  177. this->bitRev);
  178. break;
  179. }
  180. }
  181. void TransformQ31::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  182. {
  183. }