TransformQ15.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #include "TransformQ15.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. \
  22. /* Initializations of structure parameters for 2048 point FFT */ \
  23. case 2048U: \
  24. /* Initialise the bit reversal table modifier */ \
  25. S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH; \
  26. S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_2048; \
  27. S->pTwiddle = (typ *)twiddleCoef_2048_##suffix; \
  28. break; \
  29. \
  30. /* Initializations of structure parameters for 1024 point FFT */ \
  31. case 1024U: \
  32. /* Initialise the bit reversal table modifier */ \
  33. S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH; \
  34. S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_1024; \
  35. S->pTwiddle = (typ *)twiddleCoef_1024_##suffix; \
  36. break; \
  37. \
  38. /* Initializations of structure parameters for 512 point FFT */ \
  39. case 512U: \
  40. /* Initialise the bit reversal table modifier */ \
  41. S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_512_TABLE_LENGTH; \
  42. S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_512; \
  43. S->pTwiddle = (typ *)twiddleCoef_512_##suffix; \
  44. break; \
  45. \
  46. case 256U: \
  47. S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_256_TABLE_LENGTH; \
  48. S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_256; \
  49. S->pTwiddle = (typ *)twiddleCoef_256_##suffix; \
  50. \
  51. break; \
  52. \
  53. case 128U: \
  54. S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_128_TABLE_LENGTH; \
  55. S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_128; \
  56. S->pTwiddle = (typ *)twiddleCoef_128_##suffix; \
  57. \
  58. break; \
  59. \
  60. case 64U: \
  61. S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_64_TABLE_LENGTH; \
  62. S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_64; \
  63. S->pTwiddle = (typ *)twiddleCoef_64_##suffix; \
  64. break; \
  65. \
  66. case 32U: \
  67. S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_32_TABLE_LENGTH; \
  68. S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_32; \
  69. S->pTwiddle = (typ *)twiddleCoef_32_##suffix; \
  70. break; \
  71. \
  72. case 16U: \
  73. /* Initializations of structure parameters for 16 point FFT */ \
  74. S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_16_TABLE_LENGTH; \
  75. S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_16; \
  76. S->pTwiddle = (typ *)twiddleCoef_16_##suffix; \
  77. break; \
  78. \
  79. \
  80. default: \
  81. /* Reporting argument error if fftSize is not valid value */ \
  82. status = ARM_MATH_ARGUMENT_ERROR; \
  83. break; \
  84. } \
  85. \
  86. \
  87. return (status); \
  88. \
  89. }
  90. arm_status arm_cfft_init_q15(arm_cfft_instance_q15 *S, uint16_t fftLen)
  91. {
  92. CFFT_INIT(q15_t, q15, S, fftLen);
  93. }
  94. void TransformQ15::test_cfft_q15()
  95. {
  96. arm_cfft_q15(&this->cfftInstance, this->pDst, this->ifft,this->bitRev);
  97. }
  98. void TransformQ15::test_rfft_q15()
  99. {
  100. arm_rfft_q15(&this->rfftInstance, this->pSrc, this->pDst);
  101. }
  102. void TransformQ15::test_dct4_q15()
  103. {
  104. arm_dct4_q15(
  105. &this->dct4Instance,
  106. this->pState,
  107. this->pDst);
  108. }
  109. void TransformQ15::test_cfft_radix4_q15()
  110. {
  111. arm_cfft_radix4_q15(&this->cfftRadix4Instance,this->pDst);
  112. }
  113. void TransformQ15::test_cfft_radix2_q15()
  114. {
  115. arm_cfft_radix2_q15(&this->cfftRadix2Instance,this->pDst);
  116. }
  117. void TransformQ15::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
  118. {
  119. float32_t normalize;
  120. std::vector<Testing::param_t>::iterator it = params.begin();
  121. this->nbSamples = *it++;
  122. this->ifft = *it++;
  123. this->bitRev = *it;
  124. switch(id)
  125. {
  126. case TEST_CFFT_Q15_1:
  127. samples.reload(TransformQ15::INPUTC_Q15_ID,mgr,2*this->nbSamples);
  128. output.create(2*this->nbSamples,TransformQ15::OUT_Q15_ID,mgr);
  129. this->pSrc=samples.ptr();
  130. this->pDst=output.ptr();
  131. arm_cfft_init_q15(&this->cfftInstance,this->nbSamples);
  132. memcpy(this->pDst,this->pSrc,2*sizeof(q15_t)*this->nbSamples);
  133. break;
  134. case TEST_RFFT_Q15_2:
  135. samples.reload(TransformQ15::INPUTR_Q15_ID,mgr,this->nbSamples);
  136. output.create(this->nbSamples,TransformQ15::OUT_Q15_ID,mgr);
  137. this->pSrc=samples.ptr();
  138. this->pDst=output.ptr();
  139. arm_rfft_init_q15(&this->rfftInstance, this->nbSamples, this->ifft, this->bitRev);
  140. break;
  141. case TEST_DCT4_Q15_3:
  142. samples.reload(TransformQ15::INPUTR_Q15_ID,mgr,this->nbSamples);
  143. output.create(this->nbSamples,TransformQ15::OUT_Q15_ID,mgr);
  144. state.create(2*this->nbSamples,TransformQ15::STATE_Q15_ID,mgr);
  145. this->pSrc=samples.ptr();
  146. this->pDst=output.ptr();
  147. this->pState=state.ptr();
  148. normalize = sqrt((2.0f/(float32_t)this->nbSamples));
  149. memcpy(this->pDst,this->pSrc,sizeof(q15_t)*this->nbSamples);
  150. arm_dct4_init_q15(
  151. &this->dct4Instance,
  152. &this->rfftInstance,
  153. &this->cfftRadix4Instance,
  154. this->nbSamples,
  155. this->nbSamples/2,
  156. normalize);
  157. break;
  158. case TEST_CFFT_RADIX4_Q15_4:
  159. samples.reload(TransformQ15::INPUTC_Q15_ID,mgr,2*this->nbSamples);
  160. output.create(2*this->nbSamples,TransformQ15::OUT_Q15_ID,mgr);
  161. this->pSrc=samples.ptr();
  162. this->pDst=output.ptr();
  163. memcpy(this->pDst,this->pSrc,2*sizeof(q15_t)*this->nbSamples);
  164. arm_cfft_radix4_init_q15(&this->cfftRadix4Instance,
  165. this->nbSamples,
  166. this->ifft,
  167. this->bitRev);
  168. break;
  169. case TEST_CFFT_RADIX2_Q15_5:
  170. samples.reload(TransformQ15::INPUTC_Q15_ID,mgr,2*this->nbSamples);
  171. output.create(2*this->nbSamples,TransformQ15::OUT_Q15_ID,mgr);
  172. this->pSrc=samples.ptr();
  173. this->pDst=output.ptr();
  174. memcpy(this->pDst,this->pSrc,2*sizeof(q15_t)*this->nbSamples);
  175. arm_cfft_radix2_init_q15(&this->cfftRadix2Instance,
  176. this->nbSamples,
  177. this->ifft,
  178. this->bitRev);
  179. break;
  180. }
  181. }
  182. void TransformQ15::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  183. {
  184. }